Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Projection onto a Line


Linear Algebra·ProjectionDrop a perpendicular from v onto the line; the foot is Pv. Projection is idempotent: P² = P.
im Pker PPvv
v=(1.5, 1.5)
Pv=(1.5, 1.5)
Morph I → Pt = 1.000
t = 1.000

Project onto y = x

rank 1 · symmetric

Maps every point to its closest point on the diagonal. The kernel is the line y = −x; the image is y = x. Perpendicular — orthogonal projection.
Learn more about diagonal projections · kernel and image

Insight

P is symmetric (Pᵀ = P) and idempotent (P² = P). Projecting twice changes nothing.

AProjection matrixP = uuᵀ

P=
0.50.50.50.5
θ45°

04Livedrag v

|v|2.12|Pv|2.12|v − Pv|0angle(v, line)0°det P0trace P1
P²v = Pv · idempotence verified








Key Terms

Orthogonal projection onto a line — the linear map sending each vector v\mathbf{v} to the point on the line closest to it, the foot of the perpendicular dropped from v\mathbf{v}.

Projection matrix — for the line at angle θ\theta with unit direction u=(cosθ,sinθ)\mathbf{u} = (\cos\theta, \sin\theta), P=uuT=(cos2θcosθsinθcosθsinθsin2θ)P = \mathbf{u}\mathbf{u}^T = \begin{pmatrix} \cos^2\theta & \cos\theta\sin\theta \\ \cos\theta\sin\theta & \sin^2\theta \end{pmatrix}.

Image — the set of all outputs PvP\mathbf{v}; for a projection onto a line it is the line itself.

Kernel — the set of vectors sent to 0\mathbf{0}; here the line perpendicular to the projection line.

Idempotent — P2=PP^2 = P; projecting a second time changes nothing.

Symmetric — PT=PP^T = P, the mark of an orthogonal (as opposed to oblique) projection.

Rank 11 — the image is one-dimensional; detP=0\det P = 0 and trP=1\operatorname{tr} P = 1 for every line.

Residual — vPv\mathbf{v} - P\mathbf{v}, the perpendicular part, which lies in the kernel.

Getting Started

The canvas shows a projection line through the origin in blue with its image label, the perpendicular kernel line dashed in red, a draggable vector v\mathbf{v} in orange, and its projection PvP\mathbf{v} in green with a dashed dropline and a right-angle mark at the foot.

Try this sequence to build intuition:

• Start on the y = x preset. Drag v\mathbf{v} around and watch PvP\mathbf{v} slide along the diagonal, always at the foot of the perpendicular from v\mathbf{v}.
• Drag v\mathbf{v} onto the red kernel line. PvP\mathbf{v} collapses to the origin: everything perpendicular to the line projects to nothing.
• Press play in the animation panel. The grid and unit square morph from the identity to PP, flattening the whole plane onto the line, which is what a rank-11 map does to space.
• Move the θ\theta slider in the matrix card and watch the four entries of PP change while detP\det P stays 00 and trP\operatorname{tr} P stays 11.

The point: a projection is a linear transformation like any other, with a matrix, an image and a kernel, but one that throws away a dimension and then leaves what remains alone.

Dragging the Vector

The tip of v\mathbf{v} is the only handle on the canvas.

• Drag v\mathbf{v} — PvP\mathbf{v} follows as the foot of the perpendicular, the dropline and right-angle mark redraw, and the readouts under the canvas update
• Cross the line — v\mathbf{v} and PvP\mathbf{v} coincide when v\mathbf{v} lies on the line; the dropline vanishes because there is nothing to drop
• Cross the kernel — PvP\mathbf{v} becomes the origin and is drawn as a dashed ring there

The projection line itself is not dragged. It is set by the presets or by the θ\theta slider in the matrix card, because a line through the origin is one number, its angle, and a slider states that more honestly than a handle would.

The Morph Animation

