#### xaktly | Matrix and Vector Algebra

Vector projections

### Specifying the direction of a vector

It's often necessary to figure out "how much" a vector points along a certain direction or directions. To do that, we use vector projections. The word projector hints at shadows cast on the wall on which a projector light is shining. It's appropriate for vector projections. Here's a simple picture. Vector $\vec{v_1}$ does not point purely in the direction of $\vec{v_2},$ but it does a little bit. Our projection vector is a measure of precisely how much of $\vec{v_1}$ points along $\vec{v_2}.$

Here's another way to visualize projections. think about a light or lamp pointing in a direction perpendicular to $\vec{v_2}.$ Then the "shadow" of $\vec{v_1}$ along $\vec{v_2}$ is its projection In this section we'll learn how to calculate and use projections of one vector on another.

### Directions along axes

Sticking with three dimensions for now, it's fairly easy to find the angles that an $\mathbb{R}^3$ vector makes with the coordinate system. We identify the coordinate directions with the unit vectors $\hat{i} = (1, 0, 0), \; \hat{j} = (0, 1, 0),$ and $\hat{k} = (0, 0, 1).$ Now remember that the dot product of two vectors is

$$\vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}| cos (\theta),$$

So that the cosine of the angle between them is

$$cos(\theta) = \frac{\vec{a} \cdot \vec{b}}{|\vec{a}||\vec{b}|}.$$

Now if our vector of interest is $\vec{a}$ and $\vec{b}$ is the the unit vector $\hat{i})$ in the x direction, then that cosine is just

$$cos(\theta) = \frac{\vec{a} \cdot \hat{i}}{|\vec{a}||\hat{i}|} = \frac{a_1}{|\vec{a}|},$$

where a1 is the first (or x) coordinate of vector $\vec{a},$ selected by multiplying $\vec{a}$ by (1, 0, 0), and the lengths of vectors i, j, k (unit vectors) are one. So if we let the angles α, β and γ be the angles between vector $\vec{a} = (a_1, a_2, a_3)$ and the three unit vectors that define our 3-D axis system, we obtain the three so-called direction cosines of that vector,

\begin{align} cos(\alpha) &= \frac{a_1}{|\vec{a}|} \\[5pt] cos(\beta) &= \frac{a_2}{|\vec{a}|} \\[5pt] cos(\gamma) &= \frac{a_3}{|\vec{a}|} \\[5pt] \end{align}

Now think about squaring each of those terms and adding them. We get

$$\frac{a_1^2}{|\vec{a}|^2} + \frac{a_2^2}{|\vec{a}|^2} + \frac{a_3^2}{|\vec{a}|^2} = \frac{a_1^2 + a_2^2 + a_3^2}{|a|^2}$$

Now notice that the numerator is just the length of $\vec{a}$ squared, as is the denominator, so this expression equals 1, which gives

$cos^2(\alpha) + cos^2(\beta) + cos^2(\gamma) = 1,$ and

$$\frac{1}{|\vec{a}|} \vec{a} = (cos(\alpha), \, cos(\beta), \, cos(\gamma)).$$

This is a nice compact formula for finding the direction cosines of any vector in $\mathbb{R}^3,$ and it can be generalized to any number of dimensions.

Here's a picture of those angles: The angles are shown, and the green vectors are the projections of $\vec{a}$ on the coordinate axes. They are multiples of the unit vectors $\hat{i}, \, \hat{j}, \, \hat{k}.$

### Example 1

Find the direction cosines of the $\mathbb{R}^3$ vector $\vec{a} = (1, \, 3, \, 4).$

Solution: The cosines and resulting angles are

\begin{align} cos(\alpha) &= \frac{1}{\sqrt{26}} \; \rightarrow \; \alpha = 79˚ \\[5pt] cos(\beta) &= \frac{3}{\sqrt{26}} \; \rightarrow \; \beta = 54˚ \\[5pt] cos(\gamma) &= \frac{4}{\sqrt{26}} \; \rightarrow \; \gamma = 38˚ \end{align}

### Projections

Now let's move from direction angles to finding the projections of vectors on the coordinate axes to the projection of a vector on some other arbitrary vector. Here's the basic idea; we'd like to find the projection of vector b on vector a, where the points P, Q and R are endpoints of our vectors, as shown: Notice from the figure that our projection, $\vec{s},$ is just the length of $\vec{b}$ multiplied by the cosine of the angle (the direction cosine). We'll use the dot product to find $\vec{s}.$

\begin{align} \vec{a} \cdot \vec{b} &= |\vec{a}||\vec{b}| cos(\theta) \\[5pt] &= |\vec{a}|(|\vec{b}| cos(\theta)) \end{align}

Now the projection is just

\begin{align} |\vec{b}| cos(\theta) &= \frac{\vec{a} \cdot \vec{b}}{|\vec{a}|} \\[5pt] &= \frac{\vec{a}}{|\vec{a}|} \cdot \vec{b} \end{align}

