ARTICLES

# The Angle Between Two Vectors

Let’s take two vectors \(\vec{a}\) and \(\vec{b}\) on the 2D plane and an orthonormal basis \((\vec{i}, \vec{j})\); we denote \(\mathcal{C}\) the application that maps a vertex to its coordinates. For some \(a, \alpha, b, \beta\) it must be true that:

$$
\mathcal{C}(\vec{a}) = [x_a, y_a] = [a~cos(\alpha), a~sin(\alpha)]
\\

\mathcal{C}(\vec{b}) = [x_b, y_b] = [b~cos(\beta), b~sin(\beta)]
$$

#### The sine of the oriented angle

Now let us consider the *oriented* angle between \(\vec{a}\) and \(\vec{b}\); this is equal to \(\beta - \alpha\). The sine of such angle can be obtained using the trigonometric addition formulas:

$$ sin(\beta - \alpha) = sin(\beta) cos(-\alpha) + cos(\beta) sin(-\alpha) = $$

$$ = sin(\beta) cos(\alpha) - cos(\beta) sin(\alpha) = $$

$$ = \frac{y_b}{b}\frac{x_a}{a} - \frac{x_b}{b}\frac{y_a}{a} = \frac{y_b x_a - x_b y_a}{a b} $$

Remembering the definition of the determinant for a 2x2 matrix, we have:

$$ sin(\beta - \alpha) = \frac{det(\begin{bmatrix} x_a & y_a \\ x_b & y_b \end{bmatrix})}{ab} $$

In particular, if the two vectors are both unit length then \(a = b = 1\) and the sine of the oriented angle from \(\vec{a}\) to \(\vec{b}\) is exactly:

$$ det(\begin{bmatrix} x_a & y_a \\ x_b & y_b \end{bmatrix}) $$

However, even when the vectors are not unit length, the determinant formula is still very useful because the *sign of the determinant tells whether the turn if clockwise or counter-clockwise*.

In a right-handed coordinate system a positive sign for the determinant denotes a counter-clockwise rotation, while a negative sign denotes a clockwise one; if the coordinate system is left-handed, then positive means clockwise and negative is counter-clockwise.

#### The cosine of the oriented angle

What about the cosine of the angle between the two vectors? Again, using the addition formulas we can write:

$$ cos(\beta - \alpha) = cos(\beta) cos(-\alpha) - sin(\beta) sin(-\alpha) = $$

$$ = cos(\beta) cos(\alpha) - sin(\beta) (-1) sin(\alpha) = $$

$$ = cos(\beta) cos(\alpha) + sin(\beta) sin(\alpha) = \frac{x_a}{a} \frac{x_b}{b} + \frac{y_a}{a} \frac{y_b}{b} $$

Remembering the definition of the dot product in \(\mathbb{R}^2\), we have:

$$ cos(\beta - \alpha) = \frac{[x_a, y_a] \cdot [x_b, y_b]}{ab} $$

In particular, if the two vectors are both unit length then \(a = b = 1\) and the cosine of the angle from \(\vec{a}\) to \(\vec{b}\) is exactly:

$$ [x_a, y_a] \cdot [x_b, y_b] $$

However, even when the vectors are not unit length, the dot product formula is still very useful because the dot product will be zero when the *vectors are perpendicular to each other*. The dot product makes it really easy to check for perpendicularity.

#### What about 3D vectors?

In a separate article we will show how the cosine formula extends very easily to 3D, while for the sine formula we will need some adjustement that ultimately will result in the definition of the *cross product*.