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):

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).

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?

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:

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.