2 of 2
replaced http://stackoverflow.com/ with https://stackoverflow.com/
See https://stackoverflow.com/a/21486462/380384
Or follow these steps
- Create two vectors $A=(S-E)$ and $B=(W-E)$
- Calculate the dot product $$\cos\theta = A\cdot B = A_x B_x + A_z B_z$$
- Calculate the magnitude of the cross product $$\sin\theta = |A \times B| = A_x B_y - A_y B_x $$
- Use the ATAN2() function to get the included angle $$\theta = {\rm atan2}(\sin \theta, \cos \theta)$$
- Get the desired angle by $\pi - \theta$
John Alexiou
- 14.8k
- 1
- 41
- 78