Skip to main content
Home / Vectors / Vector Projection
Calculating...

Vector Projection Calculator

Calculate the projection of one vector onto another with detailed steps

Press / to search operations

No vectors added yet

Click "Add Vector" to begin entering data

Projection requires exactly 2 vectors (a projected onto b).

Learn About Vector Projection

Understanding the concepts behind calculations.


What is Vector Projection?

Vector projection is the process of finding the "shadow" of one vector onto another. It answers the question: "How much of vector a lies in the direction of vector b?"

Core Idea: Imagine shining a light perpendicular to vector b. The shadow that vector a casts onto b is the projection of a onto b.

Simple Analogy:

  • ๐ŸŒž Sunlight shining straight down casts a shadow of a flagpole on the ground โ†’ That's projection!
  • ๐Ÿ“ A vector (force) applied at an angle has a component that pulls in the direction of motion โ†’ That's the projection!

There are two related concepts:

  • Scalar Projection (Component): A number representing how long the projection is.
  • Vector Projection: An actual vector pointing in the direction of b.

The Formulas

Vector Projection of a onto b

$$ \boxed{\text{proj}_{\mathbf{b}} \mathbf{a} = \frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{b}\|^2} \mathbf{b}} $$

Where:

  • a ยท b is the dot product of vectors a and b.
  • โ€–bโ€– is the magnitude (length) of vector b.
  • โ€–bโ€–ยฒ is the squared magnitude ($b_1^2 + b_2^2 + \dots + b_n^2$).

Scalar Projection (Component) of a onto b

$$ \boxed{\text{comp}_{\mathbf{b}} \mathbf{a} = \frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{b}\|} = \|\mathbf{a}\| \cos \theta} $$

Where ฮธ is the angle between vectors a and b.

๐Ÿ“ Key Insight: The scalar projection tells you how far the projection extends, while the vector projection tells you both how far and in which direction.


Scalar vs Vector Projection

๐Ÿ“ Scalar Projection (Component)

$$ \text{comp}_{\mathbf{b}} \mathbf{a} = \frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{b}\|} $$
  • Returns a number (scalar).
  • Positive if vectors point in same general direction.
  • Negative if vectors point in opposite directions.
  • Zero if vectors are perpendicular.
  • Units: same as vector a.

๐Ÿ’ก Think: "How much of a is in b's direction?"

โžก๏ธ Vector Projection

$$ \text{proj}_{\mathbf{b}} \mathbf{a} = \left(\frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{b}\|^2}\right) \mathbf{b} $$
  • Returns a vector.
  • Always points in direction of b (or opposite if scalar projection negative).
  • Magnitude = |scalar projection|.
  • Zero vector if vectors are perpendicular.

๐Ÿ’ก Think: "The actual shadow vector along b's direction."

Relationship:

$$ \text{proj}_{\mathbf{b}} \mathbf{a} = (\text{comp}_{\mathbf{b}} \mathbf{a}) \cdot \frac{\mathbf{b}}{\|\mathbf{b}\|} $$

The vector projection equals the scalar projection times the unit vector in the direction of b.


Geometric Interpretation

๐Ÿ“ Right Triangle Formation

When you project vector a onto vector b, you create a right triangle:

  • Hypotenuse: Vector a
  • Adjacent side: Projection of a onto b
  • Opposite side: Perpendicular component ($\mathbf{a} - \text{proj}_{\mathbf{b}} \mathbf{a}$)
$$ \mathbf{a} = \text{proj}_{\mathbf{b}} \mathbf{a} + \mathbf{a}_{\perp} $$

๐ŸŽฏ Decomposition

Vector projection is the first step in orthogonal decomposition:

Any vector a can be decomposed into two perpendicular components:

  • Parallel component: $\text{proj}_{\mathbf{b}} \mathbf{a}$ (along b)
  • Perpendicular component: $\mathbf{a} - \text{proj}_{\mathbf{b}} \mathbf{a}$ (โŠฅ to b)

Visual Example:

Take a = (4, 3) and b = (2, 0) (horizontal axis)

  • Projection of a onto b = (4, 0) โ€” the horizontal component
  • Perpendicular component = (0, 3) โ€” the vertical component
  • Check: $(4, 3) = (4, 0) + (0, 3)$ โœ“

