We now know how to find out whether two vectors are
orthogonal
or
parallel.
Another interesting piece of information we might want to gather from two vectors is
the exact angle they enclose. Of course, if a vector is orthogonal to another,
they’re at a 90∘ angle. If they’re parallel, they enclose an angle of
0∘. But what if they are neither?
From trigonometry, we recall the law of cosines
c2=a2+b2−2abcos(γ),
where a, b and c are the sides of an arbitrary triangle and γ is the angle
between the sides a and b (or simply the angle at the corner C).
This can be used to derive a formula for vectors. If you would like a derivation of
the law of cosines starting from the Pythagorean Theorem, it can be found
here.
Keep this figure in mind:
We are trying to find the angle θ.
The law of cosines can be applied to this scenario as follows:
Therefore, to find the cosine of the angle between two vectors v and w,
you can use the formula
cosθ=∥v∥∥w∥v⋅w.
You can use the arccos function (sometimes referred to as cos−1) to find
the actual angle θ.
This idea extends to any number of dimensions.
NOTE: The formula shown only applies when none of the two vectors involved is a
zero vector. The division by
∥v∥∥w∥ would be undefined if either of the two
vectors have a length of 0, since you cannot divide by 0. It also would not make sense,
since the zero vector has no direction. So how do you find the angle between two vectors
if one of them has no direction?
A Remark About the Dot Product
As seen in the formula, the dot product tells you how “aligned” two vectors are.
As you have learned in a previous lesson
(orthogonal vectors),
when two vectors are orthogonal to one another, their
dot product
is 0. For a fixed vector length, the bigger the dot product,
the closer the vectors are to being parallel.
If it equals 0, they’re as unaligned as they could possibly be (orthogonal).
Looking at the sign of the dot product, you can also find out whether the angle
between the two vectors is acute (<90∘), or obtuse (>90∘):