Mapping Toolbox | ![]() ![]() |
Compute distance between two points on the globe
Syntax
dist = distance(pt1,pt2) dist = distance(pt1,pt2,geoid) dist = distance(pt1,pt2,units) dist = distance(pt1,pt2,geoid,units) dist = distance(track,pt1,...) dist = distance(lat1,lon1,lat2,lon2) dist = distance(lat1,lon1,lat2,lon2,geoid) dist = distance(lat1,lon1,lat2,lon2,units) dist = distance(lat1,lon1,lat2,lon2,geoid,units) dist = distance(track,lat1,...)
Background
Distance between two points can be calculated in two manners. For great circles, the distance is the shortest surface distance between two points. For rhumb lines, the distance is measured along the rhumb line passing through the two points, which is not, in general, the shortest surface distance between them. For more information on this distinction, see the Mapping Toolbox User's Guide.
Description
dist = distance(pt1,pt2) calculates the great circle distance from pt1
to pt2
. These two-column matrices should be of the form [latitude longitude]
. The resulting distance is returned in terms of angle units of arc length (degrees by default).
dist = distance(lat1,lon1,lat2,lon2) performs the same calculation for two pairs of latitude and longitude matrices.
dist = distance(pt1,pt2,geoid) specifies the elliptical definition of the Earth to be used with the two-element geoid
vector. The default geoid model is a unit sphere, which is sufficient for most applications. When a geoid is input, the resulting distance is given in terms of the distance units used in the geoid
vector.
dist = distance(pt1,pt2,units
) specifies the standard angle unit string. The default value is 'degrees'
. These units are also the distance units of the result (e.g., degrees of arc length) unless a geoid
vector is specified.
dist = distance(track
,pt1,...) specifies whether great circle distances or rhumb line distances are desired. Great circle distances, the default, are indicated with the standard track
string 'gc'
. Rhumb line distances are indicated with the standard track
string 'rh'
.
Examples
Imagine a trip from Norfolk, Virginia (37ºN,76ºW), to Cape St. Vincent, Portugal (37ºN,9ºW), just outside the Straits of Gibraltar. The distance between these two points depends upon the track
string selected. Using the pt1,pt2
notation, the two cases result in:
dist = distance('gc',[37,-76],[37,-9]) dist = 52.3094 dist = distance('rh',[37,-76],[37,-9]) dist = 53.5086
The difference between these two tracks is 1.992 degrees, or about 72 nautical miles. This represents about 2% of the total trip distance. The trade-off is that at the cost of those 72 miles, the entire trip can be made on a course of 090º, due east, while in order to follow the great circle path, the course must be changed continuously.
When a great circle and rhumb line coincide, the distances are the same. Using two points on the same meridian, this time in the lat1,lon1,lat2,lon2 notation:
dist = distance(37,-76,67,-76) % great circle sense dist = 30.0000 dist = distance('rh',37,-76,67,-76) dist = 30.0000
The distances are the same, about 1800 nautical miles (there are about 60 nautical miles in a degree of arc length).
See Also
azimuth |
Azimuth between two points on the globe |
elevation |
Elevation between two points on the globe |
distdim |
C onvert distance units |
reckon |
New point with an azimuth and distance |
track track1 track2 trackg |
Trace paths on the globe |
![]() | dist2str | distortcalc | ![]() |