Linear Algebra, Interactive EditionXYZ Homework Edition

⇩ Download ▾

0.7 Projection onto a Line

A force pushing a sled up a slope does two things at once: part of it moves the sled along the slope, and part of it presses the sled into the slope. Splitting the force into those two parts — one along a direction, one across it — is the operation this section builds. Given a vector 𝐯\mathbf{v} and a nonzero direction 𝐝\mathbf{d}, we want 𝐯=𝐯+𝐯\mathbf{v} = \mathbf{v}_{\parallel} + \mathbf{v}_{\perp} with 𝐯\mathbf{v}_{\parallel} a multiple of 𝐝\mathbf{d} and 𝐯\mathbf{v}_{\perp} orthogonal to 𝐝\mathbf{d}. The part along 𝐝\mathbf{d} is called the projection of 𝐯\mathbf{v} onto 𝐝\mathbf{d}; its tip is the foot of the perpendicular dropped from the tip of 𝐯\mathbf{v} onto the line through 𝐝\mathbf{d}.

The figure lives in the plane, where a right angle is a right angle from every viewpoint. The direction 𝐝=(2,1)\mathbf{d} = (2, 1) is fixed, the line of its multiples is dashed, and 𝐯=(a,b)\mathbf{v} = (a, b) is on two sliders.

Interactive figureThe projection of v onto the line through dDrag the v, x-component and v, y-component sliders.
A dashed gray line through the origin with slope one half, a short gray arrow d along it to (2, 1), and a red arrow v from the origin to (a, b), set by two sliders starting at (1, 3). A blue arrow from the origin along the dashed line is the projection of v onto d, and a dashed green arrow from the tip of the projection to the tip of v is the perpendicular part, meeting the line at a right angle. At the starting values the projection coincides with d itself. Dragging the sliders moves the red tip; the blue foot slides along the line so that the green arrow always stays perpendicular to it, shrinking to nothing when v is dragged onto the line and becoming all of v when v is dragged perpendicular to it. Adjustable parameters: v, x-component (a) = 1, v, y-component (b) = 3. Viewing window: x from -4.96 to 6.56, y from -2.38 to 4.58.
XYZ Graph · viewer build 5edf91b
The direction 𝐝=(2,1)\mathbf{d} = (2, 1) and the vector 𝐯=(a,b)\mathbf{v} = (a, b) in red. The blue arrow along the dashed line is the projection of 𝐯\mathbf{v} onto 𝐝\mathbf{d}; the dashed green arrow from its tip to the tip of 𝐯\mathbf{v} is the perpendicular part, and the two add back to 𝐯\mathbf{v}.

Explore the figure

  1. At the starting values 𝐯=(1,3)\mathbf{v} = (1, 3), the blue projection is exactly 𝐝=(2,1)\mathbf{d} = (2, 1), and the green perpendicular part runs from (2,1)(2, 1) to (1,3)(1, 3): head minus tail gives (1,2)(-1, 2). Check the right angle by the last section's test: (1,2)·(2,1)=2+2=0(-1, 2) \cdot (2, 1) = -2 + 2 = 0.
  2. Drag bb to 0.5-0.5. The red vector now points below the line, and the projection shrinks to (0.6,0.3)(0.6, 0.3) — three tenths of 𝐝\mathbf{d}. The perpendicular part (0.4,0.8)(0.4, -0.8) drops from the line downward.
  3. Set a=1a = -1 and b=2b = 2. The red vector is perpendicular to 𝐝\mathbf{d} and the blue arrow vanishes: the projection is the zero vector, and the perpendicular part is all of 𝐯\mathbf{v}.
  4. Set a=4a = 4 and b=2b = 2, so that 𝐯=2𝐝\mathbf{v} = 2\mathbf{d}. Now the green arrow vanishes instead: a vector already on the line is its own projection.
  5. Sweep aa across its range with bb fixed and watch the blue foot slide along the line. Whatever the red tip does, the green arrow meets the dashed line at a right angle. That right angle is the definition, and the formula below is what it forces.

Solving for the scalar

The parallel part is some multiple k𝐝k\mathbf{d}; the whole problem is finding kk. Dot both sides of 𝐯=k𝐝+𝐯\mathbf{v} = k\mathbf{d} + \mathbf{v}_{\perp} with 𝐝\mathbf{d}:

𝐯 · 𝐝 = k ( 𝐝 · 𝐝 ) + 𝐯 · 𝐝 = k | 𝐝 | 2 + 0 \mathbf{v} \cdot \mathbf{d} = k \, (\mathbf{d} \cdot \mathbf{d}) + \mathbf{v}_{\perp} \cdot \mathbf{d} = k \, |\mathbf{d}|^2 + 0

The perpendicular part contributed nothing, because it is orthogonal to 𝐝\mathbf{d} — that is the only thing we asked of it, and it is enough. So k=𝐯·𝐝/|𝐝|2k = \mathbf{v} \cdot \mathbf{d} / |\mathbf{d}|^2, and

