
Calculate the Distance Between Points on the Earth’s Surface #27
Chapter 3, Mapping Your World
|
117
HACK
theorem to triangles that lack a right angle. The Law of Cosines for spheri-
cal trigonometry states that:
cos c = cos a cos b + sin a sin b cos C
In this relation, C is the angle between edges a and b on a “triangle” con-
necting three points on a spherical surface. If we place the third vertex of our
spherical triangle at the North Pole, then the edges a and b, which connect
our two points to the third vertex, can be measured in units of latitude, and
angle C conveniently becomes the difference in longitude between them.
Figure 3-15 depicts this relationship, using the great circle between Lagos,
Nigeria, and San Francisco, California. We can then apply the inverse cosine
function to the Law of Cosines to get the length of edge c, which is the dis-
tance between our two original points:
c = cos
-1
( cos(90 - lat1) cos(90 - lat2)
+ sin(90 - lat1) sin(90 - lat2) cos(lon2 - lon1) )
The Code
However, our work is not quite done yet. For starters, most computational
implementations of trigonometric functions take arguments measured in
radians, not degrees. (Degrees can be converted to radians by multiplying by
π⁄
180.) Also, the result c is returned in radians (i.e., a proportion of the
Figure 3-15. The Law of Cosines, exemplified with the great circle connecting San
Francisco and Lagos