This is a generalisation of Pythagoras’ theorem \(a^2 + b^2 = c^2\) to apply to all triangles rather than just right angled ones. The cosine rule reduces to Pythagoras’ Theorem as \(\cos 90 = 0\) (this will come in handy in a bit). As well as providing the mathematical basis behind the usefulness of the dot product for establishing the extent to which two vectors are going in the same direction.
The cosine rule allows you to work out the length of the third side of any triangle providing you know the length of the other two sides and the angle at which they join.
So for this arbitrary triangle
Which gives us:
You can check this by drawing the triangle.
Going back to vectors we know that the difference between \(a\) and \(b\) is \(a-b\) so \(c^2\) is \(|a-b|^2\)2
We know that \(|a-b|^2\) is the dot product of (a-b) with itself: \((a-b)^T.(a-b)\). If we multiply that out we get:
That looks familiar doesn’t it?
Lets substitute that into the cosine rule:
This can be simplified:
Multipling through by -1 to get rid of the negative leaves us with:
What we’ve just shown is that the dot product tells us the extent to which the vectors we’re considering go in the same direction. This is because:
So positive products tell us the vectors are going in the same direction, negative products tell us they’re going in opposite directions and 0 tells us that they are orthogonal (at 90 degrees to one another). It is because of this property that we can use the dot product of a vector with itself to ascertain it’s magnitude.