The animation panel blends the identity into the projection: M(t)=(1t)I+tPM(t) = (1 - t)I + tP for tt from 00 to 11, applied to the grid and the unit square.

• At t=0t = 0 the grid is the ordinary square grid and the unit square is a square
• As tt grows the grid shears toward the line and the square thins into a parallelogram
• At t=1t = 1 every grid line lies on the projection line and the unit square has collapsed to a segment of it: the plane has been flattened

v\mathbf{v} and PvP\mathbf{v} are drawn independently of tt, so the geometry of the perpendicular stays readable while the background morphs. Selecting a preset replays the morph automatically; the transport buttons step, scrub and reset it. The collapse at t=1t = 1 is the visual meaning of detP=0\det P = 0: a projection has no inverse, because a flattened plane cannot be unflattened.

Preset Scenarios

The sidebar offers seven lines in three groups.

• Coordinate axes — the x-axis and the y-axis; PP is diagonal and simply zeroes one coordinate
• Diagonals — y=xy = x and y=xy = -x; every entry of PP is ±12\pm\tfrac{1}{2}, and the two projections add to the identity
• Custom angle — 30°30°, 60°60° and 120°120°; off-diagonal entries appear, and the 120°120° line is the same line as 60°-60°

The three sections that follow take one representative from each group and freeze it, and a fourth freezes the special case of a vector lying on the kernel. The explanation card in the tool links back to the matching section for whichever preset is active.

Projection onto a Coordinate Axis

On the x-axis preset the line is the x-axis, the kernel is the y-axis, and P=diag(1,0)P = \operatorname{diag}(1, 0): the map simply zeroes the second coordinate, (x,y)(x,0)(x, y) \mapsto (x, 0).

At the default v=(1.5,1.5)\mathbf{v} = (1.5, 1.5) the projection is (1.5,0)(1.5, 0), straight below v\mathbf{v}, and the residual is the vertical segment of length 1.51.5.
im Pker PPvv
x-axis projection, frozen

v = (1.5, 1.5) dropped straight down onto the x-axis: Pv = (1.5, 0). P = diag(1, 0) zeroes the second coordinate; the grid and unit square have collapsed onto the axis.

This is projection with all the trigonometry switched off. Both axes are eigendirections, with eigenvalue 11 along the x-axis and 00 along the y-axis, and the matrix is diagonal because the coordinate system already lines up with the image and kernel.

The y-axis preset is the transpose situation, diag(0,1)\operatorname{diag}(0, 1). Together the two axis projections add to the identity, the simplest instance of P+(IP)=IP + (I - P) = I.

Projection onto a Diagonal

On the y=xy = x preset every entry of PP is 12\tfrac{1}{2}, and the map sends (x,y)(x, y) to (x+y2,x+y2)\left(\tfrac{x + y}{2}, \tfrac{x + y}{2}\right): it averages the two coordinates and uses the average for both.

At the default v=(1.5,1.5)\mathbf{v} = (1.5, 1.5) the vector already lies on the line, so Pv=vP\mathbf{v} = \mathbf{v} and there is no dropline to draw. Drag v\mathbf{v} off the diagonal to see the perpendicular appear.
im Pker PPvv
y = x projection, frozen

v already lies on the diagonal, so Pv = (1.5, 1.5) = v and there is no perpendicular to drop. Every entry of P is 1/2; the kernel is the anti-diagonal.

The kernel is the anti-diagonal y=xy = -x, perpendicular to the image as it must be for an orthogonal projection. A vector with x=yx = -y has average 00 and projects to the origin.

The y=xy = -x preset is the complementary projection, with entries 12\tfrac{1}{2} on the diagonal and 12-\tfrac{1}{2} off it, and the two diagonal projections add to the identity. Any vector is the sum of its two diagonal shadows.

Projection onto a Custom Angle

