Distance Between Two Points in 3D
In 3D geometry, a point is described by three coordinates \((x,y,z)\) that locate it in space relative to three
perpendicular axes. The most common way to measure how far apart two points are is the Euclidean distance,
which is the straight-line (shortest) distance between them. If the points are
\(A(x_1,y_1,z_1)\) and \(B(x_2,y_2,z_2)\), the displacement from \(A\) to \(B\) is the vector
\(\overrightarrow{AB}=(x_2-x_1,\;y_2-y_1,\;z_2-z_1)\). The distance is simply the length (magnitude) of this vector.
The formula comes directly from the Pythagorean theorem applied twice. First, imagine projecting the segment \(AB\)
onto the \(xy\)-plane. In that plane, the horizontal distance is
\(\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\). Then the full 3D segment forms a right triangle with that planar distance as one leg
and the vertical difference \((z_2-z_1)\) as the other leg. Applying Pythagoras again gives:
\[
\begin{aligned}
d &= \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2} \\
d^2 &= (x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2
\end{aligned}
\]
The squared distance \(d^2\) is especially useful in practice: it avoids the square root and preserves ordering
(if \(d_1 < d_2\), then \(d_1^2 < d_2^2\)). That is why many algorithms compare squared distances when they only need
to decide which point is closer (for example, nearest-neighbor searches, clustering, and collision checks).
Units matter: if \(x\), \(y\), and \(z\) are measured in meters, then \(d\) is also in meters. The formula assumes all
coordinates use the same unit scale. In real-world applications like GPS-style 3D positioning, you often convert
latitude/longitude/altitude into a consistent Cartesian coordinate system before using Euclidean distance; otherwise,
the geometry of the Earth and unit conversions can distort the result.
This calculator also shows a 3D visualization of points \(A\) and \(B\) and the segment between them. The plot helps you
interpret the result: large coordinate differences in any direction increase the total distance because each squared
component adds positively to \(d^2\). You can orbit the camera, pan, and zoom to see the segment from different angles.
Finally, the midpoint
\(M=\left(\frac{x_1+x_2}{2},\frac{y_1+y_2}{2},\frac{z_1+z_2}{2}\right)\) is included because it’s a common companion
concept: it locates the point halfway along the straight path from \(A\) to \(B\).
Common checks
- If the two points are identical, all differences are 0 and the distance is 0.
- If only one coordinate changes (e.g., \(x\) changes but \(y,z\) don’t), the distance reduces to the absolute change in that coordinate.
- Swapping \(A\) and \(B\) does not change the distance.