Vector projection

The vector projection (also known as the vector component or vector resolution) of a vector $a$ on (or onto) a nonzero vector $b$ is the orthogonal projection of $a$ onto a straight line parallel to $b$. The projection of $a$ onto $b$ is often written as $$\operatorname{proj}_\mathbf{b} \mathbf{a}$$ or $a_{∥b}$.

The vector component or vector resolute of $a$ perpendicular to $b$, sometimes also called the vector rejection of $a$ from $b$ (denoted $$\operatorname{oproj}_{\mathbf{b}} \mathbf{a}$$ or $a_{⊥b}$), is the orthogonal projection of $a$ onto the plane (or, in general, hyperplane) that is orthogonal to $b$. Since both $$\operatorname{proj}_{\mathbf{b}} \mathbf{a}$$ and $$\operatorname{oproj}_{\mathbf{b}} \mathbf{a}$$ are vectors, and their sum is equal to $a$, the rejection of $a$ from $b$ is given by: $$\operatorname{oproj}_{\mathbf{b}} \mathbf{a} = \mathbf{a} - \operatorname{proj}_{\mathbf{b}} \mathbf{a}.$$

To simplify notation, this article defines $$\mathbf{a}_1 := \operatorname{proj}_{\mathbf{b}} \mathbf{a}$$ and $$\mathbf{a}_2 := \operatorname{oproj}_{\mathbf{b}} \mathbf{a}.$$ Thus, the vector $$\mathbf{a}_1$$ is parallel to $$\mathbf{b},$$ the vector $$\mathbf{a}_2$$ is orthogonal to $$\mathbf{b},$$ and $$\mathbf{a} = \mathbf{a}_1 + \mathbf{a}_2.$$

The projection of $a$ onto $b$ can be decomposed into a direction and a scalar magnitude by writing it as $$\mathbf{a}_1 = a_1\mathbf{\hat b}$$ where $$a_1$$ is a scalar, called the scalar projection of $a$ onto $b$, and $90° < θ ≤ 180°$ is the unit vector in the direction of $a_{1}$. The scalar projection is defined as $$a_1 = \left\|\mathbf{a}\right\|\cos\theta = \mathbf{a}\cdot\mathbf{\hat b}$$ where the operator &sdot; denotes a dot product, ‖a‖ is the length of $b$, and θ is the angle between $a$ and $b$. The scalar projection is equal in absolute value to the length of the vector projection, with a minus sign if the direction of the projection is opposite to the direction of $a$, that is, if the angle between the vectors is more than 90 degrees.

The vector projection can be calculated using the dot product of $$\mathbf{a}$$ and $$\mathbf{b}$$ as: $$\operatorname{proj}_{\mathbf{b}} \mathbf{a} = \left(\mathbf{a} \cdot \mathbf{\hat b}\right) \mathbf{\hat b} = \frac {\mathbf{a} \cdot \mathbf{b}} {\left\|\mathbf{b}\right\| } \frac {\mathbf{b}} {\left\|\mathbf{b}\right\|} = \frac {\mathbf{a} \cdot \mathbf{b}} {\left\|\mathbf{b}\right\|^2}{\mathbf{b}} = \frac {\mathbf{a} \cdot \mathbf{b}} {\mathbf{b} \cdot \mathbf{b}}{\mathbf{b}} ~ .$$

Notation
This article uses the convention that vectors are denoted in a bold font (e.g. $b$), and scalars are written in normal font (e.g. a1).

The dot product of vectors $b̂$ and $b$ is written as $$\mathbf{a}\cdot\mathbf{b}$$, the norm of $a$ is written ‖a‖, the angle between $a$ and $b$ is denoted θ.

Scalar projection
The scalar projection of $b$ on $a_{1}$ is a scalar equal to $$ a_1 = \left\|\mathbf{a}\right\| \cos \theta, $$ where θ is the angle between $a$ and $b$.

A scalar projection can be used as a scale factor to compute the corresponding vector projection.

Vector projection
The vector projection of $a$ on $a$ is a vector whose magnitude is the scalar projection of $b$ on $a$ with the same direction as $b$. Namely, it is defined as $$\mathbf{a}_1 = a_1 \mathbf{\hat b} = (\left\|\mathbf{a}\right\| \cos \theta) \mathbf{\hat b}$$ where $$a_1$$ is the corresponding scalar projection, as defined above, and $$\mathbf{\hat b}$$ is the unit vector with the same direction as $a$: $$\mathbf{\hat b} = \frac {\mathbf{b}} {\left\|\mathbf{b}\right\|}$$

Vector rejection
By definition, the vector rejection of $b$ on $a$ is: $$\mathbf{a}_2 = \mathbf{a} - \mathbf{a}_1$$

Hence, $$\mathbf{a}_2 = \mathbf{a} - \left(\left\|\mathbf{a}\right\| \cos \theta\right) \mathbf{\hat b}$$

Definitions in terms of a and b
When $θ$ is not known, the cosine of $θ$ can be computed in terms of $b$ and $a$, by the following property of the dot product $b$ $$ \mathbf{a} \cdot \mathbf{b} = \left\|\mathbf{a}\right\| \left\|\mathbf{b}\right\| \cos \theta$$

Scalar projection
By the above-mentioned property of the dot product, the definition of the scalar projection becomes: $$a_1 = \left\|\mathbf{a}\right\| \cos \theta = \frac {\mathbf{a} \cdot \mathbf{b}} { \left\|\mathbf{b}\right\|}.$$

