Dot Products and Orthogonal Projection

Separate a vector into its component along a direction and a perpendicular residual.

Builds on Vectors, Linear Combinations and Systems · Subspaces, Null Spaces and Column Spaces

The bigger question: What is the closest answer when an exact fit is impossible?

On this page

Length and angle from a dot product

For real vectors, u⋅v=∑iuivi\mathbf u\cdot\mathbf v=\sum_i u_iv_i and ∥v∥=v⋅v\|\mathbf v\|=\sqrt{\mathbf v\cdot\mathbf v}. Nonzero vectors satisfy u⋅v=∥u∥∥v∥cos⁡θ\mathbf u\cdot\mathbf v=\|\mathbf u\|\|\mathbf v\|\cos\theta. Orthogonal vectors have zero dot product. The zero vector is orthogonal to every vector, but has no defined direction or angle.

The projection of b\mathbf b onto the line through nonzero a\mathbf a is

p=aTbaTaa.\mathbf p=\frac{\mathbf a^T\mathbf b}{\mathbf a^T\mathbf a}\mathbf a.

The residual r=b−p\mathbf r=\mathbf b-\mathbf p satisfies aTr=0\mathbf a^T\mathbf r=0. This condition derives the formula: solve aT(b−ca)=0\mathbf a^T(\mathbf b-c\mathbf a)=0 for cc.

Worked example: closest point on a line

For a=(1,1)T\mathbf a=(1,1)^T and b=(3,1)T\mathbf b=(3,1)^T, the coefficient is 4/2=24/2=2. Thus p=(2,2)T\mathbf p=(2,2)^T and r=(1,−1)T\mathbf r=(1,-1)^T. The residual is perpendicular to the line. Any other point p+ta\mathbf p+t\mathbf a has squared distance ∥r∥2+t2∥a∥2\|\mathbf r\|^2+t^2\|\mathbf a\|^2, so the projection is the closest point.

Explore

Projection and perpendicular residual

Try this. Set b = (3,1) and the angle to 45°: the projection is (2,2). Rotate the line to 0° and 90°. The residual remains perpendicular; at b = (0,0), all three vectors vanish.

Projection and perpendicular residual-4-4-2-22244xyBlue: b · Green: projection · Orange: residual
b = (3, 1). Line angle = 45°. Projection p = (2, 2); residual r = (1, -1). Distance to line = 1.41421. Unit line direction · residual = 0. b = p + r. A zero vector appears as a dot.

Rotate the target line and move the input vector. The projection stays on the line and the residual stays perpendicular. The displayed dot product should remain zero apart from floating-point rounding.

PAUSE & THINKA quick check, not a grade

Try it yourself.

Choose an answer and explain your reasoning to yourself. Use a hint if you get stuck.

Project v=(3,4) onto the x-axis. What are the projection and residual?

Hint 1 · Find a starting point

The projection lies on the chosen axis.

Hint 2 · Take the next step

The residual v−projection must be perpendicular to that axis.

Show the reasoning

Answer: (3,0) and (0,4)

(3,0)+(0,4)=(3,4), and the residual is perpendicular to every x-axis vector.

Before moving on: what would make one of the other answers wrong? Saying why is part of understanding.

Worked example: a projection matrix

For the same line, P=aaT/(aTa)=12(1111)P=\mathbf a\mathbf a^T/(\mathbf a^T\mathbf a)=\tfrac12\begin{pmatrix}1&1\\1&1\end{pmatrix}. It satisfies PT=PP^T=P and P2=PP^2=P. Projecting twice changes nothing after the first projection. The complementary matrix I−PI-P extracts the residual.

If a=0\mathbf a=0, the formula divides by zero. Projection onto the zero subspace is simply zero, but it must be defined separately from projection onto a direction.

Practice

  1. Project (2,3)T(2,3)^T onto the horizontal axis.
  2. Find the angle between (1,0)T(1,0)^T and (1,1)T(1,1)^T.
  3. Verify the length decomposition for the worked example.
Show worked solutions
  1. Projection (2,0)T(2,0)^T, residual (0,3)T(0,3)^T.
  2. cos⁡θ=1/2\cos\theta=1/\sqrt2, so θ=π/4\theta=\pi/4.
  3. ∥b∥2=10\|b\|^2=10, ∥p∥2=8\|p\|^2=8, ∥r∥2=2\|r\|^2=2, so 10=8+210=8+2.
MAKE IT YOURS

Pause before the next idea.

Can you explain how the visualization connects to this lesson’s goal? If a step still feels uncertain, put this lesson on your review list and try the check again another day.

Optional marks, not a grade. Saved in this browser only. Open notebook →