Three-Dimensional Distance Calculator
Enter the (x, y, z) coordinates of two points and this calculator finds the straight-line Euclidean distance between them in three-dimensional space. You also get the midpoint of the segment, the direction vector from Point A to Point B, the unit vector, and the individual axis distances. All results update as you type.
Formula
Worked example
Points A(1, 2, 3) and B(7, 5, 9): dx=6, dy=3, dz=6. d = sqrt(36+9+36) = sqrt(81) = 9. Midpoint M = (4, 3.5, 6). Unit vector = (6/9, 3/9, 6/9) = (0.667, 0.333, 0.667).
The 3D distance formula
The straight-line (Euclidean) distance between two points A(x1, y1, z1) and B(x2, y2, z2) in three-dimensional space extends the familiar 2D Pythagorean theorem to a third axis. You compute three independent axis differences, square each one, add them together, then take the square root: d = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2). The key insight is that three perpendicular axes are independent of each other, so each squared term contributes independently to the total squared distance, just as the two legs of a right triangle combine in 2D.
Midpoint and direction vector
Beyond the scalar distance, two additional quantities are useful for most geometry and physics problems. The midpoint M is the point exactly halfway along the segment AB, computed axis by axis: M = ((x1+x2)/2, (y1+y2)/2, (z1+z2)/2). The direction vector D = (x2-x1, y2-y1, z2-z1) points from A toward B and has a magnitude equal to the distance d. Dividing D by d gives the unit vector u, which has magnitude exactly 1 and is used in physics and computer graphics to represent a pure direction without any implied speed or length.
Where 3D distance appears in science and engineering
Three-dimensional distance is a building block across many fields. In physics, it appears in Coulomb's law (electric force scales with 1/d^2), gravitational attraction, and wave propagation. In computer graphics, it determines whether objects overlap (collision detection) and powers nearest-neighbour searches in 3D scenes. In robotics and CNC machining, path length between tool positions is the sum of segment distances. Molecular chemistry uses it to measure bond lengths from atomic coordinates in crystal structure files. GPS systems triangulate a receiver's position by solving distances to at least three satellites simultaneously.
How the axis-delta breakdown helps interpretation
The bar chart above shows the absolute delta in each axis direction. If one bar dominates, the path between your two points is nearly parallel to that axis - the distance is mostly a one-axis separation, almost like a 1D problem. When all three bars are similar, the path is a true diagonal through 3D space. The unit vector components tell you the same thing as fractions: a unit-vector x-component of 0.9 means 90% of the direction lies along the x-axis. This breakdown is handy when aligning 3D objects or planning waypoints because it tells you which axis needs the biggest correction.
Axis contribution to total distance
| Axis | Delta | Delta squared | Share of squared distance |
|---|---|---|---|
| x | x₂ - x₁ | (Δx)² | (Δx)² / d² |
| y | y₂ - y₁ | (Δy)² | (Δy)² / d² |
| z | z₂ - z₁ | (Δz)² | (Δz)² / d² |
Each axis contributes its squared delta to the sum under the square root. The share shows how much of the total distance "comes from" each axis.
Frequently asked questions
What is the 3D distance formula?
d = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2). It extends the 2D Pythagorean theorem to a third dimension by adding the squared z-difference inside the square root. The three axis differences are independent, so you simply add all three squared deltas before taking the root.
How is this different from 2D distance?
The 2D formula uses only x and y differences: d = sqrt((x2-x1)^2 + (y2-y1)^2). Adding the z term accounts for depth. If both points have the same z value (z1 = z2), the z term is zero and the formula reduces to the 2D case. In the calculator you can verify this by setting z1 = z2 and comparing the result with a flat-plane distance calculation.
What is the midpoint in 3D?
The midpoint M is the point equidistant from both ends of the segment. It is computed separately for each axis: Mx = (x1+x2)/2, My = (y1+y2)/2, Mz = (z1+z2)/2. In geometry, the midpoint bisects the segment exactly in half. In physics, it is the center of mass of two equal masses placed at A and B.
What is a unit vector and why does it matter?
A unit vector has magnitude exactly 1 and represents a pure direction. Starting from the direction vector (dx, dy, dz), you divide each component by the distance d to normalise it. The result tells you "which way" to travel from A to B with a step size of 1. Unit vectors are fundamental in graphics (surface normals, ray direction) and physics (force direction, velocity direction) because they separate the concept of direction from magnitude.
Can the coordinates be negative or fractional?
Yes. The formula works for any real numbers, positive, negative, or decimal. Negative coordinates simply mean the point is on the negative side of the axis origin. The squared terms make sign irrelevant: (-3)^2 = 9, the same as 3^2 = 9. Fractional coordinates work identically; there is no requirement for integer inputs.
What happens when both points are the same?
If A and B share identical coordinates, all three deltas are zero, and d = sqrt(0+0+0) = 0. The unit vector is undefined in that degenerate case (division by zero), so the calculator shows 0 for all unit-vector components. The midpoint is identical to both points.