# How do I calculate the angle between two vectors?

Aug 29, 2014

You can use the dot product to solve this problem. See http://en.wikipedia.org/wiki/Dot_product

The dot product is an operation on two vectors. There are two different definitions of dot product. Let $\setminus \vec{A} = \left[{A}_{1} , {A}_{2} , \ldots , {A}_{n}\right]$ be a vector and $\setminus \vec{B} = \left[{B}_{1} , {B}_{2} , \ldots , {B}_{n}\right]$ be another vector, then we have 2 formulas for dot product:

1) Algebraic definition:

$\setminus \vec{A} \setminus \cdot \setminus \vec{B} = \setminus {\sum}_{1}^{n} {A}_{i} {B}_{i} = {A}_{1} {B}_{1} + {A}_{2} {B}_{2} + \ldots + {A}_{n} {B}_{n}$

2) Geometric definition:

$\setminus \vec{A} \setminus \cdot \setminus \vec{B} = | | \setminus \vec{A} | | \setminus | | \setminus \vec{B} | | \setminus \cos \left(\setminus \theta\right)$

where $\setminus \theta$ is the angle between $\setminus \vec{A}$ and $\setminus \vec{B}$, and $| | \setminus \vec{A} | |$ denotes the magnitude of $\setminus \vec{A}$ and has the formula:

$| | \setminus \vec{A} | | = \setminus \sqrt{{A}_{1}^{2} + {A}_{2}^{2} + \ldots + {A}_{n}^{2}}$

We can solve many questions (such as the angle between two vectors) by combining the two definitions:

$\setminus {\sum}_{1}^{n} {A}_{i} {B}_{i} = | | \setminus \vec{A} | | \setminus | | \setminus \vec{B} | | \setminus \cos \left(\setminus \theta\right)$

or

${A}_{1} {B}_{1} + {A}_{2} {B}_{2} + \ldots + {A}_{n} {B}_{n} = \left(\setminus \sqrt{{A}_{1}^{2} + {A}_{2}^{2} + \ldots + {A}_{n}^{2}}\right) \left(\setminus \sqrt{{B}_{1}^{2} + {B}_{2}^{2} + \ldots + {B}_{n}^{2}}\right) \setminus \cos \left(\setminus \theta\right)$

If we have two vectors, then the only unknown is $\setminus \theta$ in the above equation, and thus we can solve for $\setminus \theta$, which is the angle between the two vectors.

Example:

Q: Given $\setminus \vec{A} = \left[2 , 5 , 1\right]$, $\setminus \vec{B} = \left[9 , - 3 , 6\right]$, find the angle between them.

A:
From the question, we see that each vector has three dimensions. From above, our formula becomes:

${A}_{1} {B}_{1} + {A}_{2} {B}_{2} + {A}_{3} {B}_{3} = \left(\setminus \sqrt{{A}_{1}^{2} + {A}_{2}^{2} + {A}_{3}^{2}}\right) \left(\setminus \sqrt{{B}_{1}^{2} + {B}_{2}^{2} + {B}_{3}^{2}}\right) \setminus \cos \left(\setminus \theta\right)$

Left side:

${A}_{1} {B}_{1} + {A}_{2} {B}_{2} + {A}_{3} {B}_{3} = \left(2\right) \left(9\right) + \left(5\right) \left(- 3\right) + \left(1\right) \left(6\right) = 9$

Right side:

$| | \setminus \vec{A} | | = \setminus \sqrt{{A}_{1}^{2} + {A}_{2}^{2} + {A}_{3}^{2}} = \setminus \sqrt{{2}^{2} + {5}^{2} + {1}^{2}} = \setminus \sqrt{30}$
$| | \setminus \vec{B} | | = \setminus \sqrt{{B}_{1}^{2} + {B}_{2}^{2} + {B}_{3}^{2}} = \setminus \sqrt{{9}^{2} + {\left(- 3\right)}^{2} + {6}^{2}} = \setminus \sqrt{126}$
$\setminus \theta$ is unknown

Plug everything into the formula, we get:

$9 = \left(\setminus \sqrt{30}\right) \left(\setminus \sqrt{126}\right) \setminus \cos \left(\setminus \theta\right)$

Solve for $\setminus \theta$:

\cos(\theta) = \frac(9)((\sqrt(30))(\sqrt(126))
$\setminus \theta = \setminus {\cos}^{-} 1 \left(\setminus \frac{9}{\left(\setminus \sqrt{30}\right) \left(\setminus \sqrt{126}\right)}\right)$

Using a calculator, we get:

$\setminus \theta = 81.58$ degrees

See the following video of ...