Vector Projection Calculator

Vector Projection Calculator projb a

Enter two vectors as comma or space separated numbers (2D like 3 4 or 3D like 1 2 2). You get the scalar projection of a onto b, the vector projection with its components, the rejection (the perpendicular part), and the dot product — plus a live diagram for 2D, the full steps, and the NumPy code.

Examples:

This free vector projection calculator takes two vectors — in 2D or 3D — and returns the scalar projection of a onto b, the full vector projection with its components, and the rejection (the part of a that is perpendicular to b). For 2D inputs it draws a diagram so you can see the projection as the shadow of a cast onto the line through b, then shows every step and the matching NumPy code. Type your components above, press Compute, and you get the geometry as well as the numbers.

What a vector projection is

The projection of one vector onto another answers a simple geometric question: if you shine a light straight down onto the line that vector b points along, how long is the shadow that vector a casts, and where does it land? That shadow is the vector projection of a onto b. It is the piece of a that runs parallel to b, and it is the closest point on the line through b to the tip of a. Everything left over — the part of a that sticks out perpendicular to b — is called the rejection. Together the projection and the rejection add back up to the original vector a, splitting it cleanly into a component along b and a component at right angles to b.

There are two flavours of the answer. The scalar projection is a single number: the signed length of that shadow. It is positive when a leans in the same general direction as b, zero when a is perpendicular to b, and negative when a leans the opposite way. The vector projection is the full arrow: it has both that length and the direction of b, so it is an actual vector you can add to other vectors. This calculator reports both, plus the rejection and the dot product they are built from.

How to use the vector projection calculator

  1. Type Vector a — the vector you want to project — as comma or space separated numbers. Use two components for a 2D vector (3 4) or three for a 3D vector (1 2 2).
  2. Type Vector b — the direction you are projecting onto. It must have the same dimension as a, and it cannot be the zero vector, because a zero vector points nowhere.
  3. Press Compute. The stat tiles fill in with the scalar projection (highlighted), the vector projection and its components, the rejection, and the dot product.
  4. For 2D inputs, read the diagram: vector a is indigo, vector b is violet, the green arrow is the projection lying along b, and the grey dashed line drops perpendicularly from the tip of a to the tip of the projection.
  5. Use the Decimals selector to switch between automatic precision and a fixed 0, 2, or 4 places, and press Copy result to grab a one-line summary.

The example chips are the fastest way to explore. Simple projects [3, 4] onto the x-axis [1, 0], so the answer is just the x-component. Diagonal projects onto [1, 1] to show a slanted shadow. 3D demonstrates that the formula works in three dimensions even without a diagram, and Random throws two fresh 2D vectors at the plane.

A worked example

Take a = [3, 4] and b = [1, 0]. First compute the dot product: a·b = 3×1 + 4×0 = 3. The sum of squares of b is b·b = 1² + 0² = 1, so the magnitude of b is |b| = √1 = 1. The scalar projection is a·b / |b| = 3 / 1 = 3. The scale factor for the vector projection is a·b / (b·b) = 3 / 1 = 3, so the vector projection is 3 × [1, 0] = [3, 0]. The rejection is a − proj = [3, 4] − [3, 0] = [0, 4], which is exactly the vertical part of a — the piece that has nothing to do with the horizontal direction b. This is precisely what the calculator returns when you load the Simple example: scalar projection 3 and vector projection [3, 0].

The formulas

Everything starts from the dot product, which multiplies matching components and sums them: a·b = Σ aibi. The dot product measures how much of a already points along b, scaled by the length of b.

The scalar projection of a onto b, sometimes written compb a, divides that by the length of b to strip out b's own size and leave a pure length:

compb a = (a·b) / |b| = (a·b) / √(Σ bi²)

The vector projection projb a takes that length and attaches the direction of b. The clean way to write it avoids a separate square root by dividing by b·b (the sum of squares of b) instead of by |b|:

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

The quantity in the parentheses is a plain number — the scale factor — and multiplying it by the vector b componentwise gives the projection. Because b·b = |b|², this is the same as (compb a / |b|) b; the calculator uses the b·b form because it is numerically tidier.

The rejection is simply what is left over: a − projb a. By construction it is perpendicular to b — you can check that its dot product with b is zero — and it satisfies a = proj + rejection. This split of a vector into a parallel part and a perpendicular part is called orthogonal decomposition, and it is one of the most useful ideas in all of linear algebra.

The geometric meaning: the shadow of a onto b

