How far apart are two points on a grid? Suppose the first is at
(x_1, y_1) and the second at
(x_2, y_2). The horizontal gap between
them is x_2 - x_1, and the vertical gap is
y_2 - y_1.
Those two gaps are the legs of a right-angled triangle, and the straight-line
distance between the points is its hypotenuse. So the distance is just
Pythagoras' theorem
applied to the grid:
d = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}
For points (x_1, y_1) and (x_2, y_2):
- the horizontal leg is x_2 - x_1;
- the vertical leg is y_2 - y_1;
-
the distance is d = \sqrt{\text{leg}_1^2 + \text{leg}_2^2}
— exactly Pythagoras' theorem.