You already know how to measure distance along a straight road. Walk 3 blocks east. You traveled 3 blocks. Simple.
But what if you cut across the corner diagonally?
That diagonal shortcut is harder to measure. You can't count blocks. But there's a way to figure it out exactly, and it uses a result you probably learned in school but may have never connected to this problem: the Pythagorean theorem.
The city-blocks intuition
Picture a grid city. You're at intersection A. Your friend is at intersection B, somewhere to the northeast. To get there on foot, you have to follow the streets, walking east some number of blocks, then north.
Let's say A is at coordinates and B is at . Walking the grid, you go 3 blocks east and 4 blocks north — for a total of 7 blocks.
But you're a bird. You fly straight from A to B. How far is that diagonal path?
That's the question the distance formula answers.
Drag either point. The right triangle forms automatically — the two legs are Δx and Δy, and the hypotenuse is the distance.
Drag the two points around. Watch what happens. The moment you place two points, a right triangle appears automatically. The horizontal leg is how far you travel east. The vertical leg is how far you travel north. The diagonal — the hypotenuse — is the actual straight-line distance.
The distance formula is just the Pythagorean theorem, dressed up in coordinate language.
Why the right triangle always appears
Here's the key observation. Given any two points and , we can always build a right triangle with:
- A horizontal leg from to the corner point
- A vertical leg from straight up to
- The hypotenuse from directly to
The corner sits at the same height as and the same horizontal position as . You can always find it. It always makes a right angle.
The length of the horizontal leg is — the horizontal gap between the two points. The length of the vertical leg is — the vertical gap.
We write these as ("delta x") and ("delta y"). The symbol just means "change in."
The Pythagorean theorem, quickly
Before we apply it, let's make sure the theorem itself is vivid.
Take a right triangle with legs and and hypotenuse . Build a square on each side. The theorem says the two smaller squares together have exactly the same area as the big square.
Press Play to see squares grow on each side of the triangle. The two smaller squares fill exactly as much area as the big one.
Adjust with the slider, then hit Play. Watch the squares materialize. The two colored squares — one on each leg — always fill exactly as much space as the square on the hypotenuse. Change to any value. It always works.
This isn't a coincidence. It's a geometric fact, and it's been proven hundreds of different ways since Euclid. For our purposes, the key point is this: if you know two legs, you can always find the hypotenuse.
Deriving the formula, one step at a time
Now we have everything we need. Let's put it together slowly.
Step through the derivation one piece at a time. Each click reveals the next building block.
Work through all five steps. Here's the logic in plain English:
- We have two points and .
- We draw a right triangle by dropping a corner at .
- The horizontal leg has length . The vertical leg has length .
- By the Pythagorean theorem, the hypotenuse satisfies:
- Take the square root of both sides. Distance is always positive, so we drop the absolute value signs:
That's it. That's the distance formula.
There's nothing to memorize if you see where it comes from. It's just , where is the horizontal gap and is the vertical gap.
A few things worth noticing
The order of subtraction doesn't matter. and are the same — you're squaring, so the negative sign disappears. Distance from A to B equals distance from B to A.
The formula works in any orientation. If the two points are directly horizontal, and the formula gives — just the horizontal gap. If they're directly vertical, . The formula handles both special cases without modification.
The formula generalizes to three dimensions, too. For points and :
You just add another leg. The triangle becomes a tetrahedron. The logic is identical.
Bonus: the midpoint formula
The distance formula tells you how far apart two points are. But sometimes you want to know the point exactly halfway between them.
That's the midpoint, and it follows directly from the same logic. The midpoint between and is:
Just average the coordinates. Why? Because to get halfway in the horizontal direction, you go to the average of and . Same vertically. The midpoint is the average of both coordinates simultaneously.
Drag either endpoint. The midpoint M is always the average of both coordinates — and it's always exactly halfway between them.
Drag either endpoint. The midpoint M chases along, always landing exactly halfway. Notice that the distance from A to M always equals the distance from M to B — they update live in the stat box.
And if you think about it, this is the distance formula in action: both half-distances are equal because M is defined to split the segment exactly.
The short version
Any two points on a plane form the hypotenuse of a hidden right triangle. The legs are the horizontal gap and the vertical gap . The Pythagorean theorem gives you the hypotenuse — which is the straight-line distance:
You're not memorizing a formula. You're measuring the diagonal of a triangle you can always see.
All visualizations are interactive React components running entirely in your browser. The triangle builder uses drag events mapped to integer grid coordinates. The Pythagorean animation uses requestAnimationFrame with an ease function. No libraries beyond React.