Distance Calculator

The tools presented here allow you to compute the separation between two locations on a flat plane or within three‑dimensional space. They also handle distances between two latitude/longitude pairs or any two points you pick on a map.

2D Distance Calculator

Use this calculator to find the distance between two points on a 2D coordinate plane.

  X1 Y1
Point 1:      )
  X2 Y2
Point 2:      )
2d distance

3D Distance Calculator

Use this calculator to find the distance between two points on a 3D coordinate space.

  X1 Y1 Z1
Point 1:        )
  X2 Y2 Z2
Point 2:        )
3d distance

Distance Based on Latitude and Longitude

Use this calculator to find the shortest distance (great circle/air distance) between two points on the Earth's surface.

  Latitude 1 Longitude 1
Point 1:
  Latitude 2 Longitude 2
Point 2:
Point 1:
  Degree Minute Second  
Latitude:
Longitude:
Point 2:
  Degree Minute Second  
Latitude:
Longitude:

Distance on Map

Use the map underneath to place two markers and determine the minimal (great‑circle/air) distance separating them. After positioning, you can move a marker by pressing and dragging it.

Clear
'; calcResult += ''; }else if (markerCount>0){ calcResult += '

Point 1: ['+lat1+', '+lon1+']

Please set another marker on the map to calculate the distance.

'; }else{ calcResult += '

Please set two markers on the map to calculate the distance between them.

'; } calcResult += '
'; document.getElementById("mapresult").innerHTML = calcResult; }

Distance in a coordinate system

Distance in a 2D coordinate plane:

The distance between two points on a 2D coordinate plane can be found using the following distance formula

d = √(x2 - x1)2 + (y2 - y1)2

Here (x1, y1) and (x2, y2) denote the coordinates of the two points. The formula works regardless of which point you label as 1 or 2, as long as the matching y‑values accompany the chosen x‑values. For instance, with points (1, 5) and (3, 2), either coordinate can serve as x1/x2 provided the associated y‑values are used accordingly.

Using (1, 5) as (x1, y1) and (3, 2) as (x2, y2):

d =(3 - 1)2 + (2 - 5)2
=22 + (-3)2
=4 + 9
=13

Using (3, 2) as (x1, y1) and (1, 5) as (x2, y2):

d =(1 - 3)2 + (5 - 2)2
=(-2)2 + 32
=4 + 9
=13

In either case, the result is the same.

Distance in a 3D coordinate space:

The distance between two points on a 3D coordinate plane can be found using the following distance formula

d = √(x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2

In three dimensions (x1, y1, z1) and (x2, y2, z2) represent the coordinates of the two locations. Just like the 2‑D case, the ordering of the points is irrelevant if the corresponding coordinates stay together. For example, with (1, 3, 7) and (2, 4, 8) the distance evaluates to:

d =(2 - 1)2 + (4 - 3)2 + (8 - 7)2
=12 + 12 + 12
=3

Distance between two points on Earth's surface

Several methods exist to calculate the separation of two points on Earth's surface; two of the most frequently used formulas are listed below.

Haversine formula:

The haversine formula can be used to find the distance between two points on a sphere given their latitude and longitude:

haversine formula

In the haversine formula, d is the distance between two points along a great circle, r is the radius of the sphere, ϕ1 and ϕ2 are the latitudes of the two points, and λ1 and λ2 are the longitudes of the two points, all in radians.

The haversine approach determines the great‑circle distance between two latitude/longitude positions on a sphere, providing an approximation of Earth’s distance since the planet is roughly spherical. A great circle (also called an orthodrome) is the largest possible circle that can be drawn on a sphere, formed where a plane passing through the sphere’s centre intersects its surface. This great‑circle distance is the shortest route along the sphere’s exterior.

Because Earth is not a perfect sphere but an ellipsoid—about 6 378 km at the equator and 6 357 km at the poles—the haversine result can deviate by up to roughly 0.5 %. An ellipsoidal formula such as Lambert’s accounts for this flattening and therefore yields a more accurate estimate than the spherical haversine.

Lambert's formula:

Lambert’s formula, which powers the calculators above, computes the minimal path along an ellipsoidal surface. When applied to the Earth, it delivers distances accurate to within about 10 m over spans of several thousand kilometres, surpassing the precision of the haversine method.

Lambert's formula is as follows:

d = a(σ –
f
2
(X + Y))

where a is the equatorial radius of the ellipsoid (in this case the Earth), σ is the central angle in radians between the points of latitude and longitude (found using a method such as the haversine formula), f is the flattening of the Earth, and X and Y are expanded below.

X = (σ – sin(σ))
sin2(P)·cos2(Q)
cos2(σ/2)
Y = (σ + sin(σ))
cos2(P)·sin2(Q)
sin2(σ/2)

Where P = (β1 + β2)/2 and Q = (β2 - β1)/2

In the expressions above, β1 and β1 are reduced latitudes using the equation below:

tan(β) = (1 - f)tan(ϕ)

where ϕ is the latitude of a point.

Note that neither the haversine formula nor Lambert's formula provides an exact distance because it is not possible to account for every irregularity on the surface of the Earth.

Financial Fitness & Health Math Other