Module 7: Orthogonality
Projection answers a simple question: given a vector a and a direction b, what is the component of a along b?
The projection of a onto b is:
Read this as: "how much of a points in the b direction, times the b direction." The scalar ∣b∣2a⋅b is how far along b the foot of the perpendicular falls.
Every vector splits cleanly into two perpendicular parts:
The remainder a−projb(a) is always perpendicular to b. You can verify: take the dot product — it's zero.
This generalizes: you can project onto a plane, or any subspace. The projection matrix is P=A(ATA)−1AT. Applying P to any vector gives its component in the subspace.
Drag vector a (blue) and direction b (pink). The green arrow shows the projection. The dashed purple line is the perpendicular remainder. Notice that as a approaches the b direction, the projection equals a; when a is perpendicular to b, the projection is zero.
import numpy as np
a = np.array([3.0, 3.0])
b = np.array([4.0, 1.0])
scalar = np.dot(a, b) / np.dot(b, b)
proj = scalar * b
perp = a - proj
print(proj) # projection along b
print(np.dot(perp, b)) # ~0 — perpendicular checkproj_b(a) = [3.53, 0.88] |proj| = 3.64
perpendicular component = [-0.53, 2.12] |perp| = 2.18
Green arrow = projection of a onto b. The dashed line is the remainder — perpendicular to b.