Learn how to calculate Euclidean and Manhattan distances on a grid
Click any cell to explore heuristic values • Foundation for A* Search√[(x₂-x₁)² + (y₂-y₁)²]
|x₂-x₁| + |y₂-y₁|
Both calculations
Click any cell to see how heuristic distances are calculated from that position to the goal.
Calculates the straight-line distance between two points, like measuring with a ruler on a map. This is the shortest possible distance "as the crow flies".
No cell selected
| Position | Euclidean | Manhattan | Difference |
|---|---|---|---|
| Click cells to compare distances | |||
Euclidean: Always ≤ Manhattan distance
Manhattan: Only horizontal/vertical moves
Equal when: Moving only horizontally OR vertically
Biggest difference: On pure diagonals
Heuristics are "educated guesses" about the cost to reach a goal from any position.
Why use them? Help AI algorithms like A* search more efficiently by focusing on promising directions.
h = √[(x₂-x₁)² + (y₂-y₁)²]
h = |x₂-x₁| + |y₂-y₁|
The choice of heuristic function depends on your problem constraints. Euclidean works for free movement, Manhattan for grid-constrained movement. Understanding these basics prepares you for advanced AI search algorithms like A*!