HomeMath › 3D Distance Calculator

3D Distance Calculator

Computes the Euclidean distance between two points in three-dimensional space, their midpoint, the coordinate differences, the direction cosines and direction angles of the connecting segment, and the Manhattan distance.

When to use

You have two (x, y, z) coordinates and need the straight-line distance, the halfway point or the direction of the line between them.

Do not use when: The points are in a plane (use distance-2d), you need vector products or the angle between two vectors (use vector-operations), or the points are geographic coordinates (use haversine-distance).

Formula

distance = √(Δx² + Δy² + Δz²); midpoint = ((x₁ + x₂)/2, (y₁ + y₂)/2, (z₁ + z₂)/2); cos α = Δx / distance, cos β = Δy / distance, cos γ = Δz / distance; manhattan = |Δx| + |Δy| + |Δz|

Inputs

ParameterTypeUnitRequiredDescription
x1numberyesx-coordinate of the first point.
y1numberyesy-coordinate of the first point.
z1numberyesz-coordinate of the first point.
x2numberyesx-coordinate of the second point.
y2numberyesy-coordinate of the second point.
z2numberyesz-coordinate of the second point.

Outputs

OutputTypeUnitDescription
distancenumber√((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²).
midpoint_xnumber(x₁ + x₂) / 2.
midpoint_ynumber(y₁ + y₂) / 2.
midpoint_znumber(z₁ + z₂) / 2.
midpointstringThe midpoint as a coordinate triple, e.g. '(2.5, 4, 9)'.
delta_xnumberx₂ − x₁.
delta_ynumbery₂ − y₁.
delta_znumberz₂ − z₁.
direction_cosinesnumber_list[Δx, Δy, Δz] / distance = [cos α, cos β, cos γ]; their squares sum to 1.
direction_angles_degreesnumber_list°[α, β, γ]: angles between the segment (from point 1 to point 2) and the positive x, y and z axes.
manhattan_distancenumber|Δx| + |Δy| + |Δz|.

Example

(1, 2, 3) to (4, 6, 15): {"x1":1,"y1":2,"z1":3,"x2":4,"y2":6,"z2":15}{"distance":13,"midpoint_x":2.5,"midpoint_y":4,"midpoint_z":9,"midpoint":"(2.5, 4, 9)","delta_x":3,"delta_y":4,"delta_z":12,"direction_cosines":[0.230769,0.307692,0.923077],"direction_angles_degrees":[76.6576,72.0798,22.6199],"manhattan_distance":19}

Origin to (2, 3, 6): {"x1":0,"y1":0,"z1":0,"x2":2,"y2":3,"z2":6}{"distance":7,"midpoint":"(1, 1.5, 3)","direction_cosines":[0.285714,0.428571,0.857143],"manhattan_distance":11}

GET https://tttkmbb.com/api/v1/calculate/distance-3d?x1=1&y1=2&z1=3&x2=4&y2=6&z2=15

Machine access

Sources

FAQ

What are direction cosines used for?

They are the components of the unit vector from point 1 to point 2, so they describe the orientation of the segment; cos²α + cos²β + cos²γ = 1 always holds.

Does the order of the points matter?

Not for distance or midpoint. Δx, Δy, Δz, the direction cosines and angles are taken from point 1 to point 2 and flip sign (angles become 180° − angle) if the points are swapped.

Related calculators