# Details for computing distance using lat/long coordinates

This page explains how the distances are calculated on the page Computing distance using lat/long coordinates.

First we convert latitude and longitude to spherical coordinates. We assume the radius of the earth is 3960 miles (6373 kilometers). (To specify the earth's radius to greater precision, we have to take into account the fact that the earth is not perfectly spherical, a complication we ignore.) Therefore ρ = 3960.

The degrees east of the prime meridian gives the θ coordinate.

Finally φ is the angle from the north pole down to the geographical location. Therefore φ equals 90° minus the degrees latitude north of the equator. For example, 30° latitude corresponds to φ = 60°. For southern latitudes, φ is 90° plus the number of degrees south of the equator. For example, the Tropic of Capricorn is 23.5° south of the equator, corresponding to φ = 113.5.

We convert the θ and φ angles to radians by multiplying by 2π/360°.

Given two points in spherical coordinates (ρ, θ_{1}, φ_{1})
and (ρ, θ_{2}, φ_{2}), the arc formed
by connecting the points is

ψ = arccos(sin φ

_{1}sin φ_{2}cos(θ_{1}-θ_{2}) + cos φ_{1}cos φ_{2}).

The length of the arc ψ is ρ ψ. This is the great circle distance between the two locations

The derivation of the formula for ψ follows. Assume we are given the
spherical coordinates of two locations (ρ, θ_{1}, φ_{1}) and
(ρ, θ_{2}, φ_{2}). Let *u* and *v* be their respective
rectangular coordinates with origin at the center of the earth.

u = ρ(cos θ

_{1}sin φ_{1}, sin θ_{1}sin φ_{1}, cos φ_{1})

v = ρ(cos θ_{2}sin φ_{2}, sin θ_{2}sin φ_{2}, cos φ_{2})

If we cut the earth by the plane containing u and v, we can find the great circle containing the two locations. We find the angle ψ between the two vectors in order to find how much of the circle is taken up by the arc between the locations.

Then cos ψ is given by the dot product of the normalized vectors u/|u| and v/|v|. Note that normalizing u and v simply cancels out the factor of ρ. It follows that cos ψ equals

sin φ

_{1}sin φ_{2 }(cos θ_{1}cos θ_{2}+ sin θ_{1}sin θ_{2}) + cos φ_{1}cos φ_{2}

or

sin φ

_{1}sin φ_{2}cos(θ_{1}- θ_{2}) + cos φ_{1}cos φ_{2}

and so the expression above for ψ follows.

Need help making sense of data?