The formula
d = √((x₂ − x₁)² + (y₂ − y₁)²)
Why it works
Draw the horizontal and vertical differences between two points and you have made a right triangle whose hypotenuse is the distance. The formula is Pythagoras and nothing more; the squares are what make the signs of the differences irrelevant.
How to solve it by hand
- Subtract the x values and square the result
- Subtract the y values and square that too
- Add the two squares
- Take the square root
What is worth knowing
The squaring is doing quiet work: it makes the order of the points irrelevant, since (−3)² and 3² are the same. That is why you never need to worry about which point you call first. The formula extends to three dimensions by adding a (z₂ − z₁)² term, and to any number of dimensions the same way — which is how distance works in machine learning, where 'points' routinely have hundreds of coordinates. It is worth knowing that other distances exist: Manhattan distance adds the absolute differences instead of squaring, and it is the right one when you can only travel along a grid.