The Straight-Line Distance Almost Never Matches the Grid
Gepubliceerd op 9-11-2026 · 3 min leestijd · Ontwikkelaarstools
Daniel Okonkwo — Front-enddeveloper en techredacteur bij OneKitly
Webprestaties · Bestandsformaten
Getoetst aan 2 bronnen
The straight-line distance between two points is the square root of the squared differences added together — Pythagoras with the two legs read off the coordinates. From (2, 3) to (8, 7) the differences are 6 and 4, giving √52 = 7.211. Walking a street grid instead means covering both differences separately, which is 6 + 4 = 10. The two agree only when the movement is purely horizontal or vertical, and they diverge most when the two differences are equal: at 45° the grid route is √2 times the straight one, about 41 % longer.
From (2, 3) to (8, 7) is 7.21 in a straight line and 10 along the streets. The gap is 39 %, and it is the largest at exactly 45°.
Which distance a program should use
The straight-line figure is right for anything that moves freely — a drone, a signal, a mouse pointer. The grid figure is right for anything constrained to axis-aligned steps, which includes streets in a planned city, moves on a chessboard for a rook, and pixel operations that cannot travel diagonally. Choosing the wrong one produces answers that are consistently 0 to 41 % out, and the error is invisible in testing because both metrics agree on the simple cases people check first. Naming the variable after the metric rather than after the thing measured is the cheap defence.
Both are special cases of one family
Raise each difference to a power, add, then take the matching root: power two gives the straight line, power one gives the grid, and letting the power grow without bound gives the largest single difference on its own. That last one is the right metric for a king on a chessboard, which reaches any adjacent square in one move regardless of direction. The family is used in machine learning as a tuning knob, where the choice of power changes which points count as neighbours and therefore what a model learns — a decision that looks technical and is really about what 'close' means for the data.
| Differences | Straight | Grid |
|---|---|---|
| 6 and 0 | 6.00 | 6 |
| 6 and 4 | 7.21 | 10 |
| 3 and 4 | 5.00 | 7 |
| 1 and 1 | 1.41 | 2 |
Uitgewerkt met onze eigen calculator
Afstand tussen twee punten
Gegeven
- x₁
- 0
- y₁
- 0
- x₂
- 3
- y₂
- 4
Resultaat
- Afstand
- 5
Deze cijfers komen uit de calculator hieronder, ze zijn niet met de hand ingetypt — ze worden opnieuw berekend telkens als de tool verandert.
Reken het door met je eigen cijfers →Veelgestelde vragen
- Why does the grid route never vary with the path taken?
- Because every step either closes horizontal distance or vertical distance, and both totals have to be covered exactly once. Zigzagging block by block and going all the way along one axis before turning give the same length, which is why a taxi fare in a grid city depends on the endpoints rather than on the driver's route. It stops holding as soon as the grid has gaps — a one-way system, a park, a river — and at that point the shortest path becomes a search rather than a subtraction.
- Is the straight line always the shortest?
- On a flat plane, yes, by definition. On a curved surface it is not even available: the shortest path on a sphere is an arc of a great circle, which looks bent on every flat map ever drawn. That is why long-haul flights appear to detour towards the pole — they are following the actual shortest route while the projection distorts it. For distances under a few hundred kilometres the flat formula is close enough that the difference disappears into the measurement error, which is why this calculator is the right tool for a city and the wrong one for an ocean.
Artikelen die je misschien interesseren
Alle gidsen →Vergelijkbare tools
Bronnen
Een fout in dit artikel gezien?