Introduction to orthogonal projection onto a subspace
This orthogonal projection calculator shows how a vector in
is split into the part that lies in a chosen subspace and the part that points straight out of it. The geometric picture is a shadow, but the algebraic picture is just as important because it lets you compare a vector with a line, a plane, or any span built from one to three basis vectors.
That split shows up every time you solve a least-squares problem, orthogonalize a basis, or drop a point onto a plane in graphics. This page gives you the numbers quickly, but it also explains what those numbers mean so you can read them the same way you would in a linear algebra class or in an engineering calculation.
How to Use This Orthogonal Projection Calculator
To use this orthogonal projection calculator, enter the vector you want to project and then describe the destination subspace with up to three basis vectors. One nonzero basis vector defines a line, two independent vectors define a plane, and three independent vectors span all of
.
After you click Project Vector, the calculator assembles the basis matrix, checks whether the active basis vectors are linearly independent, and computes the projection. The results area then shows the projected vector, the residual vector
,
and the distance from the original vector to the chosen subspace. If the active vectors are dependent, the tool stops and explains why the projection matrix cannot be built from those inputs.
Keep the components in the same units if they have units. If the inputs are distances in meters, then the projected vector and residual are also interpreted in meters. The vector you supply describes what you are projecting, while the basis vectors describe the line, plane, or subspace that receives the projection.
Orthogonal projection onto a subspace: what this calculator does
This orthogonal projection calculator computes the orthogonal projection of a vector 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 and up to three basis vectors . The tool then:
- Forms the matrix whose columns are the active basis vectors.
- Builds the associated projection matrix.
- Computes the projected vector in the subspace.
- Computes the orthogonal component .
This is useful for visualizing projections in , checking homework, and understanding how least squares and Gram–Schmidt orthogonalization work under the hood.
How orthogonal projection works (formulas)
Let be a subspace of spanned by linearly independent vectors
with . Stack these basis vectors as columns in a matrix
Formula: A = [b_1 b_2 ⋯ b_k], A ∈ ℝ^3×k.
The orthogonal projection matrix onto the column space of is
Formula: P = A (A^TA)^−1 A^T.
Here:
- is the transpose of .
- is the Gram matrix, whose entries are inner products .
- is the inverse of the Gram matrix (it exists only if the basis vectors are linearly independent).
- is a matrix that sends any to its projection in the subspace.
At the vector level, you can also think of the projection as follows. We look for coefficients such that
Formula: p = A c
is the closest vector in the subspace to in the Euclidean norm. Solving the normal equations
Formula: A^T A c = A^T v
gives
Formula: c = (A^TA^-1 A^T v,, p = A c = A (A^TA^-1 A^T v.
In MathML form, the projection matrix formula can be written as:
The matrix has two key properties that characterize orthogonal projection:
- Idempotent: . Applying the projection twice does nothing new.
- Symmetric: . This symmetry encodes orthogonality of the residual.
The residual (or error) vector is
Formula: r = v − p = (I − P) v,
and it satisfies , meaning it is orthogonal to every vector in the subspace.
Interpreting the orthogonal projection results
When you use the calculator, you will typically see at least two key outputs:
- Projected vector : the shadow of on the chosen subspace.
- Orthogonal component : the part of that lies outside the subspace.
Geometrically, the projection is the point in the subspace that is closest to in Euclidean distance. The vector is perpendicular to the entire subspace, not just to one basis vector.
Numerically, you might also inspect:
- The length (norm) of , which tells you how large the component of inside the subspace is.
- The length of , which is the distance from to the subspace.
If the subspace is a line (one basis vector), the projection is just the component of 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 to the plane.
Worked example: projecting onto the xy-plane
Here is a concrete orthogonal projection example in . Consider and the subspace spanned by
and . This subspace is the -plane, so the projection keeps the horizontal coordinates and removes the vertical one.
The matrix of basis vectors is
Formula: A = [b_1 b_2] = 1 0 0 1 0 0.
Then
Formula: A^T A = 1 0 0 1,(A^TA^−1) = 1 0.
The projection matrix is
Formula: P = A (A^T^-1 A^T
Applying to gives
Formula: p = P v = [1 0 0 0 1 0 0 0 0] [1 2 3] = [1 2 0].
So the projection of onto the -plane is . The orthogonal component is
Formula: v − p = 1 2 3 − 1 2 0 = 0 0 3,
which points straight along the -axis. Geometrically, this corresponds to dropping a perpendicular from the point onto the -plane.
The calculator reproduces this example if you enter , set
, , and set the third basis vector to zero:
.
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 . |
|
Decomposing motion along a direction, resolving forces, simple geometry. |
| Projection onto a subspace |
Subspace is span of independent vectors, collected as columns of . |
|
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 for orthogonal projection in R3
This orthogonal projection calculator is designed to be straightforward for common educational and applied use cases. It makes several assumptions you should be aware of:
-
Dimension fixed to :
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 itself, enter three independent vectors.
-
Linear independence required:
the basis vectors you provide must be linearly independent for the Gram matrix to be invertible. If they are dependent (for example, one is a multiple of another), the calculator cannot form 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 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 . 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 by least squares is equivalent to projecting onto the column space of . The residual 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 a vector and basis values to compute its orthogonal projection and residual. The default values reproduce the xy-plane example discussed below.