Coordinate Geometry
Manhattan distance
The distance travelled along a grid rather than in a straight line, which is what a taxi actually drives.
Last updated
The Formula
distance = |x2 - x1| + |y2 - y1|
The distance travelled along a grid rather than in a straight line, which is what a taxi actually drives.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| d1 | Manhattan distance | units | Grid distance between the points. |
| x1 | First x | units | Horizontal coordinate of the first point. |
| y1 | First y | units | Vertical coordinate of the first point. |
| x2 | Second x | units | Horizontal coordinate of the second point. |
| y2 | Second y | units | Vertical coordinate of the second point. |
What Each Symbol Means
d1units
Manhattan distance
Grid distance between the points.
x1units
First x
Horizontal coordinate of the first point.
y1units
First y
Vertical coordinate of the first point.
x2units
Second x
Horizontal coordinate of the second point.
y2units
Second y
Vertical coordinate of the second point.
See It Worked With Real Numbers
A formula on its own does not tell you which number goes where. The how to calculate the distance between two points page applies this equation to a concrete case, shows every intermediate step, and names the mistakes that produce a wrong answer even when the algebra is right.
Where This Formula Appears
This equation is the working core of How To Calculate The Distance Between Two Points, filed under Math. Every number the guide produces comes from substituting into this one line.
Common Questions
What is the formula for Manhattan distance?
The formula for Manhattan distance is distance = |x2 - x1| + |y2 - y1|. The distance travelled along a grid rather than in a straight line, which is what a taxi actually drives.
What does each symbol in Manhattan distance stand for?
d1 is manhattan distance; x1 is first x; y1 is first y; x2 is second x; y2 is second y.
What units should I use with Manhattan distance?
Substitute d1 in units, x1 in units, y1 in units, x2 in units, y2 in units. Convert every input to those units before you start, because the equation only returns the right answer when the units on both sides agree.
What is a common mistake when using Manhattan distance?
Forgetting the square root. Without the final root you have the squared distance, which is a different quantity and is out by the square of the answer.