ELIAS EBNER

  • Home
  • Blog
  • Courses
  • About

Linear Algebra

  1. Vectors
    1. Scalars
    2. Vectors vs Sets
    3. Addition and Subtraction
    4. Scalar Multiplication
    5. Zero Vectors
    6. Linear Combinations
    7. Real Dot Product
    8. Length of a Vector
    9. Orthogonal Vectors
    10. Parallel Vectors
    11. Angle Between Vectors
    12. Unit Vectors
  2. Matrices
    1. Notation
    2. Indexing
    3. Submatrices
    4. Matrix-by-Vector Product
    5. Addition and Subtraction
    6. Scalar Multiplication
    7. Transpose
    8. Symmetries
    9. Matrix Multiplication
    10. Identity Matrix
    11. Non-Negative Integer Powers
    12. Reverse Order Law of Transposition
  3. Linear Systems
    1. Inverse Matrices
    2. Singular Matrices
    3. Linear Dependence
    4. Solutions
  4. Planes
    1. Vector Cross Product
  5. Gaussian Elimination
Linear Algebra ›Vectors ›Angle Between Vectors

Finding the Angle Between Two Vectors

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∘90^\circ90∘ angle. If they’re parallel, they enclose an angle of 0∘0^\circ0∘. But what if they are neither?

From trigonometry, we recall the law of cosines

c2=a2+b2−2abcos⁡(γ),c^2 = a^2 + b^2 - 2ab\cos(\gamma),c2=a2+b2−2abcos(γ),

where aaa, bbb and ccc are the sides of an arbitrary triangle and γ\gammaγ is the angle between the sides aaa and bbb (or simply the angle at the corner CCC).

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 θ\thetaθ.

The law of cosines can be applied to this scenario as follows:

∥v⃗−w⃗∥2=∥v⃗∥2+∥w⃗∥2−2∥v⃗∥∥w⃗∥cos⁡θ.\lVert \vec{v} - \vec{w} \rVert^2 = \lVert \vec{v} \rVert^2 + \lVert \vec{w} \rVert^2 - 2 \lVert \vec{v} \rVert \lVert \vec{w} \rVert \cos \theta.∥v−w∥2=∥v∥2+∥w∥2−2∥v∥∥w∥cosθ.

Therefore, we can conclude that

cos⁡θ=∥v⃗∥2+∥w⃗∥2−∥v⃗−w⃗∥22∥v⃗∥∥w⃗∥=v⃗⋅v⃗+w⃗⋅w⃗−(v⃗−w⃗)⋅(v⃗−w⃗)2∥v⃗∥∥w⃗∥=v⃗⋅v⃗+w⃗⋅w⃗−v⃗⋅v⃗+2v⃗⋅w⃗−w⃗⋅w⃗2∥v⃗∥∥w⃗∥=v⃗⋅w⃗∥v⃗∥∥w⃗∥.\begin{align*} \cos \theta &= \dfrac{ \lVert \vec{v} \rVert^2 + \lVert \vec{w} \rVert^2 - \lVert \vec{v} - \vec{w} \rVert^2 }{ 2 \lVert \vec{v} \rVert \lVert \vec{w} \rVert } \\[1em] &= \dfrac{ \vec{v} \cdot \vec{v} + \vec{w} \cdot \vec{w} - (\vec{v} - \vec{w}) \cdot (\vec{v} - \vec{w}) }{ 2 \lVert \vec{v} \rVert \lVert \vec{w} \rVert } \\[1em] &= \dfrac{ \vec{v} \cdot \vec{v} + \vec{w} \cdot \vec{w} - \vec{v} \cdot \vec{v} + 2\vec{v} \cdot \vec{w} - \vec{w} \cdot \vec{w} }{ 2 \lVert \vec{v} \rVert \lVert \vec{w} \rVert } \\[1em] &= \dfrac{ \vec{v} \cdot \vec{w} }{ \lVert \vec{v} \rVert \lVert \vec{w} \rVert }. \\[1em] \end{align*}cosθ​=2∥v∥∥w∥∥v∥2+∥w∥2−∥v−w∥2​=2∥v∥∥w∥v⋅v+w⋅w−(v−w)⋅(v−w)​=2∥v∥∥w∥v⋅v+w⋅w−v⋅v+2v⋅w−w⋅w​=∥v∥∥w∥v⋅w​.​