proj 𝐝 𝐯 = 𝐯 · 𝐝 𝐝 · 𝐝 𝐝 , 𝐯 = 𝐯 proj 𝐝 𝐯 \operatorname{proj}_{\mathbf{d}} \mathbf{v} = \frac{\mathbf{v} \cdot \mathbf{d}}{\mathbf{d} \cdot \mathbf{d}} \, \mathbf{d}, \qquad \mathbf{v}_{\perp} = \mathbf{v} - \operatorname{proj}_{\mathbf{d}} \mathbf{v}

At the figure's starting values, 𝐯·𝐝=2+3=5\mathbf{v} \cdot \mathbf{d} = 2 + 3 = 5 and 𝐝·𝐝=5\mathbf{d} \cdot \mathbf{d} = 5, so k=1k = 1 and the projection is 𝐝\mathbf{d} itself, as step 1 found. Notice that replacing 𝐝\mathbf{d} by 2𝐝2\mathbf{d} multiplies the numerator by 22 and the denominator by 44, and the extra factor of 𝐝\mathbf{d} restores the balance: the projection depends on the line, not on which vector along it was chosen to name the direction.

For the fixed direction (2,1)(2, 1) the formula is a recipe with two inputs, aa and bb, and two outputs. Writing it out, k=(2a+b)/5k = (2a + b)/5 and the projection is (2(2a+b)/5,(2a+b)/5)=((4a+2b)/5,(2a+b)/5)\big( 2(2a + b)/5, \; (2a + b)/5 \big) = \big( (4a + 2b)/5, \; (2a + b)/5 \big) — each output a fixed combination of the inputs. That is exactly what a matrix does, and Chapter 3 will call the array of coefficients, with rows (4/5,2/5)(4/5, \; 2/5) and (2/5,1/5)(2/5, \; 1/5), the projection matrix. It appears below as a machine check on step 1.

[21]\begin{bmatrix}2 \\ 1\end{bmatrix}
The projection at the figure's starting values ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text The projection at the figure's starting values, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The projection recipe for the direction (2,1)(2, 1), written as the matrix with rows (4/5,2/5)(4/5, 2/5) and (2/5,1/5)(2/5, 1/5) and applied by a computer algebra system to 𝐯=(1,3)\mathbf{v} = (1, 3): the output is (2,1)(2, 1), the direction vector itself, as step 1 observed.

11
A projection onto a line has rank 1 ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text A projection onto a line has rank 1, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The same array with its common factor 1/51/5 removed. Its rank is 11: every output of the recipe lies on one line, the dashed line of the figure. Chapter 3 reads this number as the dimension of everything a matrix can reach.

[2,1]\left[ 2,\; 1 \right]
The projection at the figure's starting values ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text The projection at the figure's starting values, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The figure's own numbers, computed by the projection op rather than by the matrix above: proj𝐝𝐯=(2,1)\operatorname{proj}_{\mathbf{d}} \mathbf{v} = (2, 1), which is 𝐝\mathbf{d} itself — step 1's observation, certified.

[1,2]\left[ -1,\; 2 \right]
And the perpendicular part ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text And the perpendicular part, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The other half of the same split, asked for by name. The engine returns (1,2)(-1, 2), the dashed arrow of step 1, and the two parts add back to 𝐯=(1,3)\mathbf{v} = (1, 3).

00
The right angle that forces the formula ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text The right angle that forces the formula, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The perpendicular part dotted with the direction. Zero — which is not a happy accident but the single condition the derivation solved for, and the reason the whole formula has one unknown.

[53,53,53]\left[ \frac{5}{3},\; \frac{5}{3},\; \frac{5}{3} \right]
The worked example's parallel part ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text The worked example's parallel part, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The vector from PP to AA projected onto the line's direction: (5/3,5/3,5/3)(5/3, \; 5/3, \; 5/3).

[13,23,13]\left[ \frac{1}{3},\; -\frac{2}{3},\; \frac{1}{3} \right]
Its perpendicular part ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text Its perpendicular part, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

What is left over: (1/3,2/3,1/3)(1/3, \; -2/3, \; 1/3).

13·6\frac{1}{3} \cdot \sqrt{6}
And the distance to the line ✓ Computed · mojocas 0.1.0 ✓ Agrees with the text And the distance to the line, computed exactly by mojocas 0.1.0, and confirmed to agree with the result stated in the text.

The length of that leftover, which is the distance from AA to the line: 6/3\sqrt{6}/3. The engine writes it with the root in the numerator; the prose writes the same number as 2/3\sqrt{2/3}, and stating either one certifies against the other because the check is by value, not by spelling.

An original work of XYZ Homework, built around interactive XYZ 3D figures. Its chapter sequence is aligned to Interactive Linear Algebra (Margalit & Rabinoff, Georgia Tech, GNU FDL); this work is original, copies nothing from it, and is not affiliated with or endorsed by its authors. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.