Skip to content

Projections

Find the nearest point of a plane, see why the leftover meets it at a right angle, and build the projection matrix.

Helps to know first
This topic

First, the picture

A point floats above a tilted plane. Which point of the plane is nearest? Watch three ways down, and see which is shortest.

Closest point

Three ways from b down to the plane C(B). Which is shortest?

The plane of B's columns, where the third number is the sum of the first two, and the point b = (1, 2, 6).

closest point p
–
length of e
–
straight down
–
0.00 / 9.10 s
Describe this picture

A slowly turning view of three axes in space, a tilted plane through the origin, and the point b=(1,2,6)\mathbf{b}=(1,2,6) above it. The plane is every point whose third number is the sum of the first two. In turn, three paths drop from b\mathbf{b} to the plane, each labelled with its length. The first goes straight down, parallel to the third axis, and lands at (1,2,3)(1,2,3): length 3. The second slants and lands at (2,2,4)(2,2,4): length 2.236. The third lands at p=(2,3,5)\mathbf{p}=(2,3,5), where it meets the plane at a right angle, marked with a small square; it is 1.732 long and drawn thicker than the others, which fade. Readouts give p\mathbf{p}, the length of the leftover e\mathbf{e}, and the straight-down length. When the clip has finished, b\mathbf{b} can be dragged, or moved with the arrow keys in steps of 0.5: left and right along the floor, up and down along the third axis. The three drops follow it, the right angle holds, and the readouts change.

Straight down is not the shortest

Most people expect the nearest point to be straight below, as if the point fell under gravity. The picture says otherwise. Straight down is 3 long. A slanted path to (2,2,4)(2,2,4) is shorter, 2.236. The shortest path of all, 1.732 long, lands at (2,3,5)(2,3,5), and it is the one that meets the plane at a right angle.

That is the rule for the nearest point. Call it p\mathbf{p}, and call what is left over e=b−p\mathbf{e}=\mathbf{b}-\mathbf{p}. I write the leftover in bold, e\mathbf{e}, with no number under it; the unit arrows e1,e2\mathbf{e}_1,\mathbf{e}_2 always carry a number. At the nearest point, e\mathbf{e} is at a right angle to the plane.

Why is that the nearest? Take any other point q\mathbf{q} of the plane. The step from p\mathbf{p} to q\mathbf{q} lies in the plane, so it is at a right angle to e\mathbf{e}. The path from b\mathbf{b} to q\mathbf{q} is the leftover followed by that step, and by the right-angle rule for lengths,

∥b−q∥2=∥e∥2+∥p−q∥2.\lVert\mathbf{b}-\mathbf{q}\rVert^2=\lVert\mathbf{e}\rVert^2+\lVert\mathbf{p}-\mathbf{q}\rVert^2 .

So every other point is farther. For q=(1,2,3)\mathbf{q}=(1,2,3), the point straight below: 9=3+69=3+6.

After the clip, drag b\mathbf{b}. The foot follows it, and the right angle never breaks. Drag b\mathbf{b} straight along the right-angle path, and the foot does not move at all.

Onto a line

Start with the simplest case, which you met as a shadow in Length and the dot product: project b=(1,2)\mathbf{b}=(1,2) onto the line through a=(2,1)\mathbf{a}=(2,1).

Shadow on a line

The point of a line closest to b is the foot of a right angle.

The arrow a = (2, 1), its line, and the arrow b = (1, 2).

p
–
e = b − p
–
0.00 / 5.20 s
Describe this picture

The plane with the arrow a=(2,1)\mathbf{a}=(2,1), its line drawn dashed through the origin, and the arrow b=(1,2)\mathbf{b}=(1,2). A dashed path drops from the tip of b\mathbf{b} to the line at a right angle, marked with a small square. The foot, p=(1.6,0.8)\mathbf{p}=(1.6,0.8), is labelled, and the leftover e=(−0.6,1.2)\mathbf{e}=(-0.6,1.2) is drawn from the foot to the tip of b\mathbf{b}. The picture has no control.

The foot is some multiple of a\mathbf{a}, say p=c a\mathbf{p}=c\,\mathbf{a}. The leftover b−c a\mathbf{b}-c\,\mathbf{a} must be at a right angle to a\mathbf{a}, so its dot product with a\mathbf{a} is zero:

a⋅(b−c a)=0⟹c=a⋅ba⋅a,p=a⋅ba⋅a a.\mathbf{a}\cdot(\mathbf{b}-c\,\mathbf{a})=0 \quad\Longrightarrow\quad c=\frac{\mathbf{a}\cdot\mathbf{b}}{\mathbf{a}\cdot\mathbf{a}},\qquad \mathbf{p}=\frac{\mathbf{a}\cdot\mathbf{b}}{\mathbf{a}\cdot\mathbf{a}}\,\mathbf{a}.