On the 30°30° preset the unit direction is (cos30°,sin30°)(\cos 30°, \sin 30°) and PP has entries 34\tfrac{3}{4}, 34\tfrac{\sqrt{3}}{4}, 34\tfrac{\sqrt{3}}{4}, 14\tfrac{1}{4}. The off-diagonal entries are what mixing the coordinates looks like when the line is not an axis.

At the default v\mathbf{v} the projection lands on the 30°30° line at the foot of the perpendicular, and the residual runs along the 120°120° direction of the kernel.
im Pker PPvv
30° projection, frozen

Pv = (1.77, 1.02) at the foot of the perpendicular on the 30° line, with the residual running along the 120° kernel. Off-diagonal entries appear, but det P = 0 and tr P = 1 as always.

Whatever the angle, the diagonal entries add to 11 and the determinant is 00; only how the single unit of trace is shared between the two coordinates changes. The θ\theta slider makes this a continuous experiment.

The 120°120° preset is instructive for a different reason: it is the same line as 60°-60°, so P(120°)=P(60°)P(120°) = P(-60°), and the slider's range of 0° to 180°180° already covers every projection onto a line through the origin.

A Vector on the Kernel

The frozen picture below places v=(1.5,1.5)\mathbf{v} = (1.5, -1.5) on the kernel of the y=xy = x projection. It is perpendicular to the line, its dot product with the direction (1,1)(1, 1) is zero, and PvP\mathbf{v} is the origin, drawn as a dashed ring.

The residual is all of v\mathbf{v}: nothing of it survives the projection.
im Pker Pv
v on the kernel, frozen

v = (1.5, −1.5) is perpendicular to the y = x line, so Pv is the origin, drawn as a dashed ring. The whole vector is residual - the kernel made concrete.

This is the kernel made concrete. Every vector on the red line is sent to 0\mathbf{0}, and the morph animation shows why: as the plane flattens onto the image line, the whole kernel line is squeezed into a single point.

It is also the reason a projection has no inverse. Two different vectors on the kernel, or any vector and that vector plus a kernel vector, have the same projection, so the output does not determine the input. Every linear map with a non-trivial kernel fails to be invertible for exactly this reason.

The Matrix Card and the Angle Slider

The matrix card shows the four entries of PP for the current line and a slider for the angle θ\theta in degrees.

• The entries are cos2θ\cos^2\theta, cosθsinθ\cos\theta\sin\theta (twice), and sin2θ\sin^2\theta; the two diagonal entries always add to 11 and the matrix is always symmetric
• At 0° and 90°90° the off-diagonal entries vanish and PP is diag(1,0)\operatorname{diag}(1, 0) or diag(0,1)\operatorname{diag}(0, 1)
• At 45°45° every entry is 12\tfrac{1}{2}
• The slider runs from 0° to 180°180°, not 360°360°, because a line has no orientation: θ\theta and θ+180°\theta + 180° are the same line and the same matrix

Moving the slider clears the current preset. Every PP it produces is a rank-11 orthogonal projection; the family is one-dimensional, parametrized by the angle.

The Live Card

The live card reports the numbers behind the picture.

• v\|\mathbf{v}\| and Pv\|P\mathbf{v}\| — the lengths of the vector and its projection; the second never exceeds the first
• vPv\|\mathbf{v} - P\mathbf{v}\| — the residual, the distance from v\mathbf{v} to the line
• angle — between v\mathbf{v} and the line, so that Pv=vcos(angle)\|P\mathbf{v}\| = \|\mathbf{v}\| \cos(\text{angle})
• detP\det P and trP\operatorname{tr} P — always 00 and 11, the invariants of a rank-11 projection
• idempotence — a check that P(Pv)=PvP(P\mathbf{v}) = P\mathbf{v}, which holds by construction and is worth seeing stated

Pythagoras ties the first three together: v2=Pv2+vPv2\|\mathbf{v}\|^2 = \|P\mathbf{v}\|^2 + \|\mathbf{v} - P\mathbf{v}\|^2, because the projection and the residual are perpendicular.

