What projection means

The projection of mathbfamathbf{a} onto mathbfbmathbf{b} keeps only the part of mathbfamathbf{a} that points in the same direction as mathbfbmathbf{b}.

The dot product measures alignment, and dividing by mathbfbcdotmathbfbmathbf{b}cdotmathbf{b} turns that alignment into the correct scale factor for vector mathbfbmathbf{b}.

The leftover error is the perpendicular part that cannot sit on vector B.

Good sanity checks

  • If A already points along B, the projection matches A exactly.
  • If A is perpendicular to B, the projection becomes the zero vector.
  • A zero target vector cannot be used because it has no direction to project onto.