Distance Formula Calculator (3D) Formula
Understand the math behind the distance formula calculator (3d). Each variable explained with a worked example.
Formulas Used
Distance
distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2))Distance 2d
distance_2d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))Manhattan
manhattan = abs(x2 - x1) + abs(y2 - y1) + abs(z2 - z1)Dx
dx = x2 - x1Dy
dy = y2 - y1Dz
dz = z2 - z1Variables
| Variable | Description | Default |
|---|---|---|
x1 | Point 1 x | 1 |
y1 | Point 1 y | 2 |
z1 | Point 1 z | 3 |
x2 | Point 2 x | 4 |
y2 | Point 2 y | 6 |
z2 | Point 2 z | 8 |
How It Works
Distance Formula
3D Distance
d = sqrt((x₂-x₁)² + (y₂-y₁)² + (z₂-z₁)²)
2D Distance
d = sqrt((x₂-x₁)² + (y₂-y₁)²)
Both are generalizations of the Pythagorean theorem.
Manhattan Distance
Also called taxicab distance: d = |x₂-x₁| + |y₂-y₁| + |z₂-z₁|
This is the distance when you can only move along grid lines (like streets in Manhattan).
Worked Example
Distance from (1, 2, 3) to (4, 6, 8).
x1 = 1y1 = 2z1 = 3x2 = 4y2 = 6z2 = 8
- 01dx = 3, dy = 4, dz = 5
- 023D distance = √(9 + 16 + 25) = √50 ≈ 7.0711
- 032D distance = √(9 + 16) = √25 = 5
- 04Manhattan distance = 3 + 4 + 5 = 12
Ready to run the numbers?
Open Distance Formula Calculator (3D)