What Orthogonal Projection Is

The orthogonal projection of v\mathbf{v} onto the line through the origin with unit direction u\mathbf{u} is

Pv=(vu)uP\mathbf{v} = (\mathbf{v} \cdot \mathbf{u})\,\mathbf{u}


the multiple of u\mathbf{u} closest to v\mathbf{v}. The remainder vPv\mathbf{v} - P\mathbf{v} is perpendicular to the line, which is why the construction is called dropping a perpendicular and why the canvas draws a right angle at the foot.

Because the formula is linear in v\mathbf{v}, projection is a linear transformation, and every linear transformation of the plane has a 2×22 \times 2 matrix. Writing u=(cosθ,sinθ)\mathbf{u} = (\cos\theta, \sin\theta) and expanding (vu)u=u(uTv)=(uuT)v(\mathbf{v} \cdot \mathbf{u})\,\mathbf{u} = \mathbf{u}(\mathbf{u}^T\mathbf{v}) = (\mathbf{u}\mathbf{u}^T)\,\mathbf{v} gives

P=uuT=(cos2θcosθsinθcosθsinθsin2θ)P = \mathbf{u}\mathbf{u}^T = \begin{pmatrix} \cos^2\theta & \cos\theta\sin\theta \\ \cos\theta\sin\theta & \sin^2\theta \end{pmatrix}


an outer product of a unit vector with itself. That form explains every property on the live card: rank 11 because it is an outer product, symmetric because uuT\mathbf{u}\mathbf{u}^T is, idempotent because uuTuuT=u(uTu)uT=uuT\mathbf{u}\mathbf{u}^T\mathbf{u}\mathbf{u}^T = \mathbf{u}(\mathbf{u}^T\mathbf{u})\mathbf{u}^T = \mathbf{u}\mathbf{u}^T, and trace 11 because tr(uuT)=uu=1\operatorname{tr}(\mathbf{u}\mathbf{u}^T) = \mathbf{u} \cdot \mathbf{u} = 1.

For the component-by-component computation of a single projection, see the vector projection visualizer; for projections onto subspaces of any dimension and the general projection matrix, see the projections theory page.

Kernel and Image

A projection is the cleanest example of a linear map with a non-trivial kernel.

• Image — the line itself. Every output lies on it, and every point of it is an output (it is its own projection), so imP\operatorname{im} P is exactly the line and rankP=1\operatorname{rank} P = 1
• Kernel — the perpendicular line. A vector perpendicular to u\mathbf{u} has vu=0\mathbf{v} \cdot \mathbf{u} = 0 and projects to the origin, and nothing else does
• Rank-nullity — 1+1=21 + 1 = 2, the dimension of the plane
• Orthogonal complement — kernel and image are perpendicular to each other, which is the defining feature of an orthogonal projection; an oblique projection has a kernel that is not perpendicular to its image, and a non-symmetric matrix

The morph animation shows the kernel at work: as tt reaches 11, every grid line parallel to the kernel is squeezed to a single point on the image line. For the general theory, see the image and kernel theory page.

Key Properties

Every orthogonal projection onto a line shares the same algebra, whatever the angle.

• Idempotent: P2=PP^2 = P
• Symmetric: PT=PP^T = P
• Rank 11: detP=0\det P = 0, trP=1\operatorname{tr} P = 1
• Eigenvalues: 11 along the line and 00 along the kernel; the two lines are the eigendirections
• Complement: IPI - P is the projection onto the perpendicular line, and P+(IP)=IP + (I - P) = I
• Shrinking: Pvv\|P\mathbf{v}\| \leq \|\mathbf{v}\|, with equality only for v\mathbf{v} on the line
• Closest point: PvP\mathbf{v} minimizes vw\|\mathbf{v} - \mathbf{w}\| over all w\mathbf{w} on the line
• Not invertible: a flattened plane cannot be restored; PP has no inverse