Vector Projection & Component Calculator

Enter two vectors and this calculator splits the first into the part that lies along the second and the part that is perpendicular to it. You get the vector projection proj₋a component by component, the signed scalar projection comp₋a, the length of the orthogonal remainder, and a Pythagoras check confirming the two parts account for the whole of a. Leave the z components at zero for a two-dimensional problem.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
aₓFirst component of the vector being resolved.5
aᵧSecond component of the vector being resolved.6
a_zThird component; leave at 0 for a 2D problem.2
bₓFirst component of the direction you are projecting onto.3
bᵧSecond component of the direction. Only b's direction matters, not its length.4
b_zThird component; leave at 0 for a 2D problem.0

It returns

  • Scalar projection comp_b a — Signed length of a's shadow on b. Negative when the angle exceeds 90°.
  • proj_b a — x component
  • proj_b a — y component
  • proj_b a — z component
  • Length of the orthogonal part — How much of a is left once everything along b has been removed.
  • Angle between a and b
  • |a|

The formula

projba=ab|b|2b
compba=ab|b|=|a|cosθ

In plain text: proj_b a = ((a·b)/|b|²) b and comp_b a = (a·b)/|b|

  • aThe vector being resolved
  • bThe direction being projected onto; only its direction matters
  • a·bDot product aₓbₓ + a_yb_y + a_zb_z
  • |b|²bₓ² + b_y² + b_z², the squared length of b
  • comp_b aScalar projection — the signed length |a| cos θ

The orthogonal component is a − proj_b a. It is perpendicular to b, and the two parts satisfy |a|² = (comp_b a)² + |a⊥|².

Updated Category Vectors & Vector Operations Verified against published test cases Reading time 10 min

Splitting one vector along another

Projection answers a single question: how much of vector a points along the direction of vector b? The answer comes in two forms, and confusing them is the most common error in this topic.

The scalar projection - also called the component of a along b, written comp₋a - is a single signed number: the length of the shadow a casts on the line through b, positive when the shadow falls in the same direction as b and negative when it falls the other way.

The vector projection proj₋a is that same shadow written as a vector: it has the scalar projection's length and lies along b. It is what you subtract from a to get the part of a that has nothing to do with b.

Those two pieces together give the decomposition that makes projection useful:

a = proj₋a + (a − proj₋a)

The first term is entirely parallel to b, the second entirely perpendicular to it, and the split is unique. Every application of projection - resolving a force along and across an incline, separating a velocity into radial and tangential parts, removing a known direction from a data vector - is that one identity used in a particular context.

The formula, and why b appears twice

The two projections are

comp₋a = (a · b) / |b|  and  proj₋a = ((a · b) / |b|²) b

The vector version divides by |b|² rather than |b| because it then multiplies by b itself, which contributes another factor of |b| in length. Split it apart and the logic is obvious: (a·b)/|b| is the length you want, and b/|b| is the unit vector giving the direction. Multiply them and you get ((a·b)/|b|²)b. Writing |b| where |b|² belongs produces a vector whose length is wrong by a factor of |b|, and it is the single most frequent slip in this calculation.

Where does the dot product come from? Start from a·b = |a||b|cosθ. The shadow of a on the line of b has length |a|cosθ by simple trigonometry. Divide the identity by |b| and that is exactly what remains. So the scalar projection is |a|cosθ written in a form you can evaluate from coordinates without ever finding the angle.

Note what the formula does not depend on: the length of b. Scale b by any positive number and a·b scales the same way as |b|, so the ratio is unchanged. Only b's direction matters, which is why b is often called the direction vector. Reverse b, though, and the scalar projection changes sign, because the shadow now falls opposite to the reference direction.

The orthogonal component a⊥ = a − proj₋a is perpendicular to b by construction: take its dot product with b and you get a·b − (a·b/|b|²)(b·b) = a·b − a·b = 0. Because the two parts are perpendicular, their lengths obey Pythagoras: |a|² = (comp₋a)² + |a⊥|². The calculator prints that check on every run.