Therefore, to find the cosine of the angle between two vectors v⃗\vec{v}v and w⃗\vec{w}w, you can use the formula

cos⁡θ=v⃗⋅w⃗∥v⃗∥∥w⃗∥.\cos \theta = \dfrac{\vec{v} \cdot \vec{w}}{\lVert \vec{v} \rVert \lVert \vec{w} \rVert}.cosθ=∥v∥∥w∥v⋅w​.

You can use the arccos⁡\arccosarccos function (sometimes referred to as cos⁡−1\cos^{-1}cos−1) to find the actual angle θ\thetaθ.

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⃗∥\lVert \vec{v} \rVert \lVert \vec{w} \rVert∥v∥∥w∥ would be undefined if either of the two vectors have a length of 000, since you cannot divide by 000. 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 000. For a fixed vector length, the bigger the dot product, the closer the vectors are to being parallel. If it equals 000, 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∘\lt 90^\circ<90∘), or obtuse (>90∘\gt 90^\circ>90∘):

  • v⃗⋅w⃗>0  ⟹  θ<90∘\vec{v} \cdot \vec{w} \gt 0 \implies \theta \lt 90^\circv⋅w>0⟹θ<90∘
  • v⃗⋅w⃗=0  ⟹  θ=90∘\vec{v} \cdot \vec{w} = 0 \implies \theta = 90^\circv⋅w=0⟹θ=90∘
  • v⃗⋅w⃗<0  ⟹  θ>90∘\vec{v} \cdot \vec{w} \lt 0 \implies \theta \gt 90^\circv⋅w<0⟹θ>90∘

Example

We compute the angle between these two vectors

v⃗=[35],w⃗=[−27].\vec{v} = \begin{bmatrix} 3 \\ 5 \end{bmatrix}, \vec{w} = \begin{bmatrix} -2 \\ 7 \end{bmatrix}.v=[35​],w=[−27​].

We use the formula found above:

cos⁡θ=[35]⋅[−27]∥[35]∥∥[−27]∥=3⋅(−2)+5⋅73⋅3+5⋅5⋅(−2)⋅(−2)+7⋅7=2934⋅53≈2942.45≈0.683.\begin{align*} \cos \theta &= \dfrac{ \begin{bmatrix} 3 \\ 5 \end{bmatrix} \cdot \begin{bmatrix} -2 \\ 7 \end{bmatrix} }{ \left\lVert \begin{bmatrix} 3 \\ 5 \end{bmatrix} \right\rVert \left\lVert \begin{bmatrix} -2 \\ 7 \end{bmatrix} \right\rVert } \\[1em] &= \dfrac{ 3 \cdot (-2) + 5 \cdot 7 }{ \sqrt{3 \cdot 3 + 5 \cdot 5} \cdot \sqrt{(-2) \cdot (-2) + 7 \cdot 7} } \\[1em] &= \dfrac{ 29 }{ \sqrt{34} \cdot \sqrt {53} } \\[1em] &\approx \dfrac{ 29 }{ 42.45 } \\[1em] &\approx 0.683. \end{align*}cosθ​=​[35​]​​[−27​]​[35​]⋅[−27​]​=3⋅3+5⋅5​⋅(−2)⋅(−2)+7⋅7​3⋅(−2)+5⋅7​=34​⋅53​29​≈42.4529​≈0.683.​

We can now compute the inverse of the cos⁡\coscos function to find the angle:

arccos⁡(0.683)≈46.91∘\arccos(0.683) \approx 46.91^\circarccos(0.683)≈46.91∘

So the angle between the two vectors is approximately 46.91∘46.91^\circ46.91∘.

Previous
Determining Whether Two Vectors Are Parallel
Next
Unit Vectors
This website does not collect personal data, does not use cookies, and does not perform any tracking.