Here a⋅b=2+2=4\mathbf{a}\cdot\mathbf{b}=2+2=4 and a⋅a=5\mathbf{a}\cdot\mathbf{a}=5, so c=0.8c=0.8, p=(1.6,0.8)\mathbf{p}=(1.6,0.8) and e=(−0.6,1.2)\mathbf{e}=(-0.6,1.2). Check the right angle: a⋅e=−1.2+1.2=0\mathbf{a}\cdot\mathbf{e}=-1.2+1.2=0. And the lengths: ∥p∥2+∥e∥2=3.2+1.8=5=∥b∥2\lVert\mathbf{p}\rVert^2+\lVert\mathbf{e}\rVert^2=3.2+1.8=5=\lVert\mathbf{b}\rVert^2.

Onto a plane

Now the plane at the top of the page. It is the column space C(B)C(\mathbf{B}) of

B=[100111],\mathbf{B}=\begin{bmatrix}1&0\\0&1\\1&1\end{bmatrix},

the plane where the third number is the sum of the first two, from The four fundamental subspaces. Every point of it is Bx\mathbf{B}\mathbf{x} for some weights x\mathbf{x}, so the foot is p=Bx^\mathbf{p}=\mathbf{B}\hat{\mathbf{x}} for the right weights x^\hat{\mathbf{x}}. The hat marks the best choice.

The leftover must be at a right angle to the whole plane, which means at a right angle to both columns. Two dot products must be zero, and together they are one matrix equation:

B⊤(b−Bx^)=0⟹B⊤B x^=B⊤b.\mathbf{B}^\top(\mathbf{b}-\mathbf{B}\hat{\mathbf{x}})=\mathbf{0} \quad\Longrightarrow\quad \mathbf{B}^\top\mathbf{B}\,\hat{\mathbf{x}}=\mathbf{B}^\top\mathbf{b}.

These are the normal equations; “normal” is an old word for “at a right angle”. Here B⊤B=[2112]\mathbf{B}^\top\mathbf{B}=\begin{bmatrix}2&1\\1&2\end{bmatrix} and B⊤b=(7,8)\mathbf{B}^\top\mathbf{b}=(7,8). Solving, x^=13(2⋅7−8, −7+2⋅8)=(2,3)\hat{\mathbf{x}}=\tfrac13(2\cdot7-8,\ -7+2\cdot8)=(2,3). So p=Bx^=(2,3,5)\mathbf{p}=\mathbf{B}\hat{\mathbf{x}}=(2,3,5) and e=(−1,−1,1)\mathbf{e}=(-1,-1,1).

Check: B⊤e=(−1+1, −1+1)=0\mathbf{B}^\top\mathbf{e}=(-1+1,\ -1+1)=\mathbf{0}. So e\mathbf{e} lies in the left null space N(B⊤)N(\mathbf{B}^\top), the line of (1,1,−1)(1,1,-1) on that page. The lengths split as before: ∥b∥2=41=38+3\lVert\mathbf{b}\rVert^2=41=38+3.

That is the whole picture of a projection. The column space and the left null space meet at a right angle, and every b\mathbf{b} splits into one piece in each: b=p+e\mathbf{b}=\mathbf{p}+\mathbf{e}.

The projection matrix

Put the steps together. x^=(B⊤B)−1B⊤b\hat{\mathbf{x}}=(\mathbf{B}^\top\mathbf{B})^{-1}\mathbf{B}^\top\mathbf{b}, and p=Bx^\mathbf{p}=\mathbf{B}\hat{\mathbf{x}}, so p=Pb\mathbf{p}=\mathbf{P}\mathbf{b} with

P=B(B⊤B)−1B⊤=13[2−11−121112].\mathbf{P}=\mathbf{B}(\mathbf{B}^\top\mathbf{B})^{-1}\mathbf{B}^\top=\frac13\begin{bmatrix}2&-1&1\\-1&2&1\\1&1&2\end{bmatrix}.

This P\mathbf{P} is the projection matrix. It is not the permutation matrix of Transposes and permutations, which shares the letter. Check it: Pb=13(6,9,15)=(2,3,5)\mathbf{P}\mathbf{b}=\tfrac13(6,9,15)=(2,3,5).

Three facts about P\mathbf{P} follow from the picture.

  • Projecting twice changes nothing. A point already on the plane is its own nearest point: P(2,3,5)=(2,3,5)\mathbf{P}(2,3,5)=(2,3,5). So P2=P\mathbf{P}^2=\mathbf{P}.
  • It is symmetric. P⊤=P\mathbf{P}^\top=\mathbf{P}, as you can read off the matrix above.
  • It cannot be undone. Every point on the right-angle path through b\mathbf{b} lands on the same foot, so no matrix can send the foot back to the one you started from. P\mathbf{P} has no inverse.