In two dimensions, this becomes $$a_1 = \frac {\mathbf{a}_x \mathbf{b}_x + \mathbf{a}_y \mathbf{b}_y} {\left\|\mathbf{b}\right\|}.$$

Vector projection
Similarly, the definition of the vector projection of $b$ onto $b$ becomes: $$\mathbf{a}_1 = a_1 \mathbf{\hat b} = \frac {\mathbf{a} \cdot \mathbf{b}} {\left\|\mathbf{b}\right\| } \frac {\mathbf{b}} {\left\|\mathbf{b}\right\|},$$ which is equivalent to either $$\mathbf{a}_1 = \left(\mathbf{a} \cdot \mathbf{\hat b}\right) \mathbf{\hat b},$$ or $$\mathbf{a}_1 = \frac {\mathbf{a} \cdot \mathbf{b}} {\left\|\mathbf{b}\right\|^2}{\mathbf{b}} = \frac {\mathbf{a} \cdot \mathbf{b}} {\mathbf{b} \cdot \mathbf{b}}{\mathbf{b}} ~ .$$

Scalar rejection
In two dimensions, the scalar rejection is equivalent to the projection of $a$ onto $$\mathbf{b}^\perp = \begin{pmatrix}-\mathbf{b}_y & \mathbf{b}_x\end{pmatrix}$$, which is $$\mathbf{b} = \begin{pmatrix}\mathbf{b}_x & \mathbf{b}_y\end{pmatrix}$$ rotated 90° to the left. Hence, $$a_2 = \left\|\mathbf{a}\right\| \sin \theta = \frac {\mathbf{a} \cdot \mathbf{b}^\perp} {\left\|\mathbf{b}\right\|} = \frac {\mathbf{a}_y \mathbf{b}_x - \mathbf{a}_x \mathbf{b}_y} {\left\|\mathbf{b}\right\| }.$$

Such a dot product is called the "perp dot product."

Vector rejection
By definition, $$\mathbf{a}_2 = \mathbf{a} - \mathbf{a}_1 $$

Hence, $$\mathbf{a}_2 = \mathbf{a} - \frac {\mathbf{a} \cdot \mathbf{b}} {\mathbf{b} \cdot \mathbf{b}}{\mathbf{b}}.$$

By using the Scalar rejection using the perp dot product this gives

$$\mathbf{a}_2 = \frac{\mathbf{a}\cdot\mathbf{b}^\perp}{\mathbf{b}\cdot\mathbf{b}}\mathbf{b}^\perp$$

Scalar projection
The scalar projection $b$ on $a$ is a scalar which has a negative sign if 90 degrees < θ ≤ 180 degrees. It coincides with the length $b$ of the vector projection if the angle is smaller than 90°. More exactly:
 * $a &sdot; b$ if $a$,
 * $b$ if $a$.

Vector projection
The vector projection of $a$ on $b$ is a vector $a$ which is either null or parallel to $b$. More exactly:
 * $‖c‖$ if $a_{1} = ‖a_{1}‖$,
 * $0° ≤ θ ≤ 90°$ and $a_{1} = −‖a_{1}‖$ have the same direction if $90° < θ ≤ 180°$,
 * $a$ and $b$ have opposite directions if $a_{1}$.

Vector rejection
The vector rejection of $b$ on $a_{1} = 0$ is a vector $θ = 90°$ which is either null or orthogonal to $a_{1}$. More exactly:
 * $b$ if $0° ≤ θ < 90°$ or $a_{1}$,
 * $b$ is orthogonal to $90° < θ ≤ 180°$ if $a$,

Matrix representation
The orthogonal projection can be represented by a projection matrix. To project a vector onto the unit vector $b$, it would need to be multiplied with this projection matrix: $$P_\mathbf{a} = \mathbf{a} \mathbf{a}^\textsf{T} = \begin{bmatrix} a_x \\ a_y \\ a_z \end{bmatrix} \begin{bmatrix} a_x & a_y & a_z \end{bmatrix} = \begin{bmatrix} a_x^2 & a_x a_y & a_x a_z \\ a_x a_y & a_y^2 & a_y a_z \\ a_x a_z & a_y a_z & a_z^2 \\ \end{bmatrix}$$

Uses
The vector projection is an important operation in the Gram–Schmidt orthonormalization of vector space bases. It is also used in the separating axis theorem to detect whether two convex shapes intersect.

Generalizations
Since the notions of vector length and angle between vectors can be generalized to any n-dimensional inner product space, this is also true for the notions of orthogonal projection of a vector, projection of a vector onto another, and rejection of a vector from another.

In some cases, the inner product coincides with the dot product. Whenever they don't coincide, the inner product is used instead of the dot product in the formal definitions of projection and rejection. For a three-dimensional inner product space, the notions of projection of a vector onto another and rejection of a vector from another can be generalized to the notions of projection of a vector onto a plane, and rejection of a vector from a plane. The projection of a vector on a plane is its orthogonal projection on that plane. The rejection of a vector from a plane is its orthogonal projection on a straight line which is orthogonal to that plane. Both are vectors. The first is parallel to the plane, the second is orthogonal.

For a given vector and plane, the sum of projection and rejection is equal to the original vector. Similarly, for inner product spaces with more than three dimensions, the notions of projection onto a vector and rejection from a vector can be generalized to the notions of projection onto a hyperplane, and rejection from a hyperplane. In geometric algebra, they can be further generalized to the notions of projection and rejection of a general multivector onto/from any invertible k-blade.