Picture vector a as an arrow and vector b as a straight rail running through the origin. Drop a perpendicular from the tip of a straight down onto that rail. The point where it lands is the tip of the vector projection, and the arrow from the origin to that point is projb a. The perpendicular line you dropped is the rejection. That is why the diagram draws the projection in green lying flat along b, and the rejection as a grey dashed line meeting b at a right angle.

This picture explains the signs. If a points broadly the same way as b, the shadow falls on the positive side of the rail and the scalar projection is positive. If a is exactly perpendicular to b, the shadow shrinks to the origin: the dot product is zero, the scalar projection is zero, and the vector projection is the zero vector. If a leans backwards relative to b, the shadow lands on the negative side of the rail and the scalar projection comes out negative even though a length cannot be negative — the sign is telling you which way along b the shadow points. Notice too that the projection only depends on the direction of b, not its length: stretching b to twice its size leaves projb a unchanged, because the extra length in the numerator and denominator cancels.

Common mistake
Do not confuse the scalar projection with the vector projection. The scalar projection is a single number (a signed length); the vector projection is a full vector pointing along b. A second frequent slip is projecting onto the wrong vector: projb a (a onto b) is generally not equal to proja b (b onto a). And never project onto a zero vector — b·b would be zero and the division is undefined, which is why the calculator asks for a non-zero b.

Vector projection in Python with NumPy

In code, the projection is a two-line calculation built on numpy.dot:

import numpy as np
a = np.array([3, 4])
b = np.array([1, 0])
scalar_proj = np.dot(a, b) / np.linalg.norm(b) # signed length
vector_proj = (np.dot(a, b) / np.dot(b, b)) * b # the projection vector
rejection = a - vector_proj # perpendicular part
print(scalar_proj) # 3.0
print(vector_proj) # [3 0]
print(rejection) # [0 4]

The np.dot(b, b) term is the sum of squares of b, the same denominator this tool uses, and it avoids the extra square root that np.linalg.norm(b)**2 would introduce. Because the calculator and NumPy use identical definitions, you can prototype a projection here and reproduce it exactly in code.

Where projection shows up in machine learning

Vector projection is quietly everywhere in machine learning because it is the tool for asking "how much of this points in that direction?" The most visible example is the Gram-Schmidt process, which turns a set of vectors into an orthonormal basis by repeatedly subtracting off projections — each new vector has the projections onto all the earlier ones removed, leaving only the rejection, so that the result is perpendicular to everything before it. That same subtract-the-projection step powers QR decomposition, which underlies least-squares regression and many numerical solvers.

Projection is also the heart of orthogonal decomposition, which is how linear regression really works: fitting a line by least squares is exactly projecting the target vector onto the column space of the feature matrix, so the fitted values are a projection and the residuals are the rejection. Dimensionality-reduction methods such as PCA project data onto the directions of greatest variance. And the scalar projection is a close cousin of cosine similarity: both are built from the same a·b numerator, and both measure directional agreement, which is why embedding models, recommendation engines, and semantic search all lean on the same arithmetic you see on this page. Learning to compute projections by hand makes those algorithms far less mysterious.

Frequently asked questions

What is the difference between scalar and vector projection?

The scalar projection is a single signed number — the length of the shadow a casts onto the line through b, positive or negative depending on direction. The vector projection is a full vector: it has that length and the direction of b, so it is an arrow lying along b. This calculator gives you both.

Does the projection work for 3D vectors?

Yes. Enter three components for each vector, such as 1 2 2 and 2 0 0, and the tool computes the scalar projection, vector projection, and rejection. The diagram is drawn only for 2D vectors, but every numeric result works in 3D.

Why can vector b not be the zero vector?

The projection divides by b·b, the sum of squares of b's components. For the zero vector that sum is zero, so the division is undefined — and geometrically a zero vector points in no direction, so there is no line to project onto. The calculator asks for a non-zero b.

What is the rejection used for?

The rejection is the part of a that is perpendicular to b, equal to a − proj. It is central to the Gram-Schmidt process, to computing residuals in least-squares regression, and to any task where you want to remove one direction's influence from a vector.

Are the results the same as NumPy?

Yes. The scalar projection matches np.dot(a, b) / np.linalg.norm(b), and the vector projection matches (np.dot(a, b) / np.dot(b, b)) * b, because they use the same definitions.

Related calculators

Explore the full linear algebra calculators hub, or work with the underlying operations using the vector calculator and the dot product calculator.