Orthogonal Projection
The projection of u onto a line is the closest point on that line. The residual u − proj(u) is orthogonal to the line, which is the geometric heart of least squares.
The cyan arrow is the closest point to u on the line. The rose residual is perpendicular to the line — that right angle is exactly what makes least squares work. Change the direction or move u to see the projection and residual update.
What you are seeing
The projection length is (u · v) / |v|. The projected vector is that scalar times the unit direction of v.
The residual r = u − p is perpendicular to v, so the triangle has a right angle at p.
Among all points on the line, p minimizes the distance to u. This is why least squares finds the closest fit.
Why it matters
Projection is the geometry behind regression, Fourier coefficients, signal approximation, and solving inconsistent linear systems.
Complexity & details
Projection onto a line costs O(n) for vectors in Rⁿ. Projection onto a subspace solves a normal equation.
Frequently asked questions
Why is the residual orthogonal?+
If the residual had a component along the line, moving the projection slightly would reduce the distance. Minimal distance forces the residual to be perpendicular.
What if the vector is already on the line?+
Then the projection equals the vector and the residual is zero. The point is already the closest possible point.