# 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.

- Calculator id: `distance-3d` · Category: Math (`math`) · Tool name: `calculate_distance_3d`
- Canonical page: https://tttkmbb.com/math/distance-3d · This document: https://tttkmbb.com/math/distance-3d.md · JSON definition: https://tttkmbb.com/math/distance-3d.json

## Purpose

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.

**Use when:** 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).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `x1` | number |  | required | x-coordinate of the first point. |
| `y1` | number |  | required | y-coordinate of the first point. |
| `z1` | number |  | required | z-coordinate of the first point. |
| `x2` | number |  | required | x-coordinate of the second point. |
| `y2` | number |  | required | y-coordinate of the second point. |
| `z2` | number |  | required | z-coordinate of the second point. |

## Output

| Field | 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\|. |

## 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|`

## Data Sources

- Wikipedia – Euclidean distance — https://en.wikipedia.org/wiki/Euclidean_distance (reference, retrieved 2026-09-24)
- Wikipedia – Direction cosine — https://en.wikipedia.org/wiki/Direction_cosine (reference, retrieved 2026-09-24)
- Wolfram MathWorld – Direction Cosine — https://mathworld.wolfram.com/DirectionCosine.html (reference, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/distance-3d?x1=…&y1=…&z1=…&x2=…&y2=…&z2=…`
- `POST https://tttkmbb.com/api/v1/calculate/distance-3d` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/distance-3d · OpenAPI operationId `calculate_distance_3d` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "distance-3d", "inputs": {…}}`

## Example

- (1, 2, 3) to (4, 6, 15): inputs `{"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): inputs `{"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
```

## Limitations

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). All values are computed from the formula above; no measurement or live data is involved.

## 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

- [Distance Between Two Points Calculator](https://tttkmbb.com/math/distance-2d.md) — The planar version with Manhattan distance and midpoint.
- [Vector Calculator](https://tttkmbb.com/math/vector-operations.md) — Treat the two points as vectors: dot and cross products, angle.
- [Pythagorean Theorem Calculator](https://tttkmbb.com/math/pythagorean.md) — The distance formula is the Pythagorean theorem applied twice.
