Table of Contents

Distance Between Two Points On Earth

UTM

UTM (Universal Transverse Mercator) co-ordinates are an approximate mapping from the Earth's surface to flat regions. If your co-ordinates are in UTM then you can use pythagoras to calculate the distance between points:

distance = sqrt( (x1 - x2)^2 + (y1 - y2)^2 )

Latitude and Longitude

The distance between two sets of latitude and longitude co-ordinates are more interesting. The Haversine formula is a beautiful way to calculate these, combining both simplicity and accuracy over small distances:

dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin^2(dlat/2) + cos(lat1) * cos(lat2) * sin^2(dlon/2)
c = 2 * arcsin(min(1,sqrt(a)))
d = R * c

Tarim / March 2008 / for Swarm MediaSandbox project