Now the vector is decomposed into horizontal and vertical parts!

๐Ÿ“ Key Insight: The projection is the closest vector to a that lies along the direction of b. This is why projection is used in least squares and regression!


Properties of Projection

โœ… Linear in First Argument

$$ \text{proj}_{\mathbf{b}} (\mathbf{a}_1 + \mathbf{a}_2) = \text{proj}_{\mathbf{b}} \mathbf{a}_1 + \text{proj}_{\mathbf{b}} \mathbf{a}_2 $$
$$ \text{proj}_{\mathbf{b}} (c\mathbf{a}) = c \cdot \text{proj}_{\mathbf{b}} \mathbf{a} $$

๐Ÿ”„ Not Linear in Second Argument

$$ \text{proj}_{\mathbf{b}_1 + \mathbf{b}_2} \mathbf{a} \neq \text{proj}_{\mathbf{b}_1} \mathbf{a} + \text{proj}_{\mathbf{b}_2} \mathbf{a} $$

Other Important Properties

  • Idempotent: $\text{proj}_{\mathbf{b}} (\text{proj}_{\mathbf{b}} \mathbf{a}) = \text{proj}_{\mathbf{b}} \mathbf{a}$ (projecting twice does nothing).
  • Orthogonality: $(\mathbf{a} - \text{proj}_{\mathbf{b}} \mathbf{a}) \perp \mathbf{b}$ (the difference is perpendicular to b).
  • Pythagorean: $\|\mathbf{a}\|^2 = \|\text{proj}_{\mathbf{b}} \mathbf{a}\|^2 + \|\mathbf{a} - \text{proj}_{\mathbf{b}} \mathbf{a}\|^2$.
  • Zero projection: If $\mathbf{a} \perp \mathbf{b}$, then $\text{proj}_{\mathbf{b}} \mathbf{a} = \mathbf{0}$.
  • Full projection: If $\mathbf{a}$ is parallel to $\mathbf{b}$, then $\text{proj}_{\mathbf{b}} \mathbf{a} = \mathbf{a}$.

Idempotent Property: Once you've projected, projecting again gives the same result. This makes projection an example of a linear operator that is also a projection operator.


Step-by-Step Examples

Example 1: Projecting onto a Horizontal Vector

Problem: Find the projection of $\mathbf{a} = (4, 3)$ onto $\mathbf{b} = (2, 0)$.

Step 1: Write vectors as column vectors

$$ \mathbf{a} = \begin{pmatrix} 4 \\\\ 3 \end{pmatrix}, \quad \mathbf{b} = \begin{pmatrix} 2 \\\\ 0 \end{pmatrix} $$

Step 2: Compute the dot product $\mathbf{a} \cdot \mathbf{b}$

$$ \mathbf{a} \cdot \mathbf{b} = (4)(2) + (3)(0) = 8 + 0 = 8 $$

Step 3: Compute $\|\mathbf{b}\|^2$ (squared magnitude)

$$ \|\mathbf{b}\|^2 = 2^2 + 0^2 = 4 + 0 = 4 $$

Step 4: Apply the projection formula

$$ \text{proj}_{\mathbf{b}} \mathbf{a} = \frac{8}{4} \begin{pmatrix} 2 \\\\ 0 \end{pmatrix} = 2 \begin{pmatrix} 2 \\\\ 0 \end{pmatrix} = \begin{pmatrix} 4 \\\\ 0 \end{pmatrix} $$

Solution: $\text{proj}_{\mathbf{b}} \mathbf{a} = (4, 0)$

This makes sense! The horizontal component of (4,3) is (4,0).

Example 2: Projecting onto a Diagonal Vector

Problem: Find the projection of $\mathbf{a} = (3, 4)$ onto $\mathbf{b} = (1, 1)$.

Step 1: Write vectors as column vectors

$$ \mathbf{a} = \begin{pmatrix} 3 \\\\ 4 \end{pmatrix}, \quad \mathbf{b} = \begin{pmatrix} 1 \\\\ 1 \end{pmatrix} $$

Step 2: Compute the dot product $\mathbf{a} \cdot \mathbf{b}$

$$ \mathbf{a} \cdot \mathbf{b} = (3)(1) + (4)(1) = 3 + 4 = 7 $$

Step 3: Compute $\|\mathbf{b}\|^2$

