The dot product of two vectors is equal to the cosine of the angle between them divided by the vectors' magnitudes. For example:
The dot product of <1, 2> and <3, 4> is 1*3 + 2*4, i.e. 11. The magnitudes of the vectors are sqrt(1*1+2*2) and sqrt(3*3+4*4), i.e. sqrt(5) and sqrt(25).
So the cosine of the angle between the vectors is 11 / (sqrt(5)*sqrt(25)), i.e. 11 / (sqrt(5) * 5).
If we take the arccosine of that value, we get the angle:
acos(11/(sqrt(5)*5)).
So in general, the angle between two vectors u and v is
acos(dot(u, v) / sqrt(dot(u, u) * dot(v, v))),
where dot is the dot product function.
(It happens that the magnitude of a vector v can be written as sqrt(dot(v, v)).)
And if you haven't figured it out, the dot product of two vectors is the sum of the products of their constituent parts: <x,y,z> `dot` <x', y', z'> = x*x' + y*y' + z*z'. This works for any number of dimensions.
Reputation Points: 1133
Solved Threads: 171
Super Senior Demiposter
Online 2,478 posts
since Jun 2005