Send
Close Add comments:
(status displays here)
Got it! This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
Map distances
1. Map distances
2. Earth
The earth is round, not flat.
Euclidean distances work for flat surfaces but not curved surfaces.
It is often needed to calculate (approximate) the shortest distance between two points on the surface of the earth.
3. Geographic coordinates
A location in geographic coordinates is expressed as a longitude and a latitude. Each are angles.
There are many ways to calculate the shortest distance between two points on the surface of the earth.
Here the assumption is made that the earth is a perfect sphere.
4. Spherical law of cosines
The spherical law of cosines can be used to approximate the shortest distance between two points on the surface of the earth (for small, not large, distances).
Note that coordinates on the Internet can vary for places depending on where in that location the coordinates are taken.
Actual distances by roads, of course, would be longer.
5. Method
Given 2 points on the surface of the earth in degrees.
Point 1: (lat1d, long1d)
Point 2: (lat2d, long2d)
The
radius of the earth is about
3958.8 miles.
6. Degrees and radians
Convert all latitudes and longitudes from degrees to radians using the following relationships
2π radians = 360 degrees
π radians = 180 degrees
This relationship can be used to convert, say,
lat1d (latitude in degrees) to
lat1r (latitude in radians), etc.
The symbol
π is
pi and is approximated by
3.1415.... In an actual programming language, one would use a constant for pi that approximates pi to the precision of that system.
The distance
d between the two points is then as follows, where
acos is the
arccos function (i.e., inverse
cos) and all angles are in radians.
d = R * acos( sin(lat1r)*sin(lat2r) + cos(lat1r)*cos(lat2r)*cos(long2r-long1r) )
If
radius is in miles, the distance is in miles. If
radius is in kilometers, then the distance is in kilometers.
7. Mathematical formula
A more mathematical formula is as follows.
Where:
R is radius
φ1 is latr1r
φ2 is latr2r
θ1 is long1r
θ2 is long2r
8. End of page