Vector Projection

Project one vector onto another to find the component in that direction.

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}\).

The Formula

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.

Frequently Asked Questions

What is vector projection?

Vector projection is a mathematical operation that takes one vector and "projects" it onto another vector, giving you the component of the first vector that lies along the direction of the second. It's like finding the shadow of one vector cast onto another when light shines perpendicular to the second vector.

How do you calculate vector projection?

To project vector A onto vector B, use the formula: proj_B(A) = (A · B / |B|²) × B. First calculate the dot product of A and B, divide by the squared magnitude of B, then multiply that scalar by vector B. This gives you a vector in the direction of B with the appropriate length.

What is the difference between scalar and vector projection?

Scalar projection gives you just a number (the signed length of the projection), calculated as (A · B) / |B|. Vector projection gives you an actual vector with both magnitude and direction, calculated as (A · B / |B|²) × B. The scalar projection can be negative if the vectors point in generally opposite directions, while the vector projection will point opposite to B in that case.

What is the difference between projection and component?

The terms are often used interchangeably, but technically "component" usually refers to the scalar projection (just the length), while "projection" refers to the vector result. When someone says "the component of A along B," they typically mean the scalar value, whereas "the projection of A onto B" usually means the resulting vector.

Why do we use the dot product for projection?

The dot product naturally measures how much two vectors point in the same direction. It equals |A| × |B| × cos(θ), where θ is the angle between them. When we divide by |B|², we normalize out B's length, leaving us with just the portion of A that aligns with B's direction. This geometric relationship makes the dot product the perfect tool for projection.

Can vector projection be negative?

The scalar projection can be negative when the angle between vectors is greater than 90 degrees, meaning they point in generally opposite directions. The vector projection itself isn't "negative" per se, but it will point in the opposite direction of B when the scalar projection is negative. This happens because the dot product becomes negative for obtuse angles.

What are real-world applications of vector projection?

Vector projection is used extensively in physics to calculate work (force projected onto displacement), in computer graphics for lighting and shadows, in game development for collision detection and response, in machine learning for PCA and dimensionality reduction, in signal processing for filtering, and in navigation for calculating distances along specific directions.

What happens when you project onto a unit vector?

When projecting onto a unit vector (magnitude = 1), the formula simplifies significantly. Since |B|² = 1, the projection becomes just (A · B) × B. The scalar projection is simply A · B. This simplification is why unit vectors are so useful in many applications—they make projection calculations much cleaner.

How is projection related to orthogonal decomposition?

Vector projection is half of orthogonal decomposition. Any vector A can be split into two perpendicular parts relative to B: the projection of A onto B (parallel component), and the rejection of A from B (perpendicular component). Together, these two components add up to the original vector A. The rejection is calculated as A minus the projection.

What is vector rejection and how does it relate to projection?

Vector rejection (also called the perpendicular component) is the part of vector A that is perpendicular to vector B. It's calculated as A minus the projection of A onto B. While projection gives you the component along B, rejection gives you the component at right angles to B. Together, projection and rejection completely decompose A into orthogonal parts.