So the projection of $\vec{b}$ along $\vec{a}$ is just dot product of the direction cosine vector, $(\vec{a}/| \vec{a}|),$ with $\vec{b}.$ Note that this is a scalar, which simply gives us the distance along $\vec{a}$ to the end of the projection vector.

Now if we want our result to be the full projection vector, we just need to multiply the the scalar projection by the normalized or unit a vector:

$$\frac{\vec{a}}{|\vec{a}|} \cdot \vec{b} \left( \frac{\vec{a}}{|\vec{a}|} \right) = (\vec{a} \cdot \vec{b}) \frac{\vec{a}}{|\vec{a}|^2}$$

These formulas can get a little confusing, but try to keep in mind the basic geometry of things. The length of the projection is just found using right-triangle trigonometry; to get the projection vector, just multiply this length by the unit vector in the direction of the vector your projecting onto (i.e. the normalized version of that vector).

### Example 2

Determine the vector projection of $\vec{a} = (1, \, 2, \, 3)$ on $\vec{b} = (-3, \, 2, \, 1).$

Solution: The scalar projection is

\begin{align} \frac{\vec{a}}{|\vec{a}|} \cdot \vec{b} &= \frac{1}{\sqrt{14}} [(1, 2, 3)\cdot (-3, 2, 1)] \\[5pt] &= \frac{4}{\sqrt{14}} \end{align}

Now to get the vector projection we just multiply that length by the unit vector a:

\begin{align} \vec{s} &= \frac{4}{\sqrt{14}} \left[ \frac{1}{\sqrt{14}} (-3, 2, 1) \right] \\[5pt] &= \left( \frac{-6}{7}, \, \frac{4}{7}, \, \frac{2}{7} \right) \end{align}

#### Scalar & vector projections

The length of the projection (the scalar projection) of vector $\vec{b}$ on $\vec{a}$ is

$$s = \frac{\vec{a}}{|\vec{a}|} \cdot \vec{b}$$

The vector projection is that scalar value (scalar projection) multiplied by the unit or normalized vector $\vec{a}:$

$$\vec{s} = s \frac{\vec{a}}{|\vec{a}|}$$

