The angle between two vectors
The ship flies along the vector 1, 2, and a beacon lies in the direction the vector 3, 1. How many degrees must it turn to head for the beacon?
The formula
For two vectors u and w, the dot product is |u| · |w| · cos v, as in The dot product. Dividing by the lengths gives cos v alone:
cos v = (u · w) / (|u| · |w|)
For the ship:
Working it out
On top, 1 times 3 plus 2 times 1 is 5. Below, the lengths are the square root of 5 and the square root of 10:
The roots multiply to one root, the square root of 50, which is 5 the square root of 2. The 5s cancel, and that leaves 1 over the square root of 2, which is also the square root of 2 over 2.
Reading off the angle
1 over the square root of 2 is one of the exact values of cos, from Exact values: cos 45° is the square root of 2 over 2. So the ship turns 45°.
The angle between two vectors is always from 0° to 180°, and the sign of cos decides which half:
- cosine of v equals 1 over 2 gives 60°, and cosine of v equals minus 1 over 2 gives 120°,
- cosine of v equals the square root of 3 over 2 gives 30°, and cosine of v equals minus the square root of 3 over 2 gives 150°,
- cosine of v equals 0 gives 90°.
Mind which is which: sin 30° is 1 over 2 as well, but the angle where cos is 1 over 2 is 60°. The app asks for the angle in degrees; in radians, 45° would be pi over 4.
cos v is the dot product divided by the two lengths. Simplify it to an exact value, and read off the angle between 0° and 180°.