Vector Projection Formula

The projection of vector a onto vector b is found by scaling b according to how aligned a is with it. The scaling factor comes from the dot product, normalised by the magnitude squared of b.

projb(a) = (a · b / b · b) × b

In component form:

Projection factor = (a₁b₁ + a₂b₂ + ... + aₙbₙ) / (b₁² + b₂² + ... + bₙ²)

proj = factor × b

  • a — The vector being projected
  • b — The vector onto which a is projected
  • a · b — Dot product (scalar product) of vectors a and b
  • b · b — Dot product of b with itself; equals the squared magnitude of b

Understanding the Derivation

The projection formula emerges from decomposing vector a into two parts: one parallel to b (the projection) and one perpendicular to it (the rejection).

  • Start with the decomposition: a = proj + ort, where ort is orthogonal to b
  • Express proj as a scalar multiple: proj = C × b, where C is the unknown factor
  • Eliminate the rejection: Taking the dot product of both sides with b yields C × (b · b) = a · b, because (ort · b) = 0
  • Solve for C: C = (a · b) / (b · b)

This scalar C represents how far along the direction of b the projection reaches.

Worked Example: 2D Projection

Project vector a = [3, 4] onto b = [1, 1].

  • Dot product a · b: 3(1) + 4(1) = 7
  • Dot product b · b: 1² + 1² = 2
  • Projection factor: 7 / 2 = 3.5
  • Projection vector: 3.5 × [1, 1] = [3.5, 3.5]

The projection is 3.5 times the unit direction of b, or equivalently, [3, 4] has a component of length 7 / √2 ≈ 4.95 along the direction of [1, 1].

Common Pitfalls and Caveats

Be aware of these common mistakes when computing or interpreting vector projections.

  1. Division by zero when b is the zero vector — If <strong>b</strong> = [0, 0] or [0, 0, 0], the denominator (b · b) becomes zero and the projection is undefined. Always verify that <strong>b</strong> is non-zero before calculating.
  2. Confusing projection with length of projection — The scalar factor (a · b) / (b · b) is not the same as the length of the projection. The length is |(a · b)| / |b|. The factor is the coefficient that scales <strong>b</strong> itself.
  3. Order matters for the sign — Projecting <strong>a</strong> onto <strong>b</strong> differs from projecting <strong>b</strong> onto <strong>a</strong>. A negative projection factor means <strong>a</strong> points partly in the opposite direction to <strong>b</strong>. Reversing the roles changes both the factor and the result.
  4. Dimensional mismatch between vectors — Both vectors must have the same number of dimensions. A 2D vector cannot be projected onto a 3D vector or vice versa without explicit padding or dimension reduction.

Applications in Physics and Data Science

Physics—Force decomposition: A cart on an incline experiences gravity. Its weight can be decomposed into a component along the slope (causing it to roll) and a component perpendicular (pressing into the surface). Vector projection quantifies each component, helping engineers design appropriate counterforces or friction requirements.

Data science—Linear regression and dimensionality reduction: In regression, projecting data onto a fitted line or plane yields predicted values. Principal component analysis projects high-dimensional data onto axes of maximum variance, enabling visualisation and noise reduction with minimal information loss. The projection factor determines how much of each data point aligns with the dominant direction.

Frequently Asked Questions

What does it mean if the projection factor is negative?

A negative projection factor indicates that vector <strong>a</strong> points partially in the opposite direction to <strong>b</strong>. The resulting projection vector will be flipped: it still lies on the line through <strong>b</strong>, but points backward. For instance, if you project [−1, 0] onto [1, 0], you get a factor of −1, yielding the projection [−1, 0]. This is geometrically correct and physically meaningful in contexts like forces working against a preferred direction.

How do I find the length of the projection?

The length (or magnitude) of the projection is given by |a · b| / |b|, where |b| is the magnitude of <strong>b</strong>. This differs from the projection factor because the factor already accounts for the direction of <strong>b</strong>; multiplying it by the magnitude of <strong>b</strong> gives the length. For <strong>a</strong> = [3, 4] and <strong>b</strong> = [1, 1], the magnitude of <strong>b</strong> is √2, and the projection length is 7 / √2 ≈ 4.95.

Can I project a 3D vector onto a 2D vector?

No, both vectors must have the same number of dimensions for the dot product and projection formulas to apply. If you have a 3D vector and a 2D vector, you must either extend the 2D vector to 3D (e.g., append a zero component) or reduce the 3D vector to 2D. The choice depends on your problem context and may lose or artificially constrain information.

What is the relationship between projection and the dot product?

The dot product a · b equals |a| |b| cos(θ), where θ is the angle between the vectors. Dividing this by |b|² isolates the component of <strong>a</strong> in the direction of <strong>b</strong>. The dot product directly encodes alignment: a large positive dot product means vectors point in similar directions, a negative one means opposite directions, and zero means perpendicular vectors.

How is vector projection used in machine learning?

Machine learning algorithms often project data onto lower-dimensional spaces to reduce noise and computation. Principal component analysis (PCA) projects data onto eigenvectors of the covariance matrix, preserving variance while reducing dimensions. Linear regression projects the target variable onto the span of feature vectors to minimise error. Kernel methods in support vector machines implicitly project data into high-dimensional spaces to find nonlinear decision boundaries.

What happens when vectors are parallel?

If <strong>a</strong> and <strong>b</strong> are parallel (one is a scalar multiple of the other), the projection of <strong>a</strong> onto <strong>b</strong> is <strong>a</strong> itself (or a scaled version). The factor equals |a| / |b| if they point the same way, or −|a| / |b| if opposite. This is the maximum possible projection magnitude for two vectors of fixed length, occurring when alignment is perfect.

More math calculators (see all)