### Practice problems

 1 Determine the direction cosines and the angles these $\mathbb{R}^3$ vectors form with the x, y and z axes.   $\vec{a} = (-1, \, 0, \, 1)$   $\vec{a} = (1, \, 2, \, -5)$   $\vec{a} = (1, \, 2, \, 2)$ Solution (a) Vector length: $$|\vec{a}| = \sqrt{1 + 0 + 1} = \sqrt{2}$$ Cosines and angles: \begin{align} cos(\alpha) &= \frac{a_1}{|\vec{a}|} = \frac{-1}{\sqrt{2}} \\[5pt] \alpha &= 45˚ \\[5pt] cos(\beta) &= \frac{a_2}{|\vec{a}|} = \frac{0}{\sqrt{2}} \\[5pt] \beta &= 90˚ \\[5pt] cos(\gamma) &= \frac{a_3}{|\vec{a}|} = \frac{1}{\sqrt{2}} \\[5pt] \gamma &= 45˚ \\[5pt] \end{align} Recall that cos(x) is an even function, so f(-x) = f(x) (b) Vector length: $$|\vec{a}| = \sqrt{1 + 4 + 25} = \sqrt{30}$$ Cosines and angles: \begin{align} cos(\alpha) &= \frac{1}{\sqrt{30}} \\[5pt] \alpha &= 79.5˚ \\[5pt] cos(\beta) &= \frac{2}{\sqrt{30}} \\[5pt] \beta &= 43˚ \\[5pt] cos(\gamma) &= \frac{-5}{\sqrt{30}} \\[5pt] \gamma &= 156˚ \\[5pt] \end{align} (c) Vector length: $$|\vec{a}| = \sqrt{1 + 4 + 4} = 3$$ Cosines and angles: \begin{align} cos(\alpha) &= \frac{1}{3} \\[5pt] \alpha &= 70.5˚ \\[5pt] cos(\beta) &= \frac{2}{3} \\[5pt] \beta &= 48˚ \\[5pt] cos(\gamma) &= \frac{2}{3} \\[5pt] \gamma &= 48˚ \\[5pt] \end{align} 2 Calculate the scalar and vector projections of $\vec{b}$ onto $\vec{a}.$   $\vec{a} = (-1, \, 2)$   $\vec{b} = (2, \, 3)$   $\vec{a} = (-1, \, 2, \, 3)$   $\vec{b} = (1, \, 2, \, 4)$   $\vec{a} = (2, \, 5, \, -2)$   $\vec{b} = (1, \, 1, \, 2)$ Solution (a) Length of vector a: $$|\vec{a}| = \sqrt{1 + 4} = \sqrt{5}$$ Scalar projection: \begin{align} s &= \frac{\vec{a}}{|\vec{a}|} \cdot b \\[5pt] &= \left( \frac{-1}{\sqrt{5}}, \frac{2}{\sqrt{5}} \right)\cdot (2, 3) \\[5pt] &= \frac{-2}{\sqrt{5}} + \frac{6}{\sqrt{5}} = \frac{4}{\sqrt{5}} \end{align} Now the vector projection: \begin{align} \vec{s} &= s \frac{\vec{a}}{|\vec{a}|} \\[5pt] &= \frac{4}{\sqrt{5}} \left( \frac{-1}{\sqrt{5}}, \frac{2}{\sqrt{5}} \right) \\[5pt] &= \left( \frac{-4}{5}, \frac{8}{5} \right) \end{align} (b) Length of vector a: $$|\vec{a}| = \sqrt{1 + 4 + 9} = \sqrt{14}$$ Scalar projection: \begin{align} s &= \frac{\vec{a}}{|\vec{a}|} \cdot b \\[5pt] &= \left( \frac{-1}{\sqrt{14}}, \frac{2}{\sqrt{14}}, \frac{3}{\sqrt{14}} \right)\cdot (1, 2, 4) \\[5pt] &= \frac{-1}{\sqrt{14}} + \frac{2}{\sqrt{14}} + \frac{12}{\sqrt{14}} \\[5pt] &= \frac{13}{\sqrt{14}} \end{align} Now the vector projection: \begin{align} \vec{s} &= s \frac{\vec{a}}{|\vec{a}|} \\[5pt] &= \frac{13}{\sqrt{14}} \left( \frac{-1}{\sqrt{14}}, \frac{2}{\sqrt{14}}, \frac{3}{\sqrt{14}} \right) \\[5pt] &= \left( \frac{-13}{14}, \frac{26}{14}, \frac{39}{14} \right) \\[5pt] &= \left( \frac{-13}{14}, \frac{13}{7}, \frac{39}{14} \right) \end{align} (c) Length of vector a: $$|\vec{a}| = \sqrt{4 + 25 + 4} = \sqrt{33}$$ Scalar projection: \begin{align} s &= \frac{\vec{a}}{|\vec{a}|} \cdot b \\[5pt] &= \left( \frac{2}{\sqrt{33}}, \frac{5}{\sqrt{33}}, \frac{-2}{\sqrt{33}} \right)\cdot (1, 1, 2) \\[5pt] &= \frac{2}{\sqrt{33}} + \frac{5}{\sqrt{33}} - \frac{2}{\sqrt{33}} \\[5pt] &= \frac{5}{\sqrt{33}} \end{align} Now the vector projection: \begin{align} \vec{s} &= s \frac{\vec{a}}{|\vec{a}|} \\[5pt] &= \frac{5}{\sqrt{33}} \left( \frac{2}{\sqrt{33}}, \frac{5}{\sqrt{33}}, \frac{-2}{\sqrt{33}} \right) \\[5pt] &= \left( \frac{10}{33}, \frac{25}{33}, \frac{-10}{33} \right) \end{align} 3 Calculate the scalar projection of vector $\vec{b} = (1, 0, 1)$ on vector $\vec{a} = (1, 1, -1),$ and explain the result. Solution First calculate the length of $\vec{a}$: $$|\vec{a}| = \sqrt{1 + 1 + 1} = \sqrt{3}$$ Now the scalar projection is \begin{align} \frac{\vec{a}}{|\vec{a}|} \cdot \vec{b} &= \left( \frac{1}{\sqrt{3}}, \frac{1}{\sqrt{3}}, \frac{-1}{\sqrt{3}} \right) \cdot (1, 0, 1) \\[5pt] &= \frac{1}{\sqrt{3}} + 0 - \frac{1}{\sqrt{3}} = 0 \end{align} The projection has a length of zero because vectors a and b are orthogonal. You can confirm this by calculating the dot product, which is zero. The "shadow" of vector b on vector a is a point, like the shadow of a pole in the noon-sun.

X

### Orthogonal

In two dimensions, orthogonal means perpendicular. But when we proceed to three or more dimensions, "perpendicular" isn't good enough. In 3-D a line and a plane can be perpendicular when viewed from one direction, but not perpendicular when viewed from an angle 90˚ away on the plane. The word orthogonal means perpendicular in every conceivable direction, no matter how many dimensions.  xaktly.com by Dr. Jeff Cruzan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. © 2012, Jeff Cruzan. All text and images on this website not specifically attributed to another source were created by me and I reserve all rights as to their use. Any opinions expressed on this website are entirely mine, and do not necessarily reflect the views of any of my employers. Please feel free to send any questions or comments to jeff.cruzan@verizon.net.