CalcTrace

Distance Calculator

Find the straight-line distance between two points on a plane or in 3D space, along with the midpoint and the Manhattan (grid) distance. Or enter two latitude and longitude positions to get the great-circle distance across the Earth’s surface in kilometres, miles and nautical miles.

Last updated .

Where are the two points?

Type of distance
First point
Second point

Negative and decimal coordinates are fine. Every axis must use the same unit.

Result

Distance

–

Show the working

    The distance formula

    The straight-line distance between two points on a plane is the Pythagorean theorem in disguise. The horizontal gap and the vertical gap between the points are the two legs of a right-angled triangle, and the distance is its hypotenuse. For points (x₁, y₁) and (x₂, y₂):

    d = √((x₂ − x₁)² + (y₂ − y₁)²)

    In three dimensions a third gap, along the z-axis, is squared and added under the same root:

    d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

    The midpoint, the point exactly halfway along the line, is the average of the coordinates, and the Manhattan distance adds the gaps instead of squaring them:

    Midpoint = ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2)

    Manhattan distance = |x₂ − x₁| + |y₂ − y₁|

    The vertical bars mean the size of the gap without its sign. Manhattan distance, also called taxicab distance, is how far you travel when you can only move along a grid, like a car in city blocks or a picker in warehouse aisles. It is never shorter than the straight line, and on a plane never more than √2, about 1.4142, times longer.

    Worked examples

    Two dimensions

    From (1, 2) to (4, 6).

    1. Gaps: 4 − 1 = 3 across and 6 − 2 = 4 up.
    2. Square and add: 3² + 4² = 9 + 16 = 25.
    3. Square root: √25 = 5.

    The Manhattan distance is 3 + 4 = 7 and the midpoint is (2.5, 4).

    With negative coordinates

    From (−2, 3) to (4, −5): the gaps are 4 − (−2) = 6 and −5 − 3 = −8. Squaring removes the sign, so 36 + 64 = 100 and the distance is 10. The midpoint is (1, −1) and the Manhattan distance is 6 + 8 = 14. Subtracting a negative is where most slips happen; write the brackets.

    Three dimensions

    From (1, 2, 3) to (4, 6, 15): the gaps are 3, 4 and 12, so the distance is √(9 + 16 + 144) = √169 = 13. The midpoint is (2.5, 4, 9) and the Manhattan distance is 19.

    Distance between two places on Earth

    Latitude and longitude are angles, not lengths, and the Earth’s surface is curved, so the flat formula does not apply. The shortest path over a sphere is an arc of a great circle, and the haversine formula gives its length. With latitudes φ₁ and φ₂, longitudes λ₁ and λ₂ (all in radians) and Earth radius R:

    a = sin²((φ₂ − φ₁) ÷ 2) + cos φ₁ × cos φ₂ × sin²((λ₂ − λ₁) ÷ 2)

    d = 2 × R × sin⁻¹(√a)

    This calculator uses R = 6,371.0088 km, the Earth’s mean radius. From Sydney (−33.8688, 151.2093) to Melbourne (−37.8136, 144.9631) it gives 713.4 km, which is 443.3 miles or 385.2 nautical miles. Sydney to Perth comes to about 3,290 km and Sydney to London about 16,994 km. No two places can be more than half the Earth’s circumference apart, about 20,015 km.

    How accurate is it?

    The result is an approximation. The Earth is not a perfect sphere: its equatorial radius is 6,378.137 km and its polar radius 6,356.752 km, a difference of about 0.34%. The mean radius used here is the average of two equatorial radii and one polar radius. Treating the planet as a sphere can put a long distance out by a few tenths of a per cent, which is a few kilometres between Australian capitals. Surveying and aviation use ellipsoidal methods instead. The figure is also the distance as the crow flies, at sea level. Road distances are always longer.

    Why you cannot use the flat formula on degrees

    One degree of latitude is about 111.2 km everywhere, but a degree of longitude shrinks as you move away from the equator: at Sydney’s latitude it is only about 92.3 km. Treating the Sydney to Melbourne coordinates as a flat grid of 111.2 km squares gives about 821 km, roughly 15% too far.

    Converting degrees, minutes and seconds

    Maps and older GPS units often give positions as degrees, minutes and seconds. Divide the minutes by 60 and the seconds by 3,600 and add them to the degrees, then make the result negative for south or west. A latitude of 33° 52′ 08″ S becomes −(33 + 52 ÷ 60 + 8 ÷ 3,600) = −33.8689.