haversine

Embed Size (px)

Citation preview

  • 8/10/2019 haversine

    1/4

    Distance between Points on the Earths Surface

    Abstract

    During a casual conversation with one of my students, he asked me how one could go about computing the

    distance between two p oints on the surface of the Earth, in terms of their respective latitudes and longitudes.

    This is an interesting exercise in spherical coordinates, and relates to the so-called haversine.

    Spherical coordinates

    z=Rsin!

    y=Rcos!sin "x=Rcos!cos "

    R

    z

    y

    x

    !

    "

    Figure 1: Spherical Coordinates

    The calculation of the distance be-tween two points on the surface of theEarth proceeds in two stages: (1) to

    compute the straight-line Euclideandistance these two points (obtained byburrowing through the Earth), and (2)to convert this distance to one mea-sured along the surface of the Earth.Figure 1 depicts the spherical coor-

    dinates we shall use.1

    We orient thiscoordinate system so that

    (i) The origin is at the Earths center;

    (ii) Thex-axis passes through the Prime Meridian (0 longitude);

    (iii) The xy-plane contains the Earths equator (and so the positive z-axis willpass through the North Pole)

    Note that the angle is the measurement of lattitude, and the angle is themeasurement of longitude, where0

  • 8/10/2019 haversine

    2/4

    Thus, we assume that we are given two points P1 and P2 determined by theirrespective lattitude-longitude pairs: P1(1, 1), P2(2, 2). In cartesian coordi-nates we haveP1=P1(x1, y1, z1)andP2=P2(x2, y2, z2), wherex, y, andzaredetermined by the spherical coordinates through the familiar equations:

    x = R cos cos y = R cos sin

    z = R sin

    The Euclidean distanced betweenP1andP2is given by the three-dimensionalPythagorean theorem:

    d2 = (x1

    x2)2 + (y1

    y2)

    2 + (z1

    z2)2.

    The bulk of our work will be in computing this distance in terms of the sphericalcoordinates. Converting the cartesian coordinates to spherical coordinates, weget

    d2/R2 = (cos 1cos 1 cos 2cos 2)2+(cos 1sin 1 cos 2sin 2)2+(sin 1

    sin 2)

    2

    = cos2 1cos2 1 2cos 1cos 1cos 2cos 2+ cos2 2cos2 2+cos2 1sin

    2 1 2cos 1sin 1cos 2sin 2+ cos2 2sin2 2+sin2 1 2sin 1sin 2+ sin2 2

    = 2 2cos 1cos 2cos(1 2) 2sin 1sin 2

  • 8/10/2019 haversine

    3/4

    P2

    P1

    D

    !

    R

    d/2

    d/2

    R

    Figure 2: Arc Length

    Next in order to compute the distance Dalong the surface of the Earth, we need onlyanalyze Figure 2 in detail. Notice that D is thearc length along the indicated sector. From

    sin(/2) =

    d

    2R,we get

    sin = 2 sin(/2) cos(/2)

    = d

    R

    1

    d

    2R

    2

    = d

    2R24R2 d2.

    Therefore, in terms ofd and R, the distanceDis given by

    D=R = R sin1

    d

    2R2

    4R2 d2

    ,

    which, in principle, concludes this narrative.

    The distance is often represented in terms of the so-called haversinefunction,defined by

    haversin A = sin2A

    2

    =

    1

    cosA

    2 .

    This says that cos A= 1 2 haversin A.

    Returning to the formula fordabove, we continue, feeding in the new notation:

    d2/R2 = 2 2cos 1cos 2cos(1 2) 2sin 1sin 2= 2 2cos 1cos 2[1 2 haversin (1 2)] 2sin 1sin 2= 2 2cos(1 2) + 4 cos 1cos 2haversin (1 2)

    = 4 haversin (1 2) + 4 cos 1cos 2haversin (1 2)Which says that

    d

    2R

    2

    = haversin (1 2) + cos 1cos 2haversin (1 2),

  • 8/10/2019 haversine

    4/4

    and so

    haversin= haversin (1 2) + cos 1cos 2haversin (1 2),

    Finally, we have (refer to Figure 2)

    d2R

    2= haversin (12)+cos 1cos 2haversin (12), sin2(/2) = haversin ,

    meaning that

    D=R = 2R sin1

    haversin

    .