The diagonal of P\mathbf{P} adds up to 13(2+2+2)=2\tfrac13(2+2+2)=2, the dimension of the plane. For a line, the projection matrix is aa⊤/(a⊤a)\mathbf{a}\mathbf{a}^\top/(\mathbf{a}^\top\mathbf{a}): for a=(2,1)\mathbf{a}=(2,1) it is [0.80.40.40.2]\begin{bmatrix}0.8&0.4\\0.4&0.2\end{bmatrix}, and its diagonal adds up to 1.

Worked example

  1. Onto a line. (1,2)(1,2) onto the line of (2,1)(2,1): p=0.8 (2,1)=(1.6,0.8)\mathbf{p}=0.8\,(2,1)=(1.6,0.8) and e=(−0.6,1.2)\mathbf{e}=(-0.6,1.2).
  2. Onto a plane. (1,2,6)(1,2,6) onto the plane of B\mathbf{B}: x^=(2,3)\hat{\mathbf{x}}=(2,3), p=(2,3,5)\mathbf{p}=(2,3,5), e=(−1,−1,1)\mathbf{e}=(-1,-1,1).
  3. Already there. If b\mathbf{b} is on the plane, e=0\mathbf{e}=\mathbf{0} and p=b\mathbf{p}=\mathbf{b}.
  4. Twice. PP=P\mathbf{P}\mathbf{P}=\mathbf{P}.
  5. The diagonal. For a projection onto a plane in three dimensions, the diagonal of P\mathbf{P} adds up to 2.
  6. Predict. Drag b\mathbf{b} along the right-angle path through it. The foot stays where it is.

Where you’ll meet this

A mains hum has a known shape. Suppose the shape is u=(1,0,−1,0)\mathbf{u}=(1,0,-1,0) and a recording is x=(4,1,0,1)\mathbf{x}=(4,1,0,1). The hum’s share is (u⋅x)/(u⋅u)=4/2=2(\mathbf{u}\cdot\mathbf{x})/(\mathbf{u}\cdot\mathbf{u})=4/2=2, and removing it leaves x−2u=(2,1,2,1)\mathbf{x}-2\mathbf{u}=(2,1,2,1), which is at a right angle to u\mathbf{u}.

Removing the mean of a list is a projection too. Project (2,4,6)(2,4,6) onto (1,1,1)(1,1,1): the foot is (4,4,4)(4,4,4), the mean repeated, and the leftover (−2,0,2)(-2,0,2) is the list with its mean removed. The shadow of a game character under an overhead light is a projection onto the floor, with the matrix that keeps the first two numbers and sets the height to 0.

In signal processing · orthogonal projection

The Wiener filter is a projection: its error is at a right angle to every input sample it uses, and its equations are the normal equations of this page. Resonators, notches and combs removes a hum with a notch, a soft version of this projection. One difference in counting: vector entries count from 1 here, while samples x[n]x[n] count from 0 there.

Where this leads · fitting data

When Ax=b\mathbf{A}\mathbf{x}=\mathbf{b} has no exact answer, the best one projects b\mathbf{b} onto the column space. That is Least squares.

Reference card

QuantityFormulaNotes
Splitb=p+e\mathbf{b}=\mathbf{p}+\mathbf{e}e\mathbf{e} at a right angle to the subspace
Onto a linep=a⋅ba⋅a a\mathbf{p}=\dfrac{\mathbf{a}\cdot\mathbf{b}}{\mathbf{a}\cdot\mathbf{a}}\,\mathbf{a}the shadow
Normal equationsB⊤B x^=B⊤b\mathbf{B}^\top\mathbf{B}\,\hat{\mathbf{x}}=\mathbf{B}^\top\mathbf{b}e\mathbf{e} is perpendicular to every column
Footp=Bx^\mathbf{p}=\mathbf{B}\hat{\mathbf{x}}in C(B)C(\mathbf{B})
Leftovere=b−p\mathbf{e}=\mathbf{b}-\mathbf{p}in N(B⊤)N(\mathbf{B}^\top)
Projection matrixP=B(B⊤B)−1B⊤\mathbf{P}=\mathbf{B}(\mathbf{B}^\top\mathbf{B})^{-1}\mathbf{B}^\topP2=P\mathbf{P}^2=\mathbf{P}, P⊤=P\mathbf{P}^\top=\mathbf{P}, no inverse
Lengths∥b∥2=∥p∥2+∥e∥2\lVert\mathbf{b}\rVert^2=\lVert\mathbf{p}\rVert^2+\lVert\mathbf{e}\rVert^2the right-angle rule

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look