$$ \|\mathbf{b}\|^2 = 1^2 + 1^2 = 1 + 1 = 2 $$

Step 4: Apply the projection formula

$$ \text{proj}_{\mathbf{b}} \mathbf{a} = \frac{7}{2} \begin{pmatrix} 1 \\\\ 1 \end{pmatrix} = \begin{pmatrix} 3.5 \\\\ 3.5 \end{pmatrix} $$

Solution: $\text{proj}_{\mathbf{b}} \mathbf{a} = (3.5, 3.5)$

Check: The projection lies along the line $y = x$, as expected!

Example 3: Scalar Projection Only

Problem: Find the scalar projection (component) of $\mathbf{a} = (6, 8)$ onto $\mathbf{b} = (3, 4)$.

Step 1: Compute dot product

$$ \mathbf{a} \cdot \mathbf{b} = (6)(3) + (8)(4) = 18 + 32 = 50 $$

Step 2: Compute $\|\mathbf{b}\|$ (magnitude)

$$ \|\mathbf{b}\| = \sqrt{3^2 + 4^2} = \sqrt{9 + 16} = \sqrt{25} = 5 $$

Step 3: Apply scalar projection formula

$$ \text{comp}_{\mathbf{b}} \mathbf{a} = \frac{50}{5} = 10 $$

Solution: $\text{comp}_{\mathbf{b}} \mathbf{a} = 10$

Notice that $\|\mathbf{a}\| = 10$, and since $\mathbf{a}$ is parallel to $\mathbf{b}$ ($\mathbf{a} = 2\mathbf{b}$), the scalar projection equals the magnitude of $\mathbf{a}$! โœ“

Example 4: Projection with Negative Dot Product

Problem: Find the projection of $\mathbf{a} = (-2, 1)$ onto $\mathbf{b} = (1, 2)$.

Step 1: Write vectors as column vectors

$$ \mathbf{a} = \begin{pmatrix} -2 \\\\ 1 \end{pmatrix}, \quad \mathbf{b} = \begin{pmatrix} 1 \\\\ 2 \end{pmatrix} $$

Step 2: Compute dot product

$$ \mathbf{a} \cdot \mathbf{b} = (-2)(1) + (1)(2) = -2 + 2 = 0 $$

Step 3: The dot product is zero, so the vectors are perpendicular!

$$ \text{proj}_{\mathbf{b}} \mathbf{a} = \frac{0}{\|\mathbf{b}\|^2} \mathbf{b} = 0 \cdot \mathbf{b} = \begin{pmatrix} 0 \\\\ 0 \end{pmatrix} $$

Observation: When vectors are perpendicular, the projection is the zero vector โ€” no part of $\mathbf{a}$ lies in the direction of $\mathbf{b}$.

Example 5: Projection in 3D

Problem: Find the projection of $\mathbf{a} = (2, -1, 3)$ onto $\mathbf{b} = (1, 0, 1)$.

Step 1: Write vectors as column vectors

$$ \mathbf{a} = \begin{pmatrix} 2 \\\\ -1 \\\\ 3 \end{pmatrix}, \quad \mathbf{b} = \begin{pmatrix} 1 \\\\ 0 \\\\ 1 \end{pmatrix} $$

Step 2: Compute dot product

$$ \mathbf{a} \cdot \mathbf{b} = (2)(1) + (-1)(0) + (3)(1) = 2 + 0 + 3 = 5 $$

Step 3: Compute $\|\mathbf{b}\|^2$

$$ \|\mathbf{b}\|^2 = 1^2 + 0^2 + 1^2 = 1 + 0 + 1 = 2 $$

Step 4: Apply the projection formula

$$ \text{proj}_{\mathbf{b}} \mathbf{a} = \frac{5}{2} \begin{pmatrix} 1 \\\\ 0 \\\\ 1 \end{pmatrix} = \begin{pmatrix} 2.5 \\\\ 0 \\\\ 2.5 \end{pmatrix} $$

Solution: $\text{proj}_{\mathbf{b}} \mathbf{a} = (2.5, 0, 2.5)$


Real-World Applications

๐Ÿ”ง Physics: Work Done

Work = Force ยท Displacement = $\|\mathbf{F}\| \cdot \text{comp}_{\mathbf{d}} \mathbf{F}$

