On a city grid you cannot cut diagonally through blocks, so the distance is the sum of the east–west and north–south moves. Manhattan (L1, taxicab) distance is also used in machine learning, chess-like games and warehouse routing.
How to use the Manhattan Distance Calculator
- Dimensionality
- x₁
- y₁
- z₁
- w₁
- x₂
- y₂
- z₂
- w₂
Results update as you type, and everything is calculated in your browser.
How it works
The absolute differences in each coordinate are added. For comparison the Euclidean (straight-line) and Chebyshev (largest single difference) distances are also shown.
Inputs explained
| Field | What to enter |
|---|---|
| Dimensionality | Choose one: 1D, 2D, 3D, 4D |
| x₁ | A number |
| y₁ | A number |
| z₁ | A number |
| w₁ | A number |
| x₂ | A number |
| y₂ | A number |
| z₂ | A number |
| w₂ | A number |
Example values
How the main result changes when x₁ changes and everything else stays at the example values above:
| x₁ | Manhattan distance |
|---|---|
| 0.5 | 7.5 |
| 0.75 | 7.25 |
| 1 | 7 |
| 1.25 | 6.75 |
| 1.5 | 6.5 |
| 2 | 6 |
Formula
d = |x₁ − x₂| + |y₁ − y₂| + |z₁ − z₂| + |w₁ − w₂|
Worked example
Inputs: Dimensionality: 2D; x₁: 1; y₁: 1; x₂: 4; y₂: 5.
Results: Manhattan distance = 7; Euclidean distance = 5; Chebyshev distance = 4.
Key terms
- Taxicab geometry
- Geometry with the Manhattan distance.
Frequently asked questions
Why is it called Manhattan distance?
Because of Manhattan's grid of streets: you travel along blocks, not diagonally.
Is Manhattan distance ever shorter than straight-line distance?
No, it is always at least as long.
Where is it used?
k-nearest neighbours, clustering, image processing and robot path planning on grids.
What is the L1 norm?
The Manhattan length of a vector, Σ|xᵢ|.