Calculate the Euclidean distance between two points in 2D or 3D space, or compute geographic great-circle distance using the Haversine formula. Includes midpoint, slope, and bearing calculations.
Distance measurement is fundamental to mathematics, physics, geography, navigation, data science, and everyday life. Our free distance calculator handles three types of distance calculations: the Euclidean distance between two points in 2D coordinate space, the 3D distance formula for three-dimensional coordinates, and the Haversine formula for calculating the great-circle distance between two geographic locations on Earth's surface.
The Euclidean distance between two points (x₁, y₁) and (x₂, y₂) in the Cartesian plane is derived directly from the Pythagorean theorem:
d = √((x₂ − x₁)² + (y₂ − y₁)²)
This is the straight-line ("as the crow flies") distance. For points (1, 2) and (4, 6): d = √((4-1)² + (6-2)²) = √(9+16) = √25 = 5 units exactly.
The formula also yields: midpoint = ((x₁+x₂)/2, (y₁+y₂)/2); slope of line segment = (y₂-y₁)/(x₂-x₁); and the full line equation in slope-intercept form.
Extending to three dimensions, the distance between (x₁,y₁,z₁) and (x₂,y₂,z₂) is:
d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²)
This applies the Pythagorean theorem twice. A box with dimensions l × w × h has a space diagonal = √(l²+w²+h²). In data science, 3D distance is used to measure dissimilarity between data points in three-feature space.
For two locations on Earth specified by latitude (φ) and longitude (λ), the Haversine formula gives the great-circle distance — the shortest path along Earth's surface:
Let a = sin²(Δφ/2) + cos(φ₁)·cos(φ₂)·sin²(Δλ/2)
c = 2·arctan2(√a, √(1-a))
d = R·c where R = 6,371 km (Earth's mean radius)
The "great-circle" distance is the minimum distance between two points on the surface of a sphere. It differs from straight-line (chord) distance through Earth's interior, which is physically relevant for tunnels or drilling but not travel.
| Route | Distance (km) | Distance (miles) | Notes |
|---|---|---|---|
| London → New York | ≈ 5,570 km | ≈ 3,459 miles | Great-circle over North Atlantic |
| Los Angeles → Chicago | ≈ 2,807 km | ≈ 1,744 miles | Transcon US flight route |
| Edinburgh → London | ≈ 534 km | ≈ 332 miles | UK north-south journey |
| New York → Los Angeles | ≈ 3,940 km | ≈ 2,449 miles | Classic US coast-to-coast |
| London → Edinburgh | ≈ 534 km | ≈ 332 miles | By rail: ~640 km/400 miles |
The great-circle distance is always shorter than or equal to the straight-line path through Earth. For short distances (under ~100 km), the difference is negligible. For intercontinental distances, the great-circle path curves over the polar regions — which is why transatlantic flights from London to New York fly far north over Greenland rather than across the equatorial Atlantic. The great-circle path for London-New York takes you within 200 km of Iceland.
The initial bearing (forward azimuth) from Point 1 to Point 2 is the compass direction you would head at the start of a great-circle route:
θ = arctan2(sin(Δλ)·cos(φ₂), cos(φ₁)·sin(φ₂) − sin(φ₁)·cos(φ₂)·cos(Δλ))
Bearing is measured 0°–360° clockwise from north. London to New York has an initial bearing of about 288° (west-northwest).
The Manhattan distance (also called taxicab or L1 distance) measures distance as the sum of the absolute differences of coordinates — like travelling along city blocks where diagonal movement is impossible:
d_manhattan = |x₂−x₁| + |y₂−y₁|
For our example (1,2) to (4,6): Manhattan = |4-1| + |6-2| = 3 + 4 = 7 (vs Euclidean = 5).
GPS (Global Positioning System) satellites continuously broadcast their positions and timestamps. A GPS receiver calculates its position by measuring the time delay of signals from at least four satellites and using these distances to solve for its own location via trilateration — a 3D distance problem. The US GPS system (operated by the US Air Force) and the European Galileo system both use satellite constellations in medium Earth orbit at approximately 20,200 km altitude. The UK's involvement in Galileo and development of its own system (GNSS) became politically significant following Brexit.
In machine learning and statistics, distance metrics determine similarity between data points. The Euclidean distance is used in k-nearest neighbours (k-NN) algorithms, k-means clustering, and principal component analysis. The Minkowski distance is a generalisation: d = (Σ|xᵢ−yᵢ|^p)^(1/p), where p=1 gives Manhattan distance and p=2 gives Euclidean distance. Cosine distance (1 minus cosine similarity) measures angle between vectors and is widely used in text mining and natural language processing.
The United Kingdom uses both miles (for road distances and speed limits) and kilometres (for scientific use and some newer road signs). Most UK maps show distances in both units. The US uses miles almost exclusively for road distances. Both systems appear on our geographic calculator — distances are shown in both km and miles.
For 2D: d = √((x₂-x₁)²+(y₂-y₁)²). For 3D: d = √((x₂-x₁)²+(y₂-y₁)²+(z₂-z₁)²). Both derive from the Pythagorean theorem applied to the difference in coordinates.
The Haversine formula calculates the great-circle distance between two geographic points given their latitudes and longitudes. It uses Earth's radius (≈6,371 km) and accounts for Earth's spherical shape. The formula is: d = 2R·arcsin(√(sin²(Δφ/2)+cos(φ₁)cos(φ₂)sin²(Δλ/2))).
Great-circle distance is the shortest path between two points on the surface of a sphere. It follows the arc of the "great circle" — the circle whose plane passes through Earth's centre. Long-haul flights follow great-circle routes to minimise distance, which often takes them over polar regions.
Midpoint = ((x₁+x₂)/2, (y₁+y₂)/2) for 2D. For 3D: ((x₁+x₂)/2, (y₁+y₂)/2, (z₁+z₂)/2). The midpoint is equidistant from both points.
Euclidean distance is the straight-line "as the crow flies" distance: √((Δx)²+(Δy)²). Manhattan distance follows grid lines: |Δx|+|Δy|. Manhattan distance is always ≥ Euclidean distance. It is used in contexts where diagonal movement is not possible (like city blocks).
The great-circle distance from London (51.51°N, 0.13°W) to New York (40.71°N, 74.01°W) is approximately 5,570 km (3,459 miles). Commercial flights typically cover about 5,600-5,800 km depending on the exact routing and wind patterns.
Edinburgh (55.95°N, 3.19°W) to London (51.51°N, 0.13°W) great-circle distance is approximately 534 km (332 miles). By road it is around 640 km (400 miles) and by East Coast Main Line rail approximately 630 km (393 miles).
The 3D distance formula d = √((Δx)²+(Δy)²+(Δz)²) is used for distances in three-dimensional space: the diagonal of a rectangular box, the distance between atoms in a molecule, the distance between nodes in a 3D network, or the separation between two GPS coordinates including altitude.
Geographic distances are calculated using the Haversine formula with Earth's mean radius of 6,371 km and are approximate. Earth is not a perfect sphere. For precise navigation, use certified mapping tools and GPS equipment.