Only the component of force in the direction of motion does work!

$$ W = \mathbf{F} \cdot \mathbf{d} = \|\mathbf{F}\| \cdot \text{comp}_{\mathbf{d}} \mathbf{F} $$

๐Ÿ“Š Statistics: Regression

Linear regression predicts Y from X using projection. The predicted values are the projection of Y onto the column space of X.

$$ \hat{\mathbf{Y}} = \text{proj}_{\text{col}(X)} \mathbf{Y} $$

๐ŸŽฎ Game Development: Movement

When a character moves on a sloped surface, you project movement vectors onto the surface plane.

๐Ÿ“ Computer Graphics: Shadows

Rendering shadows involves projecting 3D objects onto 2D surfaces (the shadow plane).

๐Ÿค– Machine Learning: PCA

Principal Component Analysis projects data onto principal component directions to reduce dimensionality.

โš™๏ธ Engineering: Force Decomposition

Decompose forces into normal and parallel components to analyze friction, tension, etc.

๐Ÿ”ง Physics Example: A force of 100 N is applied at a 30ยฐ angle to a box. The horizontal component (projection) is $100 \cdot \cos(30^\circ) \approx 86.6$ N. Only this component actually moves the box horizontally!


Common Mistakes to Avoid

  1. โŒ Forgetting to square the magnitude: The denominator is $\|\mathbf{b}\|^2$, not $\|\mathbf{b}\|$!
  2. โŒ Using the wrong vector in denominator: The projection is onto b, so $\mathbf{b}$ is in the denominator.
  3. โŒ Confusing scalar and vector projection: Remember โ€” scalar returns a number, vector returns a vector.
  4. โŒ Projecting onto zero vector: You cannot project onto the zero vector (division by zero).
  5. โŒ Forgetting that projection lies along b: The result is always parallel to $\mathbf{b}$ (or zero).
  6. โŒ Mixing up a and b: $\text{proj}_{\mathbf{b}} \mathbf{a} \neq \text{proj}_{\mathbf{a}} \mathbf{b}$ in general!

โš ๏ธ Common Error Example:

Wrong: $\text{proj}_{\mathbf{b}} \mathbf{a} = \frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{b}\|} \mathbf{b}$ (using $\|\mathbf{b}\|$ instead of $\|\mathbf{b}\|^2$) โ†’ This gives a vector with wrong magnitude!

$$ \text{Wrong: } \frac{7}{\sqrt{2}} \begin{pmatrix} 1 \\\\ 1 \end{pmatrix} \approx 4.95 \begin{pmatrix} 1 \\\\ 1 \end{pmatrix} = \begin{pmatrix} 4.95 \\\\ 4.95 \end{pmatrix} $$

Correct: $\text{proj}_{\mathbf{b}} \mathbf{a} = \frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{b}\|^2} \mathbf{b}$

$$ \text{Correct: } \frac{7}{2} \begin{pmatrix} 1 \\\\ 1 \end{pmatrix} = 3.5 \begin{pmatrix} 1 \\\\ 1 \end{pmatrix} = \begin{pmatrix} 3.5 \\\\ 3.5 \end{pmatrix} $$

The wrong version gives (4.95, 4.95) instead of (3.5, 3.5) โ€” off by about 41%!


Frequently Asked Questions

Q: What's the difference between scalar and vector projection?

A: Scalar projection (component) gives a number representing the length of the projection. Vector projection gives an actual vector that lies along the direction of $\mathbf{b}$ with that length.

Q: Why do we use $\|\mathbf{b}\|^2$ in the denominator?

A: Because we want the result to be a scalar times $\mathbf{b}$. The dot product gives us $\mathbf{a} \cdot \mathbf{b} = \|\mathbf{a}\| \|\mathbf{b}\| \cos \theta$. We want the scalar factor $= \frac{\|\mathbf{a}\| \cos \theta}{\|\mathbf{b}\|}$. Since $\frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{b}\|^2} = \frac{\|\mathbf{a}\| \|\mathbf{b}\| \cos \theta}{\|\mathbf{b}\|^2} = \frac{\|\mathbf{a}\| \cos \theta}{\|\mathbf{b}\|}$ โœ“

Q: Can I project onto a zero vector?