Worked example: a = (5, 6, 2) onto b = (3, 4, 0)

  1. Dot product. a · b = (5)(3) + (6)(4) + (2)(0) = 15 + 24 + 0 = 39.
  2. Squared length of b. |b|² = 9 + 16 + 0 = 25, so |b| = 5.
  3. Scalar projection. comp₋a = 39 / 5 = 7.8. Positive, so the shadow falls along b rather than against it.
  4. Scale factor. 39 / 25 = 1.56, so proj₋a = 1.56(3, 4, 0) = (4.68, 6.24, 0). Its length is 1.56 × 5 = 7.8, matching the scalar projection as it must.
  5. Orthogonal part. a − proj₋a = (5 − 4.68, 6 − 6.24, 2 − 0) = (0.32, −0.24, 2). Check perpendicularity: (0.32)(3) + (−0.24)(4) + (2)(0) = 0.96 − 0.96 = 0.
  6. Length of the orthogonal part. √(0.1024 + 0.0576 + 4) = √4.16 = 2.0396078.

Now the Pythagoras check. |a|² = 25 + 36 + 4 = 65. The two parts give 7.8² + 2.0396078² = 60.84 + 4.16 = 65. The decomposition accounts for the whole of a and nothing more.

This is exactly the arithmetic behind resolving a force on a ramp. If a is a force and b is the direction of the slope, then 7.8 is the component driving motion along the slope and 2.0396078 is the component pressing into the surface. Change the sign of b - point it down the ramp instead of up - and the scalar projection becomes −7.8 while the perpendicular magnitude stays the same, because the surface does not care which way you chose to call positive.

Reading the numbers

The sign of the scalar projection is the first thing to read. Positive means a and b make an acute angle and the projection points along b; negative means the angle exceeds 90° and the projection points along −b; zero means the two are perpendicular and a has no component along b at all. That single sign is often the whole answer in physics - it decides whether a force helps or resists a motion.

Compare the scalar projection with |a|. Their ratio is cos θ, so a projection of 7.8 out of a total length of 8.0622577 means the vectors are well aligned: 7.8 / 8.0622577 = 0.9674585, an angle of about 14.6°. A projection much smaller than |a| means most of a is doing something else.

The orthogonal magnitude is the residual - what is left of a once everything explicable by b has been removed. In least-squares fitting that residual is the error, and the whole method consists of choosing coefficients to make it as short as possible. In signal work it is the part of a signal not accounted for by a known component. Zero orthogonal magnitude means a is a multiple of b and carries no new direction.

One caution about units. The scalar projection carries the units of a, not of b - it is a length if a is a displacement, a force if a is a force. The vector projection likewise. Only the scale factor (a·b)/|b|² is a pure number, and even that is only dimensionless when a and b carry the same units.

The special cases at a glance

What the projection does as the angle between a and b changes, with |a| held fixed.
Angle θcos θScalar projectionVector projectionOrthogonal magnitude
1|a|a itself0
30°0.86600.8660|a|0.8660|a| along b0.5|a|
45°0.70710.7071|a|0.7071|a| along b0.7071|a|
60°0.50.5|a|0.5|a| along b0.8660|a|
90°00Zero vector|a|
120°−0.5−0.5|a|0.5|a| along −b0.8660|a|
180°−1−|a|−a0

Each row satisfies (scalar projection)² + (orthogonal magnitude)² = |a|², since cos²θ + sin²θ = 1. The orthogonal magnitude is |a| sin θ.

Mistakes to avoid

  • Dividing by |b| instead of |b|² in the vector formula. The result then has the wrong length by a factor of |b|. It is correct only when b happens to be a unit vector, which is why the error survives so many worked examples.
  • Projecting the wrong way round. proj₋a and proj₂b are different vectors with different lengths and different directions. The subscript names the direction you are projecting onto.
  • Reporting a negative length. The scalar projection is signed and may be negative; the length of the vector projection is its absolute value. Both are useful, but they are not the same number.
  • Assuming the orthogonal component is perpendicular to a. It is perpendicular to b. Only when a and b are themselves perpendicular does the orthogonal component equal a.
  • Projecting onto a zero vector. There is no direction to project onto and the formula divides by zero. The calculator reports nothing rather than a misleading zero.
  • Forgetting that projection loses information. The scalar projection alone cannot reconstruct a - infinitely many vectors share the same shadow. You need the orthogonal part as well, which is exactly why this calculator reports both.

