Given latitude and longitude and facing north, how can I calculate the rotation needed to face another latitude and longitude (namely 0,0)?

60 Views Asked by At

As the title says, given I'm somewhere on earth facing north, I can determine the magnitude of the distance to get to 0°,0°, but I am not sure how to calculate the rotation needed to be facing 0°,0°.

For what it's worth: Assuming 0°,0° is the other point, the magnitude is calculated as: $Radius Of The Earth$ * $\arccos$ ( $\cos$ ($latitude$) * $\cos$ ($longitude$) )

From here: https://en.wikipedia.org/wiki/Great-circle_distance#:~:text=.%5B1%5D-,Formulae,-%5Bedit%5D

1

There are 1 best solutions below

2
On BEST ANSWER

Since we're talking about angles, the radius of Earth doesn't matter, and we can take it as $1$. The coordinates in $(x,y,z)$ of a point on Earth, assumed a sphere centered at the origin $(0,0,0)$ and with radius $1$ are given by

$ P = (\cos \theta \cos \phi, \cos \theta \sin \phi, \sin \theta ) $

You are at $P_1 = (\cos \theta_1 \cos \phi_1, \cos \theta_1 \sin \phi_1, \sin \theta_1) $ where $ \theta_1$ is your latitude and $\phi_1$ is your longitude, and $ -90^\circ \le \theta_1 \le 90^\circ$ and $ -180^\circ \le \phi \le 180^\circ $.

The local north at your location is

$ N = ( - \sin \theta_1 \cos \phi_1, - \sin \theta_1 \sin \phi_1, \cos \theta_1) $

and the local east is

$ E = ( - \sin \phi_1 , \cos \phi_1 , 0 ) $

Your final direction is a combination of these two directions, and since your initially facing north, and assuming the angle of rotation is $\phi$, then you final direction will be

$ V = \cos \phi N + \sin \phi E $

If this vector is pointing towards the point

$ Q = (\cos 0^\circ \cos 0^\circ, \cos 0^\circ \sin 0^\circ, \sin 0^\circ) = (1, 0, 0) $

Then the vector $V$ lies in the plane whose normal vector is $ P_1 \times Q $

which means the vector $V$ is orthogonal to $P_1 \times Q $

Now,

$W = P_1 \times Q = (\cos \theta_1 \cos \phi_1, \cos \theta_1 \sin \phi_1, \sin \theta_1) \times (1, 0, 0) = (0, \sin \theta_1 , - \cos \theta_1 \sin \phi_1 ) $

And since we want $ V \cdot (P_1 \times Q) = 0 $, then this means that

$ \cos \phi (N \cdot W) + \sin \phi (E \cdot W) = 0 $

The solution of this trigonometric equation will give two values for $\phi$ that are separated by $180^\circ$.

As an example, suppose that you are at latitude $45^\circ$, and longitude $-75^\circ$ (i.e. $45^\circ$ North, and $75^\circ$ West). Then

$ W = (0, 0.7071, 0.683 ) $

while

$ N = ( - \sin \theta_1 \cos \phi_1, - \sin \theta_1 \sin \phi_1, \cos \theta_1) = (-0.183, 0.683, 0.7071)$

and the local east is

$ E = ( - \sin \phi_1 , \cos \phi_1 , 0 ) = (0.9659, 0.2588,0)$

Hence,

$ W \cdot N = 0.9659 $

$ W \cdot E = 0.183 $

Hence, the trigonometric equation to solve is

$ 0.9659 \cos \phi + 0.183 \sin \phi = 0 $

From which

$ \tan \phi = - \dfrac{0.9659}{0.183} = -5.278$

Therefore, $\phi = -79.272^\circ $ or $ \phi = 100.728 $

Remember that $\phi$ is a clockwise rotation (from north through east).

But only one value of $\phi$ is correct. To choose the correct one, we have to ensure our direction $ V $ makes an acute angle with $ Q - P_1$.

Now

$ Q - P_1 = (1, 0, 0) - (0.25882, -0.683, 0.7071) = (0.74118, 0.683, -0.7071) $

And with $\phi = -79.272 $ our vector $V$ is

$ V = \cos(-79.272) (-0.183, 0.683, 0.7071) + \sin(-79.272) (0.9659, 0.2588,0) \\= (-0.9831, -0.12714, 0.13162) $

So

$ (Q - P_1) \cdot V = -0.90856 \lt 0 $

So $-79.272$ is not the correct value of $\phi$.

With $ \phi = 100.728$, our vector $V$ is

$ V = \cos(100.728) (-0.183, 0.683, 0.7071) + \sin(100.728) (0.9659, 0.2588, 0) \\= (0.9831, 0.12714, -0.131620 ) $

And

$ (Q - P_1) \cdot V = 0.90856 \gt 0 $

So $100.728$ is the correct value of $\phi$.

Note that you don't have to do the calculations for $V$ twice (i.e. for both $\phi$'s), do the calculation for only one of the two values of $\phi$, if the dot product with $Q- P_1$ is positive then this is your $\phi$, otherwise, the correct $\phi$ is the other value.