calc-hub logocalc-hub.net

Distance Calculator

Enter the x and y coordinates of two points, or switch to 3D and add z. The calculator returns the straight-line distance between them and works the distance formula through with your numbers, from the gaps to the square root. Coordinates can be negative or decimal. The distance comes out in the same unit as the coordinates, rounded to 4 decimal places. For two places on Earth, switch to Latitude and longitude, and the calculator returns the great-circle distance in kilometers, miles and nautical miles.

Point 1
Point 2

How to use the Distance Calculator

  1. Choose 2D, 3D or Latitude and longitude.
  2. Enter the coordinates of point 1 and point 2. Latitude and longitude go in decimal degrees, with south and west negative.
  3. Press Calculate to see the distance and each step of the formula.

The distance formula

d = √((x₂ − x₁)² + (y₂ − y₁)²) · · · 3D: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²) · · · Great circle: a = sin²(Δφ ÷ 2) + cos φ₁ × cos φ₂ × sin²(Δλ ÷ 2), d = R × 2 × atan2(√a, √(1 − a))

The gaps x₂ − x₁ and y₂ − y₁ are the two short sides of a right triangle, and the distance between the points is its hypotenuse. That is the Pythagorean theorem. In 3D the z gap adds one more square under the root. Squaring removes the sign, so the order of the points does not matter. The great-circle form is the haversine formula, with φ the latitudes, λ the longitudes and R = 6,371 km.

Worked example

From (1, 2) to (4, 6) the gaps are 3 and 4, so d = √(9 + 16) = √25 = 5. From (−2, 3) to (5, −1) the gaps are 7 and −4, and d = √(49 + 16) = √65 ≈ 8.0623. In 3D, from (0, 0, 0) to (3, 4, 12), d = √(9 + 16 + 144) = √169 = 13. From London (51.5074, −0.1278) to New York (40.7128, −74.006) the great-circle distance is 5,570.22 km, or 3,461.18 miles.

Frequently asked questions

Does the order of the points matter?

No. Swapping the points flips the sign of each gap, and squaring removes it again. From (4, 6) to (1, 2) is 5, the same as from (1, 2) to (4, 6).

What if the two points share an x or y coordinate?

Then that gap is 0 and the distance is the other gap without its sign. From (2, 1) to (2, 9) the distance is 8.

Does it work with latitude and longitude?

Yes, in the Latitude and longitude mode. Enter decimal degrees, with south and west negative. The 2D mode is wrong for these numbers, because a degree of longitude covers less ground the closer you get to a pole.

How accurate is the great-circle distance?

It treats the Earth as a sphere of radius 6,371 km, the volumetric mean radius in the NASA Earth Fact Sheet, so it is an approximation. The same sheet gives 6,378.137 km at the equator and 6,356.752 km at the poles. Against the WGS 84 ellipsoid the sphere is off by up to about 0.6%. London to New York comes to 5,570 km here and 5,585 km on the ellipsoid.

Can I get the slope or the midpoint too?

The slope calculator takes the same four numbers and gives the slope, the angle and the equation of the line. The midpoint is the average of each coordinate, ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2), so (1, 2) and (4, 6) have the midpoint (2.5, 4).

How is this related to the Pythagorean theorem?

The distance formula is the Pythagorean theorem with the x and y gaps as the two legs. To find a missing side of a right triangle from the other two, use the Pythagorean theorem calculator.

What about driving distance?

A road can never be shorter than the straight line between its two ends, so driving distance is always the longer number. Use a map service for road distance.

We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.
Learn more.