Vector projection: dropping a onto b
The component of one vector that lies along another — the geometric move behind least-squares regression, Gram-Schmidt, and almost every dot-product application.
What this shows
Given two vectors a and b in the plane, the projection of a onto b — written proj_b(a) — is the vector that lies along b and reaches the foot of the perpendicular dropped from the tip of a onto the line through b. In formula form:
proj_b(a) = (a · b / |b|²) · b
where a · b is the dot product and |b|² = b · b. The dot product captures how much of a points in the b-direction; you divide by |b|² to convert that into a length along b, then multiply by b itself to make it a vector.
For a = (4, 3) and b = (5, 0):
a · b = 4·5 + 3·0 = 20
|b|² = 25 + 0 = 25
scalar = 20 / 25 = 4/5
proj = (4/5) · (5, 0) = (4, 0)Geometrically: b lies on the x-axis, so projecting any vector onto b just keeps its x-component. The figure shows a as the full arrow, proj_b(a) as the shorter arrow along b, and a dashed perpendicular dropping from the tip of a to the tip of the projection.
Where it shows up
Projections are the geometric core of least-squares regression: when you fit a line to noisy data, the fitted line minimises the sum of squared perpendicular distances, which is exactly the projection of the data vector onto the column space of the design matrix.
They are also the engine of the Gram-Schmidt process, which turns any basis into an orthonormal one by successively subtracting off projections. In computer graphics, the shading model at every pixel depends on the projection of the light direction onto the surface normal — Lambert's cosine law in disguise.
Frequently asked questions
What if a is perpendicular to b?
Then a · b = 0, the scalar coefficient is 0, and proj_b(a) is the zero vector. This is exactly what you'd expect — a has no component along b — and it's the test that two vectors are perpendicular in the first place.
Why divide by |b|² instead of |b|?
The dot product a · b is proportional to |b|, so to extract the *length* of a along b (a scalar called the scalar projection) you divide by |b|. To then turn that scalar back into a *vector* along b you multiply by b/|b|. Combined, you divide once by |b| and once by |b|, i.e. once by |b|².
Is proj_b(a) the same as proj_a(b)?
Not in general — the projection of a onto b lives on the line through b, while the projection of b onto a lives on the line through a. They agree only in trivial cases (e.g., when a and b are parallel).
Does this work in 3D?
Yes — and in any dimension. The formula proj_b(a) = (a·b / |b|²)·b is identical; the dot product just sums more components. The same idea works in function spaces too (e.g. Fourier coefficients are projections onto sin and cos basis functions).