Find the distance between two points on a 2D plane or in 3D space, or the shortest distance along Earth's surface between two latitudes and longitudes. 2D results also include slope, the incline angle, and the equation of the line through the points.
Formula
On a plane the distance is the Pythagorean theorem:
d = √((x₂ − x₁)² + (y₂ − y₁)²)
In 3D, add the z-term:
d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)
On Earth, Lambert's formula uses the haversine central angle σ on reduced latitudes β (tan β = (1 − f) tan φ), then
d = a (σ − (f/2)(X + Y))
with equatorial radius a = 6,378.1 km and flattening f = 1/298.257. Miles are km / 1.60935. This is air / great-circle distance, not a road route.
The default 2D example is (1, 1) and (4, 5): d = 5, m = 4/3, θ ≈ 53.130102354156°. The default Earth pair is the White House to Philadelphia: 200.0 km or 124.3 miles.
Worked identities
| Points | Distance |
|---|---|
| (1, 1) and (4, 5) | 5 |
| (1, 5) and (3, 2) | √13 ≈ 3.605551275464 |
| (0, 0) and (2, 2) | 2√2 ≈ 2.8284271247462 |
| (1, 1, 1) and (2, 2, 2) | √3 ≈ 1.7320508075689 |
| (0, 0, 0) and (2, 2, 2) | 2√3 ≈ 3.4641016151378 |
| 38.8976, −77.0366 to 39.9496, −75.1503 | 200.0 km or 124.3 miles |
Examples
2D 3-4-5 triangle (default)
Points (1, 1) and (4, 5). ΔX = 3, ΔY = 4, so d = √(9 + 16) = 5. Slope is 4/3 ≈ 1.3333333333333 and θ ≈ 53.130102354156°. The line is y = (4/3)x − 1/3.
3D unit cube diagonal (default)
Points (1, 1, 1) and (2, 2, 2). Each coordinate changes by 1, so d = √3 ≈ 1.7320508075689.
White House to Philadelphia
Decimal 38.8976, −77.0366 to 39.9496, −75.1503, or DMS 38° 53' 51.36" N, 77° 2' 11.76" W to 39° 56' 58.56" N, 75° 9' 1.08" W. Lambert's formula gives 200.0 km or 124.3 miles.