Distance Between Two Points
Two friends drop pins on a map. One café is at grid reference
(1, 1), the other bus stop at (5, 4).
A perfectly reasonable question: how far apart are they — not "4 streets across
and 3 up", but the single straight-line distance a bird would fly?
The distance formula answers exactly that. Feed it two coordinate pairs and it
hands back one number: the length of the straight line joining them. And here's the lovely secret —
it isn't a brand-new rule you have to memorise from scratch. It's
Pythagoras' theorem
wearing a disguise.
d = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}
Why it's really just Pythagoras
Put your two points on a grid. Suppose the first is at
(x_1, y_1) and the second at
(x_2, y_2). Slide across from one to the other, then straight up (or
down): the horizontal gap is x_2 - x_1 and the
vertical gap is y_2 - y_1.
Those two gaps meet at a right angle — they are the two legs of a right-angled triangle.
The straight-line distance you want is the hypotenuse stretched across from corner to
corner. Pythagoras says the hypotenuse squared equals the sum of the two legs squared, so:
d^2 = (x_2-x_1)^2 + (y_2-y_1)^2 \quad\Longrightarrow\quad 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.
Worked example 1: a clean answer
Back to the café at A = (1, 1) and the bus stop at
B = (5, 4). The horizontal gap is
5 - 1 = 4 and the vertical gap is
4 - 1 = 3. Square them, add, and take the root:
d = \sqrt{4^2 + 3^2} = \sqrt{16 + 9} = \sqrt{25} = 5
Five units apart — a tidy whole number because 3, 4, 5 is the most
famous right triangle there is. Step through the figure and watch the two gaps snap together into
that triangle, with the distance as its hypotenuse.
Worked example 2: an answer that stays a surd
Most real distances aren't whole numbers, and that's completely fine — you just leave the root in.
Find the distance between P = (2, 1) and
Q = (5, 7).
- Horizontal gap: 5 - 2 = 3.
- Vertical gap: 7 - 1 = 6.
- Square and add: 3^2 + 6^2 = 9 + 36 = 45.
d = \sqrt{45} = \sqrt{9 \times 5} = 3\sqrt{5} \approx 6.7
So the exact distance is 3\sqrt{5}, or about
6.7 if you want a decimal. A square-root answer isn't a mistake — it's
often the most exact way to write the length.
Worked example 3: two towns on a map
A hiking map is printed with a kilometre grid. Ashford sits at
(3, 2) and Brookton at (12, 14), where each
unit is one kilometre. As the crow flies, how far is the walk?
- East–west gap: 12 - 3 = 9 km.
- North–south gap: 14 - 2 = 12 km.
- Distance: \sqrt{9^2 + 12^2} = \sqrt{81 + 144} = \sqrt{225} = 15 km.
Fifteen kilometres in a straight line. (Notice 9, 12, 15 is just the
3, 4, 5 triangle scaled up by three — right triangles love to repeat.)
The distance formula has three classic traps. Dodge all three and you'll never lose a mark:
-
Don't forget the final square root. After you square and add you have
d^2, not d. In example 1,
16 + 9 = 25 is the distance squared; the distance itself is
\sqrt{25} = 5. Stopping at 25 is the single most common slip.
-
Squaring makes the order of subtraction not matter. Whether you do
1 - 5 = -4 or 5 - 1 = 4, squaring gives the
same 16 — because (-4)^2 = (4)^2. So you
can subtract either way round without worrying about the sign.
-
Never mix an x with a y.
Keep all your x-differences in one bracket and all your
y-differences in the other. Subtracting an x
from a y is like measuring "3 metres minus 2 kilograms" — it's
meaningless.
This exact formula is running, right now, millions of times a second, inside games and apps you use
every day. When a video game asks "is the enemy close enough to attack?" or "which health pack is
nearest?", it's computing the distance between two (x, y) points. Your
phone's maps app does the same to sort shops by how close they are.
Programmers even have a speed trick: taking a square root is slow for a computer. But if
you only need to know which of two things is closer — not the actual distance — you can
compare the squared distances and skip the root entirely. Since squaring keeps the
order the same (bigger distance ⇒ bigger squared distance), the winner is the same either way. This
one shortcut powers collision detection in games and "nearest-neighbour" search in AI, where a
program hunts for the data point most similar to yours. Pythagoras, quietly running the modern
world.