Audited 29 Jul 2026·Last updated 28 Oct 2026·4 citations·Tier 2·0 uses

Vector Projection Calculator

Project vector a onto vector b in 2D or 3D: the projection vector, signed scalar projection, perpendicular rejection and the distance from a to b's line.

Vector Projection Calculator

Vector dimension
Vector a is the vector being projected. The order matters: projecting a onto b is not the same as projecting b onto a.
Used only in 3D mode.
Vector b is the direction being projected onto. It must not be the zero vector.
Used only in 3D mode.
Projection proj_b a
2i + 4j + 4k
proj_b a, the part of a lying along b, written in i, j, k notation with components to six decimal places.
Scalar projection comp_b a
6
Projection x component
2
Projection y component
4
Projection z component
4
Rejection x component
0
Rejection y component
-2
Rejection z component
2
Distance from a to the line through b
2.8284
Dot product a·b
18
Magnitude ‖b‖
3

Background.

Set a 10 kg box on a ramp that rises 3 units for every 4 across, and its weight of 98.1 newtons, pointing straight down, splits into two parts: 58.86 N pulling it down the slope and 78.48 N pressing it into the surface. Finding those parts is a vector projection. You take one vector, a, and ask how much of it lies along a chosen direction, b. Whatever is left over sits at right angles to b.

Enter a and b as components, in the plane or in space, and both parts come back. The projection proj_b a is the piece along b, written in i, j, k notation with each component also listed on its own. The scalar projection is its signed length. The rejection, a − proj_b a, is the perpendicular remainder, and its length is the shortest distance from the tip of a to the line through the origin along b. The dot product a·b and the length ‖b‖ are reported as well, since every other figure is built from those two. The same split drives a game character sliding along a wall instead of stopping dead, and the Gram–Schmidt process building an orthogonal basis one vector at a time.

Two properties of the answer are easy to misread. The scalar projection is signed, so it comes out negative whenever a and b are more than 90° apart; on the ramp, a b pointing uphill gives −58.86 N. And the operation is not symmetric: projecting a onto b and projecting b onto a give different vectors, so check which set of fields each one goes in.

What is vector projection calculator?

The vector projection of a onto b is the vector running from the origin to the point on b's line nearest the tip of a, which is where a perpendicular dropped from the tip of a meets that line. Its signed length, called the scalar projection or the component of a along b, equals ‖a‖ cos θ, where θ is the angle between the two vectors: positive below 90°, zero at exactly 90°, negative beyond. Only the direction of b enters the result. Doubling b, or swapping it for a unit vector pointing the same way, leaves everything unchanged; reversing b keeps the projection vector the same but flips the sign of the scalar projection, because that length is measured along b.

How to use this calculator.

  1. Choose 2D or 3D. In 2D the z boxes are ignored and both vectors are taken to lie in the xy-plane.
  2. Enter a, the vector you want to split, in the first set of fields: a force, a velocity, a column of data, or the position of a point measured from somewhere on the line.
  3. Enter b, the direction, in the second set. Its length does not matter, so (1, 2, 2) and (2, 4, 4) give the same projection, but at least one component must be non-zero.
  4. Read proj_b a for the part along b and the scalar projection for its signed length. A negative scalar means the projection points opposite to b.
  5. For a point-to-line distance read the rejection magnitude. To check hand working, add the projection and rejection component by component; the sum must be a.

The formula.

proj_b a = ( (a·b) ⁄ ‖b‖² ) b , comp_b a = (a·b) ⁄ ‖b‖

Everything rests on the dot product, a·b = axbx + ayby + azbz, which also equals ‖a‖‖b‖ cos θ (OpenStax Calculus Volume 3, section 2.3). Dividing it once by ‖b‖ = √(bx² + by² + bz²) leaves ‖a‖ cos θ, the scalar projection: comp_b a = (a·b) ⁄ ‖b‖. Multiplying that length by the unit vector b ⁄ ‖b‖ turns it into a vector, which gives proj_b a = ((a·b) ⁄ ‖b‖²) b. The fraction in front is a plain number, the scale factor, and it says what multiple of b the projection is: 2 means twice b, −0.5 means half of b turned around.

