Linear algebra · Orthogonality and least squares
The closest point to a vector on a line or subspace is found by projection, and the leftover error has a special direction.