Skip to content

How to project one vector onto another

4 min read

Short answer

The projection of a\mathbf a onto b\mathbf b is the vector along b\mathbf b that is closest to a\mathbf a: proj⁡ba=a⋅bb⋅b b.\operatorname{proj}_{\mathbf b}\mathbf a=\frac{\mathbf a\cdot\mathbf b}{\mathbf b\cdot\mathbf b}\,\mathbf b. What is left over, a−proj⁡ba\mathbf a-\operatorname{proj}_{\mathbf b}\mathbf a, is perpendicular to b\mathbf b.

Diagrambaproj
The dashed segment is the leftover a − proj. It meets b at a right angle, which is exactly what defines the projection.

Where the formula comes from

You want the multiple cbc\mathbf b so that the leftover a−cb\mathbf a-c\mathbf b is perpendicular to b\mathbf b. Perpendicular means the dot product is 0: (a−cb)⋅b=0(\mathbf a-c\mathbf b)\cdot\mathbf b=0, so a⋅b=c b⋅b\mathbf a\cdot\mathbf b=c\,\mathbf b\cdot\mathbf b and c=a⋅bb⋅bc=\dfrac{\mathbf a\cdot\mathbf b}{\mathbf b\cdot\mathbf b}.

Scalar projection and uses

The length (with sign) of the shadow of a\mathbf a on b\mathbf b is a⋅b∣b∣\dfrac{\mathbf a\cdot\mathbf b}{|\mathbf b|}. Projection is the building block of Gram-Schmidt, least squares and the work done by a force along a direction.

Worked example

Project a=(1,3)\mathbf a=(1,3) onto b=(4,2)\mathbf b=(4,2).

a⋅b=4+6=10\mathbf a\cdot\mathbf b=4+6=10 and b⋅b=16+4=20\mathbf b\cdot\mathbf b=16+4=20, so c=1020=12c=\tfrac{10}{20}=\tfrac12 and proj⁡ba=12(4,2)=(2,1).\operatorname{proj}_{\mathbf b}\mathbf a=\tfrac12(4,2)=(2,1). Check: the leftover is (1,3)−(2,1)=(−1,2)(1,3)-(2,1)=(-1,2), and (−1,2)⋅(4,2)=−4+4=0(-1,2)\cdot(4,2)=-4+4=0, so it is perpendicular. ✓

Try it yourself

Project (2,2)(2,2) onto (1,3)(1,3).

Show the answer

a⋅b=2+6=8\mathbf a\cdot\mathbf b=2+6=8 and b⋅b=10\mathbf b\cdot\mathbf b=10, so the projection is 0.8(1,3)=(0.8, 2.4)0.8(1,3)=(0.8,\ 2.4).

Keep going with practice

Vidi's vector playground lets you drag two vectors and watch the projection and the perpendicular leftover update live.