Coordinate Conversion
Haversine Formula
The Haversine formula can be used to find the shortest distance (great circle distance) between two points on the earth’s surface, given their latitude and longitude coordinates.
where:
is the shortest (great circle) distance between the two points, in meters
radius of the earth, in meters *(see below)
is the latitude and longitude of point 1, in radians
is the latitude and longitude of point 2, in radians
The typical value used for is , which is the mean radius of the earth.
The code for this formula in many different languages can be found at https://rosettacode.org/wiki/Haversine_formula.
You may also see this Haversine distance formula written as:
where all the symbols have the same meaning as above
These two formulas are equivalent!
Bearing
This formula calculates the initial bearing, given a start and end co-ordinate.
where:
is the initial bearing, in radians, from to
is the latitude and longitude of point 1, in radians
is the latitude and longitude of point 2, in radians
Note that this calculates the initial bearing, which is the bearing you would have to be pointing in at the first co-ordinate to travel to the second co-ordinate along a great circle (shortest path on the sphere). As you travel there, the bearing is likely to change (there are a few cases in where it wouldn’t change, one being if you were travelling exactly North).
Destination Coordinate Given Distance And Bearing From Start Coordinate
The following formula allows you to calculate a destination coordinate (lat/lon) if you know a starting coordinate (again, in lat/lon), ground distance (great circle distance) and initial bearing.
where:
= angular distance, in radians
= ground (great circle) distance between start coordinate and destination coordinate, in meters
= radius of the earth, in meters
= initial bearing from start to destination coordinate (clockwise from North), measured in radians
= starting coordinate, latitude and longitude measured in radians
= destination coordinate, latitude and longitude measured in radians
Note that depends on , so you have to calculate the latitude of p2 before you can calculate the longitude.