Orthogonal Projection Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

Orthogonal projection onto a subspace: what this calculator does

This calculator computes the orthogonal projection of a vector vR3 onto a subspace spanned by up to three basis vectors. It also lets you see the connection to the standard projection matrix formula used in linear algebra, least squares, and numerical methods.

You enter the components of v and up to three basis vectors b1,b2,b3. The tool then:

  • Forms the matrix whose columns are the basis vectors.
  • Builds the associated projection matrix.
  • Computes the projected vector p in the subspace.
  • Computes the orthogonal component vp.

This is useful for visualizing projections in R3, checking homework, and understanding how least squares and Gram–Schmidt orthogonalization work under the hood.

How orthogonal projection works (formulas)

Let S be a subspace of R3 spanned by linearly independent vectors b1,,bk with 1k3. Stack these basis vectors as columns in a matrix

A=[b1 b2  bk],A3×k.

The orthogonal projection matrix onto the column space of A is

P=A(ATA)1AT.

Here:

  • AT is the transpose of A.
  • ATA is the Gram matrix, whose entries are inner products biTbj.
  • ATA1 is the inverse of the Gram matrix (it exists only if the basis vectors are linearly independent).
  • P is a 3×3 matrix that sends any vR3 to its projection p=Pv in the subspace.

At the vector level, you can also think of the projection as follows. We look for coefficients ck such that

p=Ac

is the closest vector in the subspace to v in the Euclidean norm. Solving the normal equations

ATAc=ATv

gives

c=(ATA-1ATv,,p=Ac=A(ATA-1ATv.

In MathML form, the projection matrix formula can be written as:

P = A ( AT A -1 ) AT

The matrix P has two key properties that characterize orthogonal projection:

  • Idempotent: P2=P. Applying the projection twice does nothing new.
  • Symmetric: PT=P. This symmetry encodes orthogonality of the residual.

The residual (or error) vector is

r=vp=(IP)v,

and it satisfies rS, meaning it is orthogonal to every vector in the subspace.

Interpreting the results

When you use the calculator, you will typically see at least two key outputs:

  • Projected vector p: the shadow of v on the chosen subspace.
  • Orthogonal component vp: the part of v that lies outside the subspace.

Geometrically, the projection p is the point in the subspace that is closest to v in Euclidean distance. The vector vp is perpendicular to the entire subspace, not just to one basis vector.

Numerically, you might also inspect:

  • The length (norm) of p, which tells you how large the component of v inside the subspace is.
  • The length of vp, which is the distance from v to the subspace.

If the subspace is a line (one basis vector), the projection is just the component of v along that line. If the subspace is a plane (two independent basis vectors), the projection is the point in the plane obtained by dropping a perpendicular from v to the plane.

Worked example in R3

Consider v=(1,2,3) and the subspace spanned by b1=(1,0,0) and b2=(0,1,0). This subspace is the xy-plane.

The matrix of basis vectors is

A=[b1b2]=100100.

Then

AT A= 1001, (AT A1)= 1001.

The projection matrix is

P=A(AT)(A)-1AT

Applying P to v gives

p=Pv=[100010000][123]=[120].

So the projection of v onto the xy-plane is p=(1,2,0). The orthogonal component is

vp=123120=003,

which points straight along the z-axis. Geometrically, this corresponds to dropping a perpendicular from the point 123 onto the xy-plane.

The calculator reproduces this example if you enter v=(1,2,3), set b1=(1,0,0), b2=(0,1,0), and either leave b3=(0,0,0) or at its default value representing the z-axis.

Comparison: single vector vs. subspace projection

Projecting onto a single vector is a special case of projection onto a subspace. The formulas simplify when there is only one basis vector, but the geometric idea is the same.

Case Setup Projection formula Typical use
Projection onto a single vector Subspace is span of one nonzero vector b. projb(v)=vTbbTbb Decomposing motion along a direction, resolving forces, simple geometry.
Projection onto a subspace Subspace is span of k independent vectors, collected as columns of A. projspan(A)(v)=A(ATA1)ATv Least squares, regression, dimensionality reduction, numerical linear algebra.

This calculator always uses the general subspace formula, so it works for both situations: if you only want to project onto a single direction, just provide one nonzero basis vector and leave the others at zero.

Limitations and assumptions of this calculator

The tool is designed to be simple and numerically stable for common educational and applied use cases. It makes several assumptions you should be aware of:

  • Dimension fixed to R3: all vectors are three-dimensional. The calculator does not handle higher or lower dimensions.
  • Up to three basis vectors: you can enter between one and three basis vectors. To work with a line, enter one nonzero basis vector; for a plane, enter two linearly independent basis vectors; for R3 itself, enter three independent vectors.
  • Linear independence required: the basis vectors you provide must be linearly independent for the Gram matrix ATA to be invertible. If they are dependent (for example, one is a multiple of another), the calculator cannot form ATA1 and will report an error instead of a projection.
  • Zero or unused vectors: if you leave a basis vector as all zeros, it contributes nothing to the span. Use this to indicate that your subspace has lower dimension (for example, one or two active basis vectors instead of three).
  • Floating-point arithmetic: computations are carried out numerically. If ATA is very close to singular, small rounding errors may lead to large changes in the result. In such borderline cases the calculator may display a warning or treat the matrix as singular.
  • Euclidean inner product: the projection is always with respect to the standard dot product on R3. Weighted inner products or non-Euclidean geometries are not supported.

Being aware of these conditions will help you interpret the output correctly and avoid relying on the tool in cases it is not designed to handle.

Connections and applications

Orthogonal projection is more than a geometric curiosity. It underlies several core techniques:

  • Least squares and regression: solving an overdetermined system A xb by least squares is equivalent to projecting b onto the column space of A. The residual bAx is orthogonal to that column space.
  • Gram–Schmidt orthogonalization: building an orthonormal basis from arbitrary vectors uses repeated projection and subtraction of orthogonal components.
  • Data analysis and dimension reduction: in methods like principal component analysis (PCA), data is projected onto lower-dimensional subspaces capturing the most variance.
  • Computer graphics and geometry: projecting 3D points onto planes or lines is fundamental for rendering, collision detection, and camera transformations.

The same matrix formula implemented by this calculator is used implicitly in these applications, often at a much larger scale. Working with concrete three-dimensional examples can make these abstract ideas more tangible.

Enter the components of the vector to be projected and up to three basis vectors defining the subspace (leave unused basis vectors as zeros). Vectors are assumed to be in R3.

Vector
Basis 1
Basis 2
Basis 3
Enter vector and basis values, then project to view the components.

Embed this calculator

Copy and paste the HTML below to add the Orthogonal Projection onto a Subspace Calculator to your website.