How the distance formula works
Two points form the hypotenuse of a right triangle, with the horizontal difference Δx = x₂ − x₁ as one leg and the vertical difference Δy = y₂ − y₁ as the other. By the Pythagorean theorem the straight-line distance is:
d = √[(x₂ − x₁)² + (y₂ − y₁)²]
The midpoint of a segment is simply the average of the endpoints, ((x₁+x₂)/2, (y₁+y₂)/2) — the one point on the segment equidistant from both ends. The slope of the joining line is Δy ÷ Δx, and when Δx is zero the line is vertical so the slope is undefined.
Worked example
Distance from (0, 0) to (3, 4): Δx = 3, Δy = 4, so d = √(9 + 16) = √25 = 5 — the classic 3-4-5 right triangle, the exact case Pythagoras used. The midpoint is (1.5, 2) and the slope is 4 ÷ 3 ≈ 1.333. Two points like (2, 5) and (8, 1) give Δx = 6, Δy = −4, so d = √(36 + 16) = √52 ≈ 7.211 and the slope is −0.667, a line falling to the right.
Where this shows up in real work
Screen sizes and aspect ratios (is a 16:9 laptop actually 13.3″ wide?), map and floor-plan measurements, vector graphics and game development, machine-vision part picking, and navigation all reduce to this one formula. In 3D, extend it to a third term: d = √(Δx² + Δy² + Δz²).