Reply to comment

Lost but lovely: The haversine

Sine, cosine, and tangent — we do love our trigonometric functions! So imagine our bliss when we recently came across a function we had never even heard of before. It's called the haversine and it's defined in terms of the sine function:

  \[ \mbox{haversin}(\theta ) = \sin ^2(\theta /2). \]    
Great circle distance

The dotted yellow line is an arc of a great circle. It gives the shortest distance between the two yellow points. Image courtesy USGS.

The term "haversine" apparently comes from "half versed sine". To see why this function is useful, put yourself in the shoes of an intrepid traveller setting out on a sea voyage from Liverpool to New York. The first thing you'd want to know is how far you will have to travel. Ignoring islands, rocks, currents and other inconvenient factors, let's say that you will travel along the shortest path between the two cities. We know that the shortest path between two points is along a straight line, but that fact doesn't help you here. The straight line that connects Liverpool and New York cuts right through the Earth and you are not about to dig a tunnel.

You need the shortest path on the surface of the Earth, which is roughly spherical. On a sphere the shortest path between two points is along an arc of a great circle: that's a circle drawn on the surface of the sphere which is centred on the same point as the sphere and has the same radius. Any two points lie on a unique great circle, which they divide up into two arcs. The shortest path between the points is along the shorter of these two arcs.

So how do you calculate this great circle distance between two points $P$ and $Q$ on the Earth? First, recall that the locations of the two points are given by their latitudes, for which we will write $\phi _ P$ and $\phi _ Q,$ and their longitudes, which we will denote by $\lambda _ P$ and $\lambda _ Q.$ Write $R$ for the radius of the Earth, which is roughly $6,371$ km. The great circle distance $d$ between $P$ and $Q$ comes from the formula

  \begin{equation} \sin ^2{\left(\frac{d}{2R}\right)} = \sin ^2{\left(\frac{\phi _2-\phi _1}{2}\right)} + \cos {\phi _1}\cos {\phi _2} \sin ^2{\left(\frac{\lambda _2-\lambda _1}{2}\right)},\end{equation}   (1)

(where the angles are measured in radians).

Solving for $d$ gives

  \begin{equation} d = 2R \sin ^{-1}{\left(\sqrt {\sin ^2{\left(\frac{\phi _2-\phi _1}{2}\right)} + \cos {\phi _1}\cos {\phi _2} \sin ^2{\left(\frac{\lambda _2-\lambda _1}{2}\right)}}\right)}.\end{equation}   (2)

You’ll admit that this isn’t the simplest of formulae. If you were are a seafarer hundreds of years ago, armed only with sine and cosine tables to help you, working out the distance $d$ would prove pretty cumbersome. There’s a square root to take, as well as the inverse of the sine function .... argh!

But now let’s replace any expressions of the form $\sin ^2(\theta /2)$ by the haversine function. Expression (1) above becomes

  \[ \mbox{haversin}\left(\frac{d}{R}\right) = \mbox{haversin}\left(\phi _2-\phi _1\right) + \cos {\phi _1}\cos {\phi _2} \mbox{haversin}\left(\lambda _2-\lambda _1\right). \]    

The distance $d$ is now

  \[ d = R \; \;  \mbox{haversin}^{-1}\left(\mbox{haversin}\left(\phi _2-\phi _1\right) + \cos {\phi _1}\cos {\phi _2} \mbox{haversin}\left(\lambda _2-\lambda _1\right)\right). \]    

Working out the great circle distance between two points is so important in navigation that people in the old days produced tables giving the values of the haversine function and also of the inverse of the haversine function. This made seafarers’ lives a lot easier. Working out the distance $d$ only involved looking up two cosine values and two haversine values, adding and multiplying them in the correct way, looking up the inverse of the haversine function and multiplying by $R$— done!

The reason why the haversine function has come out of fashion is that with the help of calculators and computers it’s easy enough to work out the distance $d$ straight from formula (2). That’s why you don’t find a haversine button on your average calculator.

Let’s give it a go. Liverpool has latitude $53.4^\circ $ and longitude $-3^\circ $, and New York has latitude $40.71^\circ $ and longitude $-74^\circ $. These are measured in degrees. Converting them into radians (multiplying by $\pi /180$) gives $\phi _ L = 0.932^\circ $ and $\lambda _ L=-0.052^\circ $ for Liverpool, and $\phi _{NY} = 0.71^\circ $ and $\lambda _{NY}=-1.291^\circ $ for New York (rounded to three decimal places) Plugging these into expression (2), with the radius of the Earth $R = 6371$, gives a great circle distance of around 5313 km. Quite a way to go!

Reply

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

To prevent automated spam submissions leave this field empty.
By submitting this form, you accept the Mollom privacy policy.