## Given the latitudes and longitudes of two places on earth, what is the
(great circle) distance between them?

- The earth is (generally close
enough to) a sphere, radius R; define the (surface) distance we seek as D.
- D=R
*a* where *a* is
the angle (in radians, or in degrees*(2Pi/360)) between vectors *R*_{1}
and *R*_{2} from the center of the earth to the two
points.
- Since the dot product
*R*_{1}.R_{2}=R^{2}cos*a*,
we can write D=Rcos^{-1}(*R*_{1}.R_{2}/R^{2})
- Transform spherical to
rectilinear coordinates: (R,
*lat*,*long*)->(Rcos(*lat*)cos(*long*),Rcos(*lat*)sin(*long*),Rsin(*lat*)).
- So
*R*_{1}.R_{2}/R^{2}=cos(*lat*_{1})cos(*long*_{1})cos(*lat*_{2})cos(*long*_{2})+cos(*lat*_{1})sin(*long*_{1})cos(*lat*_{2})sin(*long*_{2})+sin(*lat*_{1})sin(*lat*_{2}).
- D=R cos
^{-1}(cos(*lat*_{1})cos(*long*_{1})cos(*lat*_{2})cos(*long*_{2})+cos(*lat*_{1})sin(*long*_{1})cos(*lat*_{2})sin(*long*_{2})+sin(*lat*_{1})sin(*lat*_{2})).
- D=R
cos
^{-1}(cos(*long*_{1}-*long*_{2})cos(*lat*_{1})cos(*lat*_{2})+sin(*lat*_{1})sin(*lat*_{2})).
- Sanity check: On the equator
(both latitudes zero) this says D=R(
*long*_{1}*-long*_{2})
as expected.
- Sanity check: When the two
longitudes are equal this says D=R(
*lat*_{1}*-lat*_{2})
as expected.