Air distance

In the last post a proof of the spherical law of cosines was made.

For the figure below, following equality holds:

$cos(a)cos(b) + sin(a)sin(b)cos(u) = cos(c)$   (***)

The earth is more like an ellipsoid but for computing the air distance with enough accuracy it is fine to consider it a sphere. Imagine that the earth is the sphere from the figure, $A'$ has the GPS coordinates $(x_A, y_A)$ and $B'$ has GPS coordinates $(x_B, y_B)$. All the coordinate are expressed in radians. Note that the angle $u$ is the difference between longitudes because $NA''$ and $NB''$ are meridians: $u=y_B-y_A$

The longitude of $A'$ will be $x_A=\frac{\pi}{2}-a$ and the $B'$ will be $x_B=\frac{\pi}{2}-b$.

It follows that we can substitute those values in (***) to find $c$:

$cos(c)=cos(a) \cdot cos(b) + sin(a) \cdot sin(b) \cdot cos(u)$ = $cos\left(\frac{\pi}{2}-x_A\right) \cdot cos\left(\frac{\pi}{2}-x_B\right) + sin\left(\frac{\pi}{2}-x_A\right) \cdot sin\left(\frac{\pi}{2}-x_B\right) \cdot cos(y_B-y_A)$ = $sin(x_A) \cdot sin(x_B) + cos(x_A) \cdot cos(x_B) \cdot cos(y_B-y_A)$

Having the $c$ angle, the length of the arc $A'B'$ can be computed by multiplying with the earth radius.

$s=R \cdot arccos(sin(x_A) \cdot sin(x_B) + cos(x_A) \cdot cos(x_B) \cdot cos(y_B-y_A))$

Note that this formula holds for sure if both $A'$ and $B'$ are in the north hemisphere and if the difference between longitudes is smaller than $\pi$. For other situations it may need some $\pm$ adjustments.