What is Projection?
The projection of vector \(\vec{a}\) onto vector \(\vec{b}\) is the vector component of \(\vec{a}\) that lies along \(\vec{b}\).
Vector projection of \(\vec{a}\) onto \(\vec{b}\):
\[\text{proj}_{\vec{b}}\vec{a} = \frac{\vec{a} \cdot \vec{b}}{|\vec{b}|^2}\vec{b} = \frac{\vec{a} \cdot \vec{b}}{\vec{b} \cdot \vec{b}}\vec{b}\]
Scalar projection (just the length):
\[\text{comp}_{\vec{b}}\vec{a} = \frac{\vec{a} \cdot \vec{b}}{|\vec{b}|}\]
Example
Project (3, 4) onto (1, 0)
a · b = 3(1) + 4(0) = 3
|b|² = 1² + 0² = 1
proj = (3/1)(1, 0) = (3, 0)
The x-component of (3, 4) is 3, as expected!
Geometric Interpretation
Think of projection as dropping a perpendicular from the tip of \(\vec{a}\) onto the line defined by \(\vec{b}\). The projection is where it lands.
Applications
- Physics: Work done by force in a direction
- Graphics: Shadow calculations, lighting
- ML: Dimensionality reduction (PCA)
- Game dev: Collision response
Code Example
function project(a, b) {
const dot = a.reduce((s, v, i) => s + v * b[i], 0);
const magSq = b.reduce((s, v) => s + v * v, 0);
const scalar = dot / magSq;
return b.map(v => v * scalar);
}
project([3, 4], [1, 0]); // [3, 0]
💡
Vector Projection Explained Simply
Imagine holding a flashlight directly above a stick and shining it straight down onto the floor. The shadow the stick casts is essentially what vector projection does—it shows you how much of one vector "falls" along the direction of another. If you have vector A and want to know how much of it points in the direction of vector B, projection gives you that answer as a new vector lying perfectly along B.
Think of it like breaking a force into components. When you push a shopping cart at an angle, only part of your push actually moves the cart forward—the rest is wasted pushing it into the ground. Vector projection mathematically extracts just that useful "forward" part. The result is a vector that has the same direction as B but a length that represents how much A contributes in that direction.
The formula uses the dot product because it naturally measures how aligned two vectors are. When you calculate (A · B) / |B|², you're finding the scaling factor that tells you how many "units of B" fit into the shadow of A. Multiply that scalar by B itself, and you get the projection vector—a scaled version of B that represents A's component along that direction.
This concept appears everywhere in real life. In physics, it calculates work done by a force (only the component parallel to motion counts). In computer graphics, it determines how light hits surfaces. In machine learning, projection is the foundation of dimensionality reduction techniques like PCA, where high-dimensional data is projected onto fewer dimensions while preserving the most important information.