3D distance calculator
From (1.5, 2.5, 3.5) to (4.5, 6.5, 8.5) the gaps are 3, 4 and 5, so the straight-line distance is 7.07106781187. Enter any two points in space and get that length, each axis gap and the squared distance. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- X1
- 1.5
- Y1
- 2.5
- Z1
- 3.5
- X2
- 4.5
- Y2
- 6.5
- Z2
- 8.5
- Dx
- 3
- Dy
- 4
- Dz
- 5
- Distance
- 7.0710678119
You send six numbers and get back the distance, the three axis deltas and the squared distance, in the same unit you measured the coordinates in. It is the natural generalization of the Pythagorean theorem to space — the answer to 'how far apart are these two things' in volumes, scenes and physical models — delivered as a single deterministic call, with an explicit error whenever any coordinate is missing or is not a finite number.
From Pythagoras to three dimensions
The 3D distance formula is the Pythagorean theorem applied twice. First collapse the z dimension: the projection of your segment onto the xy-plane has length sqrt(dx² + dy²), exactly the 2D case. That projection and the vertical gap dz form the legs of a second right triangle whose hypotenuse is the true spatial segment, so d = sqrt(dx² + dy² + dz²).
The 3d distance calculator performs exactly this computation and nothing else. Because every delta is squared, the order of the points is irrelevant: the distance from A to B always equals the distance from B to A, and negative gaps collapse into the same positive leg lengths. Because the result is a square root of a sum of squares, it is always non-negative and it is zero exactly when the two points coincide.
Units, squared distances and numerical robustness
No conversion is applied and none is needed, which also means it is your responsibility to give all six coordinates in the same unit before calling. Two implementation details are worth knowing. First, the squared distance dx² + dy² + dz² is returned alongside the distance itself: when you only need to rank candidates by closeness — the nearest drone, the closest sensor, the farthest vertex — comparing squared distances avoids the square root entirely and is the standard trick inside nearest-neighbour loops over large point clouds.
Second, the square root is taken with Math.hypot rather than by naively summing squares, so coordinate differences approaching 10¹⁵⁴ do not overflow to Infinity on the way to a perfectly finite answer, and tiny differences near 10⁻¹⁵⁴ do not underflow to zero. Outputs are rounded to twelve significant decimal places, which keeps responses stable and comparable across machines and runs without sacrificing any precision a physical measurement could justify.
What you can do with it
Proximity and collision checks in 3D engines
Measure separation between objects, waypoints or agents in games and simulations, triggering events when the distance crosses a threshold.
Nearest neighbour in point clouds
Rank squared distances from a query point to sensors, assets or LiDAR samples and pick the closest without paying for unnecessary square roots.
Engineering clearances and tolerances
Verify that two mounting points, cables or components in a CAD or BIM model keep the required minimum or maximum separation.
FAQ
What formula does it use?
The Euclidean distance in space: d = sqrt((x2 - x1)² + (y2 - y1)² + (z2 - z1)²), computed with Math.hypot for numerical robustness.
What units is the result in?
The same unit as your coordinates. If x, y and z are metres, the distance is metres; no unit conversion is applied.
Why is the squared distance returned too?
Because comparing squared distances is cheaper when you only need to rank candidates by closeness — the square root is unnecessary for ordering.
Does the order of the two points change the distance?
No. Every gap is squared before it is added, so the distance from A to B always equals the distance from B to A, and a negative gap counts the same as a positive one.
Can the distance between two points be zero or negative?
It is never negative, because it is the square root of a sum of squares. It is zero only when the two points are exactly the same, which makes it a handy check for duplicate positions.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/distance-3d \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"x1":1.5,"y1":2.5,"z1":3.5,"x2":4.5,"y2":6.5,"z2":8.5}'const res = await fetch("https://api.kit.forhosting.com/math/distance-3d", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"x1": 1.5,
"y1": 2.5,
"z1": 3.5,
"x2": 4.5,
"y2": 6.5,
"z2": 8.5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/distance-3d",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"x1": 1.5,
"y1": 2.5,
"z1": 3.5,
"x2": 4.5,
"y2": 6.5,
"z2": 8.5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/distance-3d", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"x1":1.5,"y1":2.5,"z1":3.5,"x2":4.5,"y2":6.5,"z2":8.5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"x1":1.5,"y1":2.5,"z1":3.5,"x2":4.5,"y2":6.5,"z2":8.5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/distance-3d", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"x1": 1.5,
"y1": 2.5,
"z1": 3.5,
"x2": 4.5,
"y2": 6.5,
"z2": 8.5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.distance_3d",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The 3D distance API computes the Euclidean distance between two points in three-dimensional space from their x, y and z coordinates: the straight-line length of the segment joining (x1, y1, z1) and (x2, y2, z2), given by d = sqrt((x2 - x1)² + (y2 - y1)² + (z2 - z1)²).
From Pythagoras to three dimensions
The response echoes the parsed coordinates and the three deltas next to the distance, so you can audit precisely which inputs produced which output without re-deriving anything by hand. That traceability matters when a distance feeds a collision threshold, a quality tolerance or a safety clearance and somebody later asks why a borderline case passed or failed.
Units, squared distances and numerical robustness
The endpoint is deliberately unit-agnostic: coordinates in metres yield a distance in metres, voxels yield voxels, and CAD model units yield model units.
Validation, errors and how to integrate it
The contract is strict on purpose: every one of the six coordinates must be a finite number. Numeric strings such as '4.5' are accepted and coerced, because form data and query strings arrive as text in the real world, but the coercion is exact: anything that does not parse fully as a number is rejected rather than silently truncated. A missing field, a null, an empty string, a boolean, an array, a non-numeric label like 'up', NaN or ±Infinity all produce the same outcome — a clean invalid_input error naming the offending field, and no charge, since client errors are never billed. Integration is trivial: POST a JSON object with x1, y1, z1, x2, y2 and z2, read the distance field from the response, and handle the documented error code instead of parsing messages. If your data is genuinely two-dimensional, either pin both z coordinates to the same value or use the dedicated 2D endpoint, which needs only four numbers. The same code that runs on our edge runs free in your browser on this page, so you can prototype with real numbers before wiring the API into your pipeline, and you pay the published $0.002 per request only when you automate it.
Technical questions
What does it cost?
$0.002 per request. It is also free to run in your browser on this page.
What happens if a coordinate is missing or not a number?
You get an invalid_input error naming the field, and the request is not billed. NaN and Infinity are also rejected.
Can I use it for 2D points?
Yes — give both points the same z coordinate and the formula reduces to the 2D case, though the dedicated 2D endpoint needs fewer fields.