Where projection leads

Work is the canonical application. A constant force F acting through a displacement d does work W = F · d = (compₔF)|d|: only the component of the force along the motion counts, and the perpendicular component does no work at all. That is why a centripetal force changes direction without changing speed, and why carrying a box across a level floor does no work against gravity.

In linear algebra, projection onto a single vector generalises to projection onto a subspace, and that generalisation is the entire content of least squares. Fitting a line to data means projecting the observation vector onto the column space of the design matrix; the residual you are minimising is precisely the orthogonal component computed here, one dimension at a time. Repeating the projection-and-subtract step across a set of vectors is the Gram-Schmidt process, which turns any basis into an orthogonal one and underlies QR factorisation.

The dot product does the work in all of these, so the dot product calculator is the natural companion page, and the angle between vectors is the same ratio read as an angle instead of a length. Where projection extracts the parallel part, the cross product measures the perpendicular part, with magnitude |a||b| sinθ - exactly |b| times the orthogonal magnitude reported here. For the matrix machinery that turns these ideas into a general solver, see the row reduction and eigenvector pages, since an eigenvector is precisely a direction whose projection under a transformation is itself.

Frequently asked questions

What is the difference between the scalar and vector projection?

The scalar projection is one signed number - the length of a's shadow on b's line, negative when the shadow falls opposite to b. The vector projection is that shadow as a vector, pointing along b (or along −b when the scalar is negative). They are related by proj₋a = (comp₋a)(b/|b|): multiply the scalar by the unit vector in b's direction.

Why does the vector formula divide by |b| squared?

Because it then multiplies by b, which supplies a factor of |b| in length. You want length (a·b)/|b| in direction b/|b|; multiply those and the denominators combine to |b|². If you divide by |b| only and multiply by b, the result is too long by exactly a factor of |b| - correct only when b is already a unit vector.

Can the projection be longer than a?

No. The scalar projection is |a| cos θ, and cosine never exceeds 1 in magnitude, so the projection's length is at most |a|, with equality only when a and b are parallel or antiparallel. If your answer is longer than a, you have divided by |b| where |b|² was required.

What does a negative scalar projection mean physically?

That a points more than 90° away from b, so its component along b opposes the reference direction. For a force resolved along a direction of motion, a negative value means the force is retarding the motion and doing negative work - friction, drag, or a brake. The magnitude is still the size of that opposing component.

Is the orthogonal component perpendicular to a or to b?

To b, always. That follows from the construction: dot a − proj₋a with b and the two terms cancel exactly. It is perpendicular to a only in the special case where a and b are themselves perpendicular, in which case the projection is zero and the orthogonal component is the whole of a.

Does the length of b affect the answer?

Not for a positive rescaling. Both the scalar and the vector projection depend only on b's direction, because the |b| introduced by the dot product cancels against the |b| in the denominator. Reversing b does matter: it flips the sign of the scalar projection and reverses the vector projection, since the reference direction has changed.

How does this connect to least squares?

Least squares is projection onto a subspace instead of onto a single vector. You project the observation vector onto the space spanned by your model's columns; the fitted values are the projection and the residuals are the orthogonal component. Minimising the sum of squared residuals is exactly minimising the length of that orthogonal part, and the normal equations are the statement that the residual is perpendicular to every column.

Can I project in two dimensions?

Yes - leave both z components at zero. The formulas never assume a dimension count; the same expressions work in two, three or three hundred dimensions. The chart on this page always draws the plane containing a and b, which is where the whole calculation lives regardless of the ambient dimension.

References

  • Calculus: Early Transcendentals, 9th ed. (Section 12.3, Projections) — James Stewart, Daniel Clegg and Saleem Watson, Cengage Learning
  • Linear Algebra and Its Applications, 6th ed. (Chapter 6, Orthogonality and Least Squares) — David C. Lay, Steven R. Lay and Judi J. McDonald, Pearson
  • Introduction to Linear Algebra, 6th ed. (Chapter 4, Orthogonality) — Gilbert Strang, Wellesley-Cambridge Press