A Manhattan distance calculator finds the distance between two points when you can only move along the axes, like a taxi on a grid of city blocks. It adds up the absolute differences of the coordinates. It also shows the straight-line Euclidean distance and the Chebyshev distance for comparison, and the number of shortest paths on a grid. Enter two points and press the button. The formula follows the Wikipedia page on taxicab geometry, and the work is done in your browser.
How to use the Manhattan distance calculator
- Type the coordinates of point A, separated by commas.
- Type the coordinates of point B, with the same number of coordinates.
- Press Calculate.
The formula
The page defines the taxicab distance between two points p and q as the sum of the absolute values of the differences of their coordinates: d(p, q) = |p₁ − q₁| + |p₂ − q₂| + … + |pₙ − qₙ|. In the plane it is |x₁ − x₂| + |y₁ − y₂|. For the points (0, 0) and (6, 6), it is 6 + 6, which is 12. For (1, 2, 3) and (4, 6, 3), it is 3 + 4 + 0, which is 7. The calculator shows this sum, so that you can see each contribution.
Why it is called taxicab distance
In a city with streets laid out in a grid, a taxi cannot cut across the blocks, so the length of any route between two corners is the number of blocks east or west plus the number north or south. The page makes this point with a grid in which every route between opposite corners has the length 12, while the straight-line distance is 6 times the square root of 2, which is about 8.49. The calculator shows both numbers for (0, 0) and (6, 6): 12 and 8.48528. Their ratio, about 1.414, is the largest possible ratio in the plane, which occurs when the line is at 45 degrees.
Counting the shortest routes
If the points are on whole-number coordinates in the plane, the number of shortest routes along the grid lines is the number of ways to arrange the east-west and the north-south steps. With a steps in one direction and b in the other, that is the number of ways to choose which a of the a + b steps go one way, which is (a + b)!/(a! b!). For (0, 0) and (6, 6) it is 12!/(6! 6!), which is 924. For a 3 by 2 block it is 10. The calculator gives this count whenever both differences are whole numbers.
Comparison with other distances
The Euclidean distance is the straight-line distance, the square root of the sum of the squares of the differences. The Chebyshev distance is the largest single difference, which is the number of moves a chess king needs. For any two points, Chebyshev is at most Euclidean, and Euclidean is at most Manhattan. The three agree when the points differ in only one coordinate. The page also points out an odd feature of the taxicab plane: the set of points at a given distance from a center, the taxicab circle, is a square tilted at 45 degrees, and its circumference is 8 times its radius, so the taxicab value of π is 4.
Where Manhattan distance is used
Manhattan distance is the natural measure for routes on grids, such as city blocks, warehouse aisles and the cells of a board game. In data science it is used to compare data points, where it is less affected by single large differences than the Euclidean distance, and in image processing it appears as the sum of absolute differences of pixel values. The calculator accepts up to 12 coordinates, so it can compare small feature vectors as well as points in the plane.
A worked example in three dimensions
For the points (1, 2, 3) and (4, 6, 3), the differences are 3, 4 and 0, so the Manhattan distance is 7. The Euclidean distance is the square root of 9 + 16 + 0, which is exactly 5, and the Chebyshev distance is 4. The three numbers are in the expected order, 4 for Chebyshev, 5 for Euclidean and 7 for Manhattan. The calculator shows all three so that you can see how much the choice of distance matters for your points.
Typing tips
Separate the coordinates with commas or spaces. Both points must have the same number of coordinates, from 1 to 12. Negative numbers and decimals are allowed. For one-dimensional points, the Manhattan, Euclidean and Chebyshev distances all equal the absolute difference of the two numbers.
Distance in a warehouse or on a board
Suppose a picker walks from the bay at coordinates (2, 3) to the bay at (9, 7), moving only along the aisles. The Manhattan distance is 7 + 4, which is 11 units, while the straight line would be about 8.06. If the aisles are laid out on a grid with whole-number coordinates, the number of different shortest routes is 11!/(7! 4!), which is 330. A game board works the same way: a piece that moves one square at a time along rows and columns needs exactly the Manhattan distance in moves.
Common mistakes
- Forgetting the absolute values. Each difference must be positive.
- Using the straight-line formula. That is the Euclidean distance.
- Giving the points a different number of coordinates. They must match.
- Assuming a single shortest route. There are usually many of the same length.
- Expecting the same circle as the Euclidean one. The taxicab circle is a diamond.
What next
Use this often? Add Manhattan Di to your Home screen.
Frequently asked questions
What is a Manhattan distance calculator?
A tool that finds the distance between two points moving along the axes only: the sum of the absolute differences of the coordinates.
What is the Manhattan distance formula?
d = |x₁ − x₂| + |y₁ − y₂| in the plane, and the sum of |pᵢ − qᵢ| in general. For (0, 0) and (6, 6) it is 12.
How is it different from the Euclidean distance?
Euclidean is the straight-line distance, √(Σ(pᵢ − qᵢ)²). For (0, 0) and (6, 6) it is about 8.49, while the Manhattan distance is 12.
How many shortest paths are there on a grid?
For a and b steps in the two directions, (a + b)!/(a! b!). For 6 and 6 it is 924.
What does a taxicab circle look like?
A square tilted at 45 degrees. Its circumference is 8r, so the taxicab π equals 4.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.