Home › Math › 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
| Parameter | Type | Unit | Required | Description |
|---|---|---|---|---|
x1 | number | yes | x-coordinate of the first point. | |
y1 | number | yes | y-coordinate of the first point. | |
z1 | number | yes | z-coordinate of the first point. | |
x2 | number | yes | x-coordinate of the second point. | |
y2 | number | yes | y-coordinate of the second point. | |
z2 | number | yes | z-coordinate of the second point. |
Outputs
| Output | Type | Unit | Description |
|---|---|---|---|
distance | number | √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). | |
midpoint_x | number | (x₁ + x₂) / 2. | |
midpoint_y | number | (y₁ + y₂) / 2. | |
midpoint_z | number | (z₁ + z₂) / 2. | |
midpoint | string | The midpoint as a coordinate triple, e.g. '(2.5, 4, 9)'. | |
delta_x | number | x₂ − x₁. | |
delta_y | number | y₂ − y₁. | |
delta_z | number | z₂ − z₁. | |
direction_cosines | number_list | [Δx, Δy, Δz] / distance = [cos α, cos β, cos γ]; their squares sum to 1. | |
direction_angles_degrees | number_list | ° | [α, β, γ]: angles between the segment (from point 1 to point 2) and the positive x, y and z axes. |
manhattan_distance | number | |Δ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
- API:
GET https://tttkmbb.com/api/v1/calculate/distance-3d(query parameters) orPOSTwith a JSON body{"inputs": {...}} - Schema: https://tttkmbb.com/api/v1/calculators/distance-3d · Markdown: https://tttkmbb.com/math/distance-3d.md · JSON definition: https://tttkmbb.com/math/distance-3d.json
- MCP: server
https://tttkmbb.com/mcp, toolrun_calculator with calculator_id="distance-3d" - OpenAPI operationId:
calculate_distance_3d - Freshness:
static. Authentication: none. Rate limit: fair use (see rate limits).
Sources
- Wikipedia – Euclidean distance (reference)
- Wikipedia – Direction cosine (reference)
- Wolfram MathWorld – Direction Cosine (reference)
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
- Distance Between Two Points Calculator — The planar version with Manhattan distance and midpoint.
- Vector Calculator — Treat the two points as vectors: dot and cross products, angle.
- Pythagorean Theorem Calculator — The distance formula is the Pythagorean theorem applied twice.