The distance between two points

The distance between two points in the coordinate plane comes from the Pythagorean theorem1. Here we find the distance between A(1,2)A(1, 2) and B(4,6)B(4, 6).

Building a right triangle

Going from AA to BB moves 41=34 - 1 = 3 across and 62=46 - 2 = 4 up. Taking these horizontal and vertical differences as the two legs of a right triangle, the segment joining AA and BB is its hypotenuse.

AB=32+42=25=5AB = \sqrt{3^2 + 4^2} = \sqrt{25} = 5

The familiar right triangle with sides in the ratio 3:4:53 : 4 : 5 has appeared.

The general formula

(x2x1)2+(y2y1)2\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

Because the differences are squared, it does not matter if x2x1x_2 - x_1 is negative: naming the points in either order gives the same distance.

SituationFormula
General pair of points(x2x1)2+(y2y1)2\sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}
Distance from the originx2+y2\sqrt{x^2 + y^2}
On the number linex2x1|x_2 - x_1|

The distance from the origin is what the absolute value on the number line becomes in the plane.

The midpoint

The same two points also give the midpoint of the segment, whose coordinates are the averages of the xx values and of the yy values.

(1+42,2+62)=(52,4)\left(\frac{1 + 4}{2}, \frac{2 + 6}{2}\right) = \left(\frac{5}{2}, 4\right)

The equation of a circle

A circle is the set of points at distance rr from a center (a,b)(a, b), so (xa)2+(yb)2=r\sqrt{(x - a)^2 + (y - b)^2} = r, and squaring gives the familiar equation.

(xa)2+(yb)2=r2(x - a)^2 + (y - b)^2 = r^2

The equation of a circle is nothing but the distance formula rewritten.

Identifying a triangle

Identifying the shape of a triangle from three points also begins here, by computing its three side lengths.

Condition on the sidesThe triangle is
two sides equalisosceles
a2+b2=c2a^2 + b^2 = c^2 for the longest side ccright-angled
all three sides equalequilateral

The distance is 00 only when the two points coincide; otherwise it is always positive.

Extending to space

In three dimensions you add the square of the difference in zz. This is the Euclidean distance2, and it remains the basic tool in applications such as nearest-neighbor search, where the closest data point is the one to find.

The large dots on the graph are AA and BB, and the length of the segment joining them is the distance 55 we found.

  1. Pythagorean theorem, Wikipedia
  2. Euclidean distance, Wikipedia