Linear Algebra

Vector Projection

The projection of vector a onto vector b is the component of a in the direction of b. The calculator returns the scalar projection comp_b(a), the vector projection proj_b(a) = ((a·b)/|b|²) b, and the perpendicular component a − proj_b(a).

Vector Projection

Projection of a onto b, scalar projection and the perpendicular component.

Try:
Answerproj_b(a) = (3, 0)
  1. Vectorsa = (3, 4), b = (1, 0)
  2. Dot producta · b = 3
  3. Magnitude squared|b|² = 1
  4. Scalar projectioncomp_b(a) = (a · b)/|b| = 3
  5. Coefficient(a · b)/|b|² = 3
  6. Projection onto bproj_b(a) = (3, 0)
  7. Perpendicular componenta − proj_b(a) = (0, 4)

A decomposition, not just a length

Projecting one vector onto another splits it in two: the part that lies along the second vector, and the part left over at right angles to it. That decomposition is unique, and between them the two parts reconstruct the original exactly.

This calculator produces all three quantities — the scalar projection, the vector projection, and the perpendicular remainder.

Reporting the perpendicular component alongside the projection is what makes this a decomposition rather than a measurement. The two pieces are guaranteed to be perpendicular to each other and to sum back to the original vector, which is a complete description rather than a single extracted number.

That split is the engine behind a great deal of applied mathematics. Resolving a force along a surface and normal to it, separating a signal into a component along a reference and the residual, and orthogonalising a set of vectors are all this operation applied repeatedly.

How to use this calculator

  1. Enter the vector being projected The one to be split. Its components are comma-separated, and both vectors must have the same length.
  2. Enter the vector to project onto This supplies the direction. It must not be the zero vector, which has no direction to project onto and is rejected.
  3. Read the scalar projection A single signed number giving how far the first vector reaches along the second. Negative means it reaches backwards.
  4. Read the two components The projection itself and the perpendicular remainder. Adding them returns the original vector exactly.

The formula, and where it comes from

comp_b(a) = (a·b)/|b| proj_b(a) = ((a·b)/|b|²)·b a − proj_b(a) ⊥ b

The scalar projection divides the dot product by the length of the target vector, which converts it from a quantity depending on both magnitudes into one depending only on the first vector's reach along the second. It is signed, so it records direction as well as distance.

The vector projection divides by the squared length instead, and the difference between the two divisors is the point. Dividing once gives a length; dividing twice and multiplying by the vector itself scales the target down to exactly the right size, since the vector contributes one factor of its own length back.

That coefficient is what the implementation reports as its own step. It is the multiple of the target vector that the projection equals, so reading it says immediately whether the projection is longer or shorter than the vector it lies along.

The perpendicular component is what remains after subtracting the projection. Its perpendicularity to the target is not imposed but automatic: the projection was constructed to absorb exactly the aligned part, so nothing aligned is left behind.

What each input means

a Vector being projected — form field “Vector a (comma-separated)”
The vector to decompose. Its length and direction determine both output components.
b Direction vector — form field “Vector b (comma-separated)”
Supplies the direction only — its length cancels out of the projection. Must be non-zero.
comp_b(a) Scalar projection
A signed length. Positive when the first vector reaches forwards along the second, negative when backwards.
proj_b(a) Vector projection
The component along the direction vector, always parallel to it or opposite.

Worked examples

Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.

Projecting onto an axis

A vector reaching 3 across and 4 up, projected onto a unit vector along the horizontal axis.

Inputs Vector a (comma-separated) = 3, 4, Vector b (comma-separated) = 1, 0

  1. Vectors a = (3, 4), b = (1, 0)
  2. Dot product a · b = 3
  3. Magnitude squared |b|² = 1
  4. Scalar projection comp_b(a) = (a · b)/|b| = 3
  5. Coefficient (a · b)/|b|² = 3
  6. Projection onto b proj_b(a) = (3, 0)
  7. Perpendicular component a − proj_b(a) = (0, 4)

Result proj_b(a) = (3, 0)

The projection picks out the horizontal component alone, and the perpendicular remainder is the vertical one. Projecting onto a coordinate axis is exactly how a vector's components are defined in the first place.

The scalar projection equals 3 here because the direction vector has unit length. With a longer target vector the scalar and the coefficient would differ, which is where the two divisors stop agreeing.

Projecting onto a diagonal in three dimensions

A general 3D vector projected onto the vector with all components equal — the main diagonal.