A: No! The zero vector has no direction, so projection onto it is undefined (you'd be dividing by zero).

Q: What does a negative scalar projection mean?

A: It means the vectors point in opposite directions (angle > 90ยฐ). The projection vector will point opposite to $\mathbf{b}$.

Q: What's the relationship between projection and least squares?

A: In linear regression, the best-fit line comes from projecting the data vector onto the column space of the design matrix โ€” exactly the same idea as vector projection!

Q: Is projection the same as the component?

A: Not exactly. The "component" usually refers to the scalar projection (the length). However, sometimes people say "component" meaning the vector projection. Check the context!

Q: How does projection relate to the angle between vectors?

A: The scalar projection $= \|\mathbf{a}\| \cos \theta$, where $\theta$ is the angle between $\mathbf{a}$ and $\mathbf{b}$. The vector projection $= (\|\mathbf{a}\| \cos \theta) \cdot (\text{unit vector in direction of } \mathbf{b})$.


Practice Problems

Beginner

  1. Find the scalar projection of $\mathbf{a} = (3, 4)$ onto $\mathbf{b} = (1, 0)$.

  2. Find the vector projection of $\mathbf{a} = (2, 5)$ onto $\mathbf{b} = (0, 1)$.

  3. Find the projection of $\mathbf{a} = (1, 2, 2)$ onto $\mathbf{b} = (0, 0, 1)$.

Intermediate

  1. Find both scalar and vector projection of $\mathbf{a} = (4, 3)$ onto $\mathbf{b} = (2, 2)$.

  2. A force vector $\mathbf{F} = (10, 20)$ N is applied. Find the component of $\mathbf{F}$ in the direction of $\mathbf{v} = (1, 2)$.

  3. Project $\mathbf{a} = (2, -1, 4)$ onto $\mathbf{b} = (1, 1, 1)$.

  4. Find the perpendicular component of $\mathbf{a} = (6, 8)$ relative to $\mathbf{b} = (3, 4)$ (i.e., $\mathbf{a} - \text{proj}_{\mathbf{b}} \mathbf{a}$).

Advanced

  1. Prove that $\text{proj}_{\mathbf{b}} \mathbf{a}$ is the closest vector to $\mathbf{a}$ that lies on the line spanned by $\mathbf{b}$.

  2. For what value of $k$ is the projection of $\mathbf{a} = (2, k)$ onto $\mathbf{b} = (1, -1)$ equal to the zero vector?

  3. Show that $\|\text{proj}_{\mathbf{b}} \mathbf{a}\| \leq \|\mathbf{a}\|$ with equality only when $\mathbf{a}$ is parallel to $\mathbf{b}$.

Click to reveal solutions

1. $\text{comp}_{\mathbf{b}} \mathbf{a} = 3$

2. $\text{proj}_{\mathbf{b}} \mathbf{a} = (0, 5)$

3. $\text{proj}_{\mathbf{b}} \mathbf{a} = (0, 0, 2)$

4. Scalar: $\frac{7\sqrt{2}}{2} \approx 4.95$, Vector: $(3.5, 3.5)$

5. $\text{comp}_{\mathbf{v}} \mathbf{F} = \frac{50}{\sqrt{5}} \approx 22.36$ N

6. $\text{proj}_{\mathbf{b}} \mathbf{a} = (\frac{5}{3}, \frac{5}{3}, \frac{5}{3}) \approx (1.67, 1.67, 1.67)$

7. $\mathbf{a} - \text{proj}_{\mathbf{b}} \mathbf{a} = (0, 0)$ ($\mathbf{a}$ is parallel to $\mathbf{b}$)

8. Minimization of $\|\mathbf{a} - t\mathbf{b}\|$ leads to $t = \frac{\mathbf{a} \cdot \mathbf{b}}{\|\mathbf{b}\|^2}$.

9. $k = 2$ makes $\mathbf{a} \cdot \mathbf{b} = 2 - k = 0$, so projection is zero.

10. $\|\text{proj}_{\mathbf{b}} \mathbf{a}\| = \frac{|\mathbf{a} \cdot \mathbf{b}|}{\|\mathbf{b}\|} \leq \frac{\|\mathbf{a}\| \|\mathbf{b}\|}{\|\mathbf{b}\|} = \|\mathbf{a}\|$ by Cauchy-Schwarz.


Related Operations