Orthogonality and Projections
Perpendicular means zero dot product. Projection splits any vector into a parallel part plus a perpendicular leftover, which is how clean bases get built.
Why Does This Exist?
Least squares, Fourier series, PCA, and attention all throw away the part they cannot use and keep the part they can. Without a clean split, the leftover leaks into the kept part: correlated features double count evidence, non-orthogonal bases entangle coefficients, and denoising removes signal with the noise.
Orthogonality makes the split clean. Two vectors are orthogonal when their dot product is zero, meaning they share no direction. Projection drops one vector onto another (or onto a subspace), leaving a residual that is orthogonal to everything kept. Lengths come from norms, and the full basis-building payoff is PCA derivation. This page covers the split, the formula, and the 3-4-5 check.
The one idea you need first
For unit direction with , the projection of along is : how far reaches in that direction, laid back along it. The residual is perpendicular by construction. For general , divide by the squared length: .
Think of It Like This
Noon shadow on a straight road
Sun directly overhead throws your shadow straight onto the road centerline. Your full height is the vector ; the shadow on the road is the projection; the vertical drop from your head to the shadow tip is the residual, perpendicular to the road.
The shadow length tells how far along the road you reach, nothing about height. Where it stops: shadows collapse a dimension, so many heights share one shadow. Projection likewise keeps one part and parks the rest in the residual, recoverable only by adding it back.
How It Actually Works
Orthogonal means . Projection keeps the parallel part and parks the rest: with . Only the parallel part survives a second projection, which is why orthogonal bases decouple coefficients. Gram-Schmidt repeats this: take the next vector, subtract its projections onto every kept direction, keep the residual. Each residual is orthogonal to all previous ones by construction.
Worked example
Take and unit direction along the x-axis. Dot: . Projection: . Residual: . Check: , so perpendicular. Lengths: , , , and . The diagram draws exactly this right triangle.
Code
import numpy as np
def project(v: np.ndarray, u: np.ndarray) -> np.ndarray: return ((v @ u) / (u @ u)) * u # scale by overlap over squared length
v = np.array([4.0, 3.0])u = np.array([1.0, 0.0])p = project(v, u)print(p.tolist()) # -> [4.0, 0.0]print((v - p).tolist()) # -> [0.0, 3.0]print(float(u @ (v - p))) # -> 0.0Parallel part plus perpendicular leftover, with zero dot product confirming the split.
Watch Out For
Using the unit formula on a non-unit direction
without dividing by scales the answer by . With , it reports instead of , and the residual is not perpendicular: .
Symptom: residual dot product nonzero, lengths violating Pythagoras. Fix: always use , or normalize first and use . Test on against where the answer must be .
Projecting onto correlated axes one at a time
Subtracting the projection onto then onto works only when . When axes correlate, the second subtraction reintroduces a component, so coefficients entangle and the residual still points along kept directions.
Symptom: residual dot products against kept axes are nonzero, and refitting changes earlier coefficients. Fix: orthogonalize first (Gram-Schmidt), or solve the joint normal equations instead of projecting sequentially.
The Quick Version
- Orthogonal means zero dot product: no shared direction.
- Projection splits into parallel plus residual perpendicular to .
- Example along gives plus with dot zero and lengths 3 4 5.
- General formula divides by squared length: .
- Gram-Schmidt repeats the split to build orthogonal bases; PCA lives on the same split.
- Unit formula on non-unit vectors and sequential projection onto correlated axes both silently fail.