MathsGeometry

Distance
calculator.

Measure the distance between two points, in 2D or 3D, or between two places on Earth.

How it's worked out

The straight-line distance is the Pythagorean theorem in coordinates. The differences in x and y are the legs of a right triangle, and the distance is its long side.

d\displaystyle d=(x2−x1)2+(y2−y1)2\displaystyle {}= \sqrt{(x_2 - x_1)^{2} + (y_2 - y_1)^{2}}

In three dimensions, one more squared term joins in, and the distance becomes the diagonal of a box with the two points at opposite corners. When every coordinate is whole, the tool also pulls square factors out of the root, which is called simplest radical form.

Other measures suit other jobs. Manhattan distance adds the sizes of the differences, as on a street grid. Chebyshev distance is just the largest one. Minkowski distance holds both as special cases, with an order pp that you choose.

Dp\displaystyle D_p=(|Δx|p+|Δy|p)1p\displaystyle {}= \bigl(|\Delta x|^{p} + |\Delta y|^{p}\bigr)^{\frac{1}{p}}

Places on Earth need a different method, since the ground curves. The haversine formula finds the angle cc at Earth's center between two points, with φ\varphi for latitude and λ\lambda for longitude. Multiplying by the radius gives the great-circle distance. This uses the mean radius of 6,371.0088 km from the GRS 80 reference system.

h\displaystyle h=sin2⁡Δφ2+cos⁡φ1cos⁡φ2sin2⁡Δλ2\displaystyle {}= \sin^{2}\frac{\Delta\varphi}{2} + \cos\varphi_1 \cos\varphi_2 \sin^{2}\frac{\Delta\lambda}{2}
c\displaystyle c=2arctan⁡h1−h\displaystyle {}= 2\arctan\frac{\sqrt{h}}{\sqrt{1 - h}}

As a check, the tool also finds the same angle by the spherical law of cosines. The haversine form holds up better on short legs, where the other route loses accuracy to rounding.

Worked examples

Kim compares two routes across town

On a grid in kilometers, Kim is at (−3, −1) and the drop-off is at (2, 3). The differences are 5 and 4, so the squares add to 41.

d\displaystyle d=52+42\displaystyle {}= \sqrt{5^{2} + 4^{2}}=41\displaystyle {}= \sqrt{41}

That is about 6.4 km in a straight line, and 9 km if she has to follow the streets. The longest single leg of the grid route is 5 km.

Open this example in the tool

Noah checks if a long rod fits his room

His room is 5 m long, 4 m wide and 3 m high. The longest straight line runs from a floor corner to the far ceiling corner, the box's diagonal.

The squares add to 50, so the distance is 5√2, about 7.07 m. A rod shorter than that fits if he can get it in the door. Walking the edges instead would take 12 m.

Open this example in the tool

Ada works out her flight from New York to London

JFK sits at 40.6413° N, 73.7781° W, and Heathrow at 51.47° N, 0.4543° W. The great-circle distance is 5,540 km, or 3,442 miles, and 2,991 nautical miles.

The first heading is 51.4°, about northeast, even though London is east of New York on a map. Coming home, the first heading is 287.9°, which is no simple reverse. A real flight runs longer, because winds and airspace change the path.

Open this example in the tool

Reading your result

A radical can be the exact answer. From (−3, −1) to (2, 3) the root does not simplify, so √41 stands. From (0, 0) to (6, 6) the root of 72 becomes 6√2. From (0, 0) to (3, 4) the root is whole: 5.

The order p decides how much one big difference counts. For (1, 2) and (4, 6), the distance is 7 at pp = 1, 5 at pp = 2, 4.5 at pp = 3, 4.02 at pp = 10. It settles toward 4, the largest difference, as pp grows.

Great-circle results are good to a fraction of a percent. Earth is slightly flattened, so a sphere is only an approximation. Errors can reach 0.55%, though they are usually below 0.3%. On this sphere, one degree along a meridian is 111.2 km. For surveying or aviation, use a tool built on an ellipsoid.

Miles and nautical miles are exact conversions. The mile is 1,609.344 m and the nautical mile is 1,852 m. Sydney to Tokyo comes to 7,826 km, or 4,226 nautical miles.

Common mistakes

  • Adding before squaring. The root of a sum of squares is not the sum of the differences. For legs of 3 and 4, the distance is 5, not 7.
  • Dropping a negative. Going from a negative coordinate adds, so −3 to 2 is a difference of 5, not 1. The squares then hide your slip if you never check the sign.
  • Swapping latitude and longitude, or their signs. Latitude comes first, and south and west are negative. Leaving off the minus on a western longitude puts New York in Asia.
  • Using the distance on a flat map. A straight ruler on a world map follows no shortest route, and its scale changes with latitude.

Questions people ask

Add the squared differences, then pull out the largest perfect square factor. From (−8, −2) to (−6, 2), the squares add to 20, and that simplifies to 2√5. This needs whole coordinates, or the squares may not add to a whole number.

Sources