The rejection is r = a − proj_b a. Its dot product with b is a·b − ((a·b) ⁄ ‖b‖²)(b·b) = 0 for any inputs, so it is always perpendicular to b, and its length √(rx² + ry² + rz²) is the shortest distance from the tip of a to the line through b. By Pythagoras, comp² + ‖r‖² = ‖a‖². When a and b are perpendicular the dot product is zero, the projection shrinks to the zero vector and the rejection is all of a; when a is parallel to b the rejection vanishes. The one input with no answer is b = 0, since ‖b‖² would sit in the denominator as zero and a zero vector has no direction. A zero a is allowed and simply projects to zero.

A worked example.

Example

With a = (2, 2, 6) and b = (1, 2, 2), begin with the dot product: 2 × 1 + 2 × 2 + 6 × 2 = 2 + 4 + 12 = 18. The squared length of b is 1² + 2² + 2² = 9, so ‖b‖ = 3. The scale factor is 18 ÷ 9 = 2, and twice b is (2, 4, 4), so the projection is 2i + 4j + 4k. Its signed length is 18 ÷ 3 = 6, positive because the vectors are only about 25.2° apart (cos θ = 18 ÷ (3 × √44) ≈ 0.9045). The rejection is a minus the projection: (2 − 2, 2 − 4, 6 − 4) = (0, −2, 2). Dotting it with b gives 0 × 1 + (−2) × 2 + 2 × 2 = 0, which confirms the right angle, and its length is √(0 + 4 + 4) = √8 = 2.8284. The tip of a therefore sits 2.8284 units from the line through b. The pieces fit together exactly: (2, 4, 4) + (0, −2, 2) = (2, 2, 6), and 6² + 8 = 44 = ‖a‖².

bx1
ax2
by2
ay2
bz2
az6
dimension3

Frequently asked questions.

My scalar projection is negative. Did I enter something wrong?
Probably not: a negative value means the angle between a and b is over 90°. On the ramp, with b = (4, 3) pointing uphill and the weight a = (0, −98.1) N, the scalar projection is −58.86 N because gravity pulls downhill. Enter b as (−4, −3) and it becomes +58.86 N, while the projection vector, (−47.088, −35.316), does not change at all.
How do I get the distance from a point to a line that does not pass through the origin?
Subtract any point Q on the line from your point P and enter P − Q as a, with the line's direction as b. The rejection magnitude is the distance. For P = (5, 5) and the line through Q = (2, 1) with direction (1, 1), enter a = (3, 4) and b = (1, 1): the distance comes out as 0.7071, which is 1 ⁄ √2.
Is projecting a onto b the same as projecting b onto a?
No, because the vector you project onto sets both the direction and the denominator. With the default vectors, proj_b a is 2i + 4j + 4k with scalar projection 6, while projecting b = (1, 2, 2) onto a = (2, 2, 6) gives roughly 0.8182i + 0.8182j + 2.4545k with scalar projection 2.7136. Only the dot product, 18, is the same both ways.
Does it matter how long I make the direction vector b?
Not for the projection or the scalar projection, which depend only on b's direction. Entering b = (2, 4, 4) instead of (1, 2, 2) still gives 2i + 4j + 4k and a scalar projection of 6; only the dot product (now 36) and ‖b‖ (now 6) double. That is why a unit vector, a scaled copy or a direction read straight off a diagram all work equally well.
How does projection connect to the work done by a force?
Work is W = F·d, the force's scalar projection onto the displacement multiplied by the length of the displacement. Only the part of the force along the motion does work. A force at right angles to the motion, such as the normal force on a box sliding across a level floor, has zero projection onto the displacement and so does no work, however large it is.
What does projection have to do with least-squares fitting?
Fitting y ≈ βx through the origin by least squares gives β = (x·y) ⁄ (x·x), which is exactly the scale factor for projecting the data vector y onto x. The fitted values are the projection, the residuals are the rejection, and the residuals are perpendicular to x. Multiple regression does the same thing with a plane or higher-dimensional subspace in place of a single direction.

How this page was produced

Published by
Quanta Calculator
Primary sources
4 cited below
Method
proj_b a = ( (a·b) ⁄ ‖b‖² ) b , comp_b a = (a·b) ⁄ ‖b‖
Published
Last verified

Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.

In this category

Embed

Quanta Pro

Paid features are coming later.

  • All 1560 calculators remain free
  • No billing is enabled
Coming soon