CalcWorldHub
Math · CalcWorldHub

3D Manhattan Distance: The City-Block Metric

From (1,2,3) to (5,6,7), the 3D Manhattan distance is |4|+|4|+|4|=12 coordinate units. The Euclidean straight-line distance is only √48≈6.9282. The difference matters when movement is constrained to coordinate-aligned steps rather than allowed to cut diagonally through space.

Open calculator
A stepped right-angle route runs through a three-dimensional orthogonal grid between two endpoints.

Share this article

A grid path travels along three coordinate axes in right-angle segments from a start point to a destination.
Add each axis-aligned segment; the order of the turns does not change the total.

How the city-block metric works

For points P₁=(x₁,y₁,z₁) and P₂=(x₂,y₂,z₂), the Manhattan or L₁ distance is |x₂−x₁|+|y₂−y₁|+|z₂−z₁|. Each absolute difference is the amount of travel along one axis. Summing them describes a path made from axis-aligned segments, without requiring a particular order for those segments.

The name comes from grid routes through city blocks, where a straight line may not be a legal path. In three dimensions, the same metric can model movement between orthogonal aisles or cells when diagonal motion is disallowed. It is a geometric distance under this rule, not a route planner that checks obstacles or available corridors.

What its inputs mean

The calculator accepts the same six point coordinates as a straight-line distance tool: Point 1 x, y, z and Point 2 x, y, z. Use one common coordinate frame and unit. Negative values are valid because the absolute changes are taken after subtracting corresponding coordinates; coordinates should not be converted to absolute positions before computing the differences.

Only the endpoint coordinates are used. The formula does not ask which axis to move first, because every ordering has the same total length when all axis-aligned moves are available and cost is proportional to distance. If turns carry a cost, movement is blocked, or some axes have different travel rates, this unweighted distance will not capture those rules.

Worked examples

Example 1 · equal changes on three axes

Inputs: P₁=(1,2,3), P₂=(5,6,7).

Calculation: |Δx|+|Δy|+|Δz|=4+4+4=12. Euclidean distance=√48≈6.9282.

Manhattan distance=12.0000 coordinate units.

Example 2 · negative movement on one axis

Inputs: P₁=(−2,4,1), P₂=(3,−1,4).

Calculation: Absolute changes are (5,5,3); total=5+5+3=13.

Manhattan distance=13.0000; the Euclidean comparison is √59≈7.6811.

A displacement of four units on each of three axes totals 12 Manhattan units, compared with a shorter Euclidean segment.
The city-block and straight-line metrics answer different route questions.

Compare it with a direct segment

For a displacement with component changes Δx, Δy, Δz, Manhattan distance is |Δx|+|Δy|+|Δz|, while Euclidean distance is √(Δx²+Δy²+Δz²). Squaring the sum of absolute components produces the sum of squares plus nonnegative cross terms, so the Manhattan value cannot be smaller. If two or three axes change, the gap reflects the unavailable diagonal shortcut.

For (1,2,3) to (5,6,7), every component changes by 4. The city-block total is 12, while the direct segment is √(16+16+16)=√48≈6.9282. If only x changes by 4 and y,z remain fixed, both metrics return 4. That one-axis check is a useful sanity test.

A second route example

From P₁=(−2,4,1) to P₂=(3,−1,4), the signed changes are (5,−5,3), so the absolute axis travel is 5+5+3=13. A valid axis-aligned path can move five units in x, five in y, and three in z in any order; its total length stays 13 as long as each segment is counted once.

The Euclidean comparison is √(25+25+9)=√59≈7.6811. This is not evidence that one metric is wrong: they answer different movement questions. A warehouse robot restricted to perpendicular aisles may care about the first; a laser measurement between endpoints uses the second.

When scaling or weighting changes the answer

Unweighted Manhattan distance assumes a unit of x, y, and z each represents the same cost. If coordinates mix meters and centimeters, convert them before adding. If motion along z is twice as costly as motion along x, a weighted metric may be more suitable, but the current calculator does not accept weights or costs and should not be described as computing that alternative.

In data analysis, an L₁ distance across features can be dominated by columns with large numerical scales. Standardization or a domain-specific weighting may be needed, and the choice changes the meaning of similarity. In a physical grid, however, preserving actual lengths may be the right choice. Decide whether the coordinates represent comparable distances or merely coded features.

Check the output against the path rule

The runtime displays the total to four decimal places and lists the absolute change for each axis. Add those displayed components as a quick check, while remembering they are rounded. Reversing the two endpoints should leave the total and each absolute component unchanged. Translating both endpoints by the same vector should also preserve the result.

A common mistake is to square the differences and take a root, which computes Euclidean distance instead. Another is to add signed differences, letting positive and negative movement cancel. Use absolute values before summing. If a route has obstacles, one-way passages, or unequal step costs, compute over that graph or cost model instead of treating endpoint distance as the actual route length.

Sources and further reading

Share this article

Browse all articles · Calculator: 3D Manhattan distance calculator