The shortest path between two points is a straight line, and its length follows from the Pythagorean theorem. This distance formula calculator takes the x, y and z coordinates of two points and returns the distance in 3D, the distance in the xy plane and the coordinates of the midpoint.
How the calculation works
- Differences Δx = x₂ − x₁, Δy = y₂ − y₁ and Δz = z₂ − z₁.
- Distance in 3D = √(Δx² + Δy² + Δz²), the Pythagorean theorem applied twice.
- Distance in the xy plane = √(Δx² + Δy²), the length of the shadow of the segment on the floor.
- Midpoint = ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2, (z₁ + z₂) ÷ 2).
Example
Take the points (1, 2, 3) and (4, 6, 15). The differences are Δx = 3, Δy = 4 and Δz = 12. The distance in three dimensions is √(9 + 16 + 144) = √169 = 13. The distance in the xy plane is √(9 + 16) = 5, and the midpoint is (2.5, 4, 9).
Why it matters
Distances between points come up in geometry homework, game and graphics programming, robotics, surveying, 3D printing and CAD. The formula gives the length of a diagonal of a room, the span of a cable between two anchor points or the distance between two atoms in a molecular model.
Good to know
Use the same unit for every coordinate, and the distance will come out in that unit. The distance in the xy plane is the horizontal part, which is useful for the run of a ramp or the footprint of a cable. For points on the Earth, a flat formula is only accurate over short distances, and a great-circle formula is needed for long ones. Round only at the end, because rounding the differences first adds an error to the result.
Related tools
The GPS distance calculator handles latitude and longitude, the point-line distance calculator measures to a line and the point-plane distance calculator measures to a plane.