Skip to content
Omnikalc

Distance formula calculator: how far apart are two points in 3D?

Enter the x, y and z coordinates of two points to get the straight-line distance between them, the distance in the horizontal plane and the coordinates of the midpoint.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Results

Distance in 3D

13.0000

Distance in the xy plane
5.0000
Midpoint x
2.5000
Midpoint y
4.0000
Midpoint z
9.0000

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.

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.

Frequently asked questions

What is the distance formula in 3D?

d = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]. It is the Pythagorean theorem extended to three coordinates.

Does it work in 2D?

Yes. Set both z values to the same number, for example 0, and the result is the usual 2D distance.

How do I find the midpoint?

Average each coordinate: ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2, (z₁ + z₂) ÷ 2). It is the point halfway along the segment.

Is this the distance on the Earth's surface?

No. It is the straight line through space, in the units of your coordinates. For latitude and longitude, use a great-circle distance calculator.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.