Inputs Vector a (comma-separated) = 1, 2, 3, Vector b (comma-separated) = 1, 1, 1

  1. Vectors a = (1, 2, 3), b = (1, 1, 1)
  2. Dot product a · b = 6
  3. Magnitude squared |b|² = 3
  4. Scalar projection comp_b(a) = (a · b)/|b| = 3.4641
  5. Coefficient (a · b)/|b|² = 2
  6. Projection onto b proj_b(a) = (2, 2, 2)
  7. Perpendicular component a − proj_b(a) = (-1, 0, 1)

Result proj_b(a) = (2, 2, 2)

The projection has all three components equal, since it must be a multiple of the target. Its coefficient is the average of the original components, which is what projecting onto the all-ones direction always computes.

The perpendicular remainder has components summing to zero. That is the condition for being perpendicular to the all-ones vector, and it is a quick check on the decomposition.

An orthogonal pair

Two perpendicular unit vectors, so the first has no component along the second at all.

Inputs Vector a (comma-separated) = 1, 0, Vector b (comma-separated) = 0, 1

  1. Vectors a = (1, 0), b = (0, 1)
  2. Dot product a · b = 0
  3. Magnitude squared |b|² = 1
  4. Scalar projection comp_b(a) = (a · b)/|b| = 0
  5. Coefficient (a · b)/|b|² = 0
  6. Projection onto b proj_b(a) = (0, 0)
  7. Perpendicular component a − proj_b(a) = (1, 0)

Result proj_b(a) = (0, 0)

The dot product is zero, so the projection is the zero vector and the scalar projection is zero. The perpendicular component is the entire original vector, which is what perpendicularity means.

This is the degenerate end of the decomposition: one piece takes everything and the other takes nothing. Nothing about the calculation changes, only the values.

Reading the result

The two pieces reconstruct the original

Adding the projection and the perpendicular component returns the vector that was decomposed. That identity is the definition of the split and the most direct check available on any answer.

The direction vector's length does not matter

Scaling the target vector leaves the projection unchanged, because the extra length cancels between the numerator and the squared denominator. Only its direction affects the result.

A negative scalar projection is ordinary

It means the vector reaches backwards along the target direction, and the projection points opposite to it. The magnitude is still a genuine length; the sign carries the direction.

When you would use this

Resolving a force along a surface

Splitting a force into a component along an incline and one perpendicular to it is this decomposition, and it is the first step in almost every problem involving a slope.

Orthogonalising a set of vectors

Subtracting the projection of one vector onto another leaves something perpendicular to it. Repeating that systematically is the Gram-Schmidt process, and this is its inner step.

Assumptions and limitations

What this calculator assumes

  • Both vectors have the same number of components.
  • The direction vector is non-zero; projecting onto nothing is undefined and is refused.
  • The perpendicular component is obtained by subtraction rather than computed independently.
  • Only the direction of the target vector affects the result, not its length.

Where it stops being the right tool

  • One projection at a time, so orthogonalising a set requires repeated runs.
  • Projection onto a single vector only, not onto a plane or a higher-dimensional subspace.
  • No angle between the vectors is reported alongside the components.
  • Components are decimals, so an exact fraction appears rounded.

Common mistakes

Dividing by the length instead of its square

Why it happens. Both divisors appear in the two formulas and differ by one factor, which is easy to lose when the target vector has unit length and the two coincide.

How to avoid it. The scalar projection divides once; the vector projection divides twice and multiplies by the vector. Check against a non-unit target, where the two genuinely differ.

Projecting the wrong way round

Why it happens. The operation is not symmetric — projecting one vector onto another gives a different result from the reverse — but the two fields look interchangeable.

How to avoid it. The first field is the vector being split; the second supplies the direction. The projection is always parallel to the second.

Assuming the projection is shorter than the original

Why it happens. Taking a component sounds like it must reduce the length, and for the projection itself that is true.

How to avoid it. The projection is never longer than the vector projected, but it can be much longer than the target vector, since the target's length is irrelevant to the result.

Frequently asked questions

What is the difference between scalar projection and vector projection?

The scalar projection is a single signed number giving how far the first vector reaches along the second. The vector projection is the actual vector in that direction with that length — the same information, expressed as a vector rather than a magnitude.

What if the direction vector is zero?

The projection is undefined, because a zero vector points nowhere and there is no direction to project onto. The calculator reports that rather than attempting a division by zero.

What is the perpendicular component used for?

It completes the decomposition: the projection plus the perpendicular part reconstructs the original vector, split into what lies along the target direction and what does not. Subtracting a projection to leave something perpendicular is the core step of Gram-Schmidt orthogonalisation.

Does the length of the direction vector matter?

No. Scaling it leaves the projection unchanged, because the extra factor cancels between the dot product and the squared magnitude. Only its direction affects the answer.