# Angle between two points on a sphere

Suppose I am standing at point $A$ on Earth (a 3D sphere of a known radius) and suppose $B$ is another point a few miles away. The longitude and latitude of points $A$ and $B$ are $(\lambda_1,\varphi_1)$ and $(\lambda_2,\varphi_2)$ respectively. What is the angle from $A$ to $B$? In other words, If I was holding a compass whose needle points north while standing at point $A$, at what angle will point $B$ be?

• What have you attempted towards solving the problem? – Parcly Taxel Mar 13 '18 at 3:17
• To do this correctly, you need to use the trigonometry of spherical triangles. If the cities are very close to each other, however, you can ignore the curvature of the Earth and do plane geometry. But never forget that a degree of latitude and a degree of longitude are equal only at the equator: towards the poles, a degree of longitude is smaller. – Lubin Mar 13 '18 at 3:33
• @Lubin You can use the Mercator projection to solve this also. – Parcly Taxel Mar 13 '18 at 3:41
• @ParclyTaxel, that’s not right at all: consider two cities at the same latitude, but moderately far from each other. You see that the great-circle path heads towards the pole, in other words, the angle between due North and the “line” towards the other city will always be acute. But Mercator tells you to head due East (or West). – Lubin Mar 13 '18 at 12:48

There are two laws of cosines for spherical triangles: \begin{align}\cos a&=\cos b\cos c+\sin b\sin c\cos A\\ \cos A&=-\cos B\cos C+\sin B\sin C\cos a\end{align} Where $A$, $B$, and $C$ are the angles of the spherical triangle and $a$, $b$, and $c$ are the opposite side. Here you know one angle and two sides of the spherical triangle with vertices at the cities and the north pole: \begin{align}b=\frac{\pi}2-\phi_1,&&c=\frac{\pi}2-\phi_2,&&\text{and}\quad A=\lambda_2-\lambda_1\end{align} So you can apply the first of the two laws to get $$\cos a=\sin\phi_1\sin\phi_2+\cos\phi_1\cos\phi_2\cos(\lambda_2-\lambda_1)$$ Then the distance between the two cities is $Ra$, where $R$ is the radius of the earth and $a$ is the angle we just computed in radians. Oh, but you wanted the bearing. There is also a law of sines: $$\frac{\sin A}{\sin a}=\frac{\sin B}{\sin b}=\frac{\sin C}{\sin c}$$ So we can now get $$\sin C=\frac{\sin A\sin c}{\sin a}$$ And $C$ is the bearing from city $1$ to city $2$ measured east of north.