# Projections

One of the most useful applications of the dot product is the idea of a projection. A projection is an operation that allows us to determine, given two vectors, $\vec{x}$ and $\vec{y}$, how much the vector $\vec{x}$ is in the direction of $\vec{y}$.

Suppose that we have two vectors, $\vec{x}$ and $\vec{y}$, that exist in some arbitrary direction in $\mathbb{R}^2$.

If we wanted to determine how much $\vec{y}$ points in the direction of $\vec{x}$, we first need to extend $\vec{y}$ to match the length of $\vec{x}$. Once we have done this, we can draw a line directly perpendicular to $\vec{y}$ connecting it to $\vec{x}$, creating a right triangle.

This gives us a picture of what a projection looks like from a geometric point of view. From here, we can derive a formula to calculate the projection. In order to extend $\vec{x}$ to reach $\vec{y}$, we can utilize the dot product, and then divide by the length of the vector to keep it to a unit size. From here, we can apply the scalar to vector $\vec{y}$, and end up with a vector that is the length of $\vec{x}$, in the direction of $\vec{y}$.

The actual formula for the projection is the following: $proj_{\vec{x}}\vec{y} = \frac{\vec{x}*\vec{y}}{|\vec{x}|^2} * \vec{x}$

**Example: **Determine the value of $proj_{\vec{x}}\vec{y}$ where $\vec{x} = \left[\begin{array}{cc} 4 & 3 & -1 \end{array}\right]$ and $\vec{y} = \left[\begin{array}{cc} -2 & 5 & 3 \end{array}\right]$

We can easily solve this problem just by substituting in the appropriate values for the projection equation.

$proj_{\vec{x}}\vec{y} = \frac{\vec{x}*\vec{y}}{|\vec{x}|^2} * \vec{x} = \frac{\left[\begin{array}{cc} 4 & 3 & -1 \end{array}\right] * \left[\begin{array}{cc} -2 & 5 & 3 \end{array}\right]}{\sqrt{4^2+3^2+(-1)^2)}}*\left[\begin{array}{cc} 4 & 3 & -1 \end{array}\right]$

$= \frac{4}{26} * \left[\begin{array}{cc} 4 & 3 & -1 \end{array}\right] = \left[\begin{array}{cc} \frac{16}{26} & \frac{12}{26} & \frac{-4}{26} \end{array}\right]$

Often, you may also want to find a vector that is perpendicular to the vector $\vec{x}$. To do this, we can use a projection, as calculated above, to determine the projection of $\vec{y}$ which is perpendicular to $\vec{x}$.

The reason we want to be able to do this mostly stems from Physics applications. In Physics, we often want to componentize forces which can be done with projections. From here, we may want to find a force that acts perpendicular to vector, which we will show how to calculate now.

If we want to find the projection of $\vec{y}$ perpendicular to $\vec{x}$, we can use the formula $perp_{\vec{x}}\vec{y} = \vec{y} - proj_{\vec{x}}\vec{y}$. To get an intuition of why this works, consider what exactly we get when we calculate the projection of $\vec{y}$ onto $\vec{x}$. We get a vector that is the length of $\vec{x}$, in the same direction as $\vec{y}$. If we subtract the vector $\vec{y}$ from the projection, we would end up with a vector perpendicular to the projection.

One further application of projections is to be able to find the minimum distance from a line to a given point. The shortest line between any line and a point is a line that is perpendicular to the line. Due to this, we can apply the perp operation to be able to find such a value.

**Example: **Find the distance from Q(4,3) to the line $\vec{x} = \left[\begin{array}{cc} 1 & 2 \end{array}\right] + t \left[\begin{array}{cc} -1 & 1 \end{array}\right]$

First, we are going to draw a line between Q and a point on $\vec{x}$, which we will call P. The easiest point to use is the y-intercept, which is $\left[\begin{array}{cc} 1 & 2 \end{array}\right]$. This would give us $PQ = \left[\begin{array}{cc} 4-1 & 3-2 \end{array}\right] = \left[\begin{array}{cc} 3 & 1 \end{array}\right]$.

From here, we can find the projection that is perpendicular to PQ.

$perp_d PQ = PQ - proj_d PQ = \left[\begin{array}{cc} 3 & 1 \end{array}\right] - \frac{-2}{2} \left[\begin{array}{cc} -1 & 1 \end{array}\right] = \left[\begin{array}{cc} 2 & 2 \end{array}\right]$

What we have learned from this is that the vector $\left[\begin{array}{cc} 2 & 2 \end{array}\right]$ is the vector with the shortest distance from the line $\vec{x}$ to the point Q. We can find that distance by taking the magnitue of the vector, which is equal to $2*\sqrt{2}$