Math 8 · 8.G.B.8 · G.GPE.B.7

The distance formula

Two points sit on a grid, but neither is straight across from the other nor straight above it. How far apart are they?

Where you are 9 in Coordinate geometry

Why this exists

On a number line, distance is a subtraction. Points at 2 and 9 are 9 - 2 = 7 apart, and taking the absolute value of the difference handles any order and any signs (Distance on a number line). On the The coordinate plane the same subtraction still works whenever two points share a row or share a column, because then the segment between them lies along a grid line.

Most pairs of points do neither. The points (1, 3) and (13, 8) are joined by a slanted segment that cuts through grid squares at awkward places, and no row of unit squares lies along it to be counted. A ruler on paper would give an estimate, but not an exact length, and not one that works for points too far apart to draw.

The way through is a right triangle. Go from the first point straight across, then straight up, to the second. Both of those moves run along grid lines, so their lengths can be counted. Together with the slanted segment they make a right triangle, and the The Pythagorean theorem turns the two legs into the third side. The distance formula is nothing more than that triangle written once in letters, so that it works for any two points without drawing anything.

Definition

The distance between two points P and Q is the length of the segment \overline{PQ} that joins them, written PQ. A distance is never negative, and it is 0 only when P and Q are the same point.

Two cases need only subtraction, as on a number line (Horizontal and vertical distance):

  • Points in the same row have the same y-coordinate. The distance between (x_1, y) and (x_2, y) is |x_2 - x_1|.
  • Points in the same column have the same x-coordinate. The distance between (x, y_1) and (x, y_2) is |y_2 - y_1|.

For any other pair, P(x_1, y_1) and Q(x_2, y_2), take the corner point R(x_2, y_1). It has P’s y-coordinate, so it is in P’s row, and Q’s x-coordinate, so it is in Q’s column. The triangle PRQ has a right angle at R, because \overline{PR} is horizontal and \overline{RQ} is vertical. Its legs are PR = |x_2 - x_1|, the change in x, and RQ = |y_2 - y_1|, the change in y. Its hypotenuse is PQ, the distance wanted.

Intuition

P(1, 3)
Q(13, 8)
R(13, 3)
12
5
d
x
y
Figure 1Across 12, up 5. The slanted segment is the hypotenuse of a right triangle whose legs are counted on the grid.

Take P(1, 3) and Q(13, 8). Starting at P, count 12 squares to the right to reach the column of Q; that lands on the corner R(13, 3). From R, count 5 squares up to reach Q. Those two walks are the legs of a right triangle, and the slanted segment \overline{PQ} is its hypotenuse. So

PQ^2 = 12^2 + 5^2 = 144 + 25 = 169,

and PQ = 13. Nothing was measured with a ruler. Both legs were read off the grid, and the theorem did the rest.

Two things are worth seeing in the picture. First, the two leg lengths are differences of coordinates: 12 = 13 - 1 is the change in x, and 5 = 8 - 3 is the change in y. Second, the triangle could just as well have been drawn the other way, going up from P first and then across, with its corner at (1, 8). That triangle is the same size and shape turned half a turn, with the same legs 5 and 12, so it gives the same answer.

When the two points share a row, the “triangle” has no height at all: the up-leg is 0 and the hypotenuse lies flat along the across-leg. The theorem still agrees, since \displaystyle \sqrt{a^2 + 0^2} = a for a length a. Horizontal and vertical distances are the flattened special cases of the same picture.

A(-6, 5)
B(3, 5)
C(5, -3)
D(5, 7)
9
10
x
y
Figure 2Points in the same row, or in the same column, need no triangle. Subtract the coordinates that differ.

Results

Horizontal and vertical distance. Two points in the same row are |x_2 - x_1| apart. Two points in the same column are |y_2 - y_1| apart.

The distance formula. The distance between (x_1, y_1) and (x_2, y_2) is

d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}.

Order does not matter. Swapping which point is called first changes the sign of each difference but not its square, so the distance from P to Q equals the distance from Q to P.

(x_1, y_1)
(x_2, y_2)
(x_2, y_1)
x_2 - x_1
y_2 - y_1
d
Figure 3The same triangle for any two points. The corner shares its row with the first point and its column with the second.
Why it is true

Let the points be P(x_1, y_1) and Q(x_2, y_2), and suppose first that they share neither a row nor a column, so x_1 \ne x_2 and y_1 \ne y_2.

Take the corner R(x_2, y_1). The points P and R have the same y-coordinate, so \overline{PR} is horizontal and lies along a copy of the x-axis; its length is the number-line distance |x_2 - x_1|. The points R and Q have the same x-coordinate, so \overline{RQ} is vertical, with length |y_2 - y_1|. A horizontal segment and a vertical segment meet at a right angle, so triangle PRQ is a right triangle with hypotenuse \overline{PQ}. By the Pythagorean theorem,

PQ^2 = |x_2 - x_1|^2 + |y_2 - y_1|^2.

Squaring a number and squaring its absolute value give the same result, because a number and its absolute value differ at most in sign, and (-a)^2 = a^2. So the absolute value bars can be dropped:

PQ^2 = (x_2 - x_1)^2 + (y_2 - y_1)^2.

PQ is a length, so it is the square root that is not negative:

PQ = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}.

The same squaring step explains why the order of the points does not matter. Calling Q the first point turns x_2 - x_1 into x_1 - x_2 = -(x_2 - x_1), and a number and its negative have the same square.

If the points share a row, there is no triangle, but the formula still holds: y_2 - y_1 = 0, and \displaystyle \sqrt{(x_2 - x_1)^2 + 0} = |x_2 - x_1|, which is the number-line distance. Sharing a column works the same way. If the points coincide, both differences are 0 and the formula gives 0. So the formula is true for every pair of points in the plane.

Worked examples

Examples 1 to 3 are the first day: draw the right triangle on the grid, count its legs, and use the theorem. Examples 4 to 7 are the second day: the same steps written once as the formula, then used for points in every quadrant, for perimeters, and for telling what kind of triangle three points make.

Example 1

Counting the legs on the grid

Find the distance between P(1, 3) and Q(13, 8), the points in Figure 1.

Solution

The points are in different rows and different columns, so draw the right triangle. The corner R(13, 3) is in P’s row and Q’s column.

The across-leg runs from x = 1 to x = 13 along one row, so its length is 13 - 1 = 12. The up-leg runs from y = 3 to y = 8 along one column, so its length is 8 - 3 = 5. The angle at R is a right angle because one leg is horizontal and the other vertical. By the Pythagorean theorem,

PQ^2 = 12^2 + 5^2 = 144 + 25 = 169.

A length is not negative, so \displaystyle PQ = \sqrt{169} = 13.

Check: 5, 12, 13 is a Pythagorean triple, since 25 + 144 = 169.

Example 2

Same row, same column

In Figure 2, find AB for A(-6, 5) and B(3, 5), and CD for C(5, -3) and D(5, 7).

Solution

A and B both have y-coordinate 5, so they lie in one row and the segment between them is horizontal. Its length is the distance between -6 and 3 on a number line:

AB = |3 - (-6)| = |9| = 9.

Counting confirms it: 6 squares from x = -6 to the y-axis, then 3 more.

C and D both have x-coordinate 5, so they lie in one column:

CD = |7 - (-3)| = |10| = 10.

The theorem gives the same answers with one leg of length 0. For \overline{AB} the change in y is 5 - 5 = 0, and \displaystyle \sqrt{9^2 + 0^2} = \sqrt{81} = 9.

Example 3

Starting from either end

Find the distance between S(2, 7) and T(7, 4). Then work it again starting from T, and explain why the answer is the same.

Solution

From S to T, the change in x is 7 - 2 = 5 and the change in y is 4 - 7 = -3. The negative sign says that T is lower than S; the vertical leg is 3 squares long. So

ST^2 = 5^2 + (-3)^2 = 25 + 9 = 34,

and \displaystyle ST = \sqrt{34}. Since 5^2 = 25 and 6^2 = 36, this lies between 5 and 6; a calculator gives \displaystyle \sqrt{34} \approx 5.83.

Starting from T instead, the changes are 2 - 7 = -5 and 7 - 4 = 3. Both signs flip, and both squares stay the same:

(-5)^2 + 3^2 = 25 + 9 = 34.

The squaring removes the sign, so the order of the points never matters.

Example 4

The formula with negative coordinates

Find the distance between M(-5, -2) and N(7, 3).

Solution

Take M as (x_1, y_1) and N as (x_2, y_2). Subtracting a negative number is adding its opposite, so the brackets matter:

\begin{aligned} x_2 - x_1 &= 7 - (-5) = 12, \\ y_2 - y_1 &= 3 - (-2) = 5. \end{aligned}

These are the leg lengths of the right triangle: from x = -5 to x = 7 is 5 squares to the y-axis and 7 beyond it, 12 in all. Then

\begin{aligned} MN &= \sqrt{12^2 + 5^2} \\ &= \sqrt{144 + 25} = \sqrt{169} = 13. \end{aligned}

The formula did exactly what the drawing would have done: one subtraction for each leg, the theorem, and a square root.

Example 5

A robot’s straight path

A delivery robot crosses a large paved square marked in a grid of 1-meter tiles. It starts at (-3, 2) and must reach a doorway at (4, -2). It can roll straight across the open square. How long is its straight path, and how much shorter is that than following the tile lines across and then down?

Solution

The changes are

\begin{aligned} x_2 - x_1 &= 4 - (-3) = 7, \\ y_2 - y_1 &= -2 - 2 = -4. \end{aligned}

So the straight path is

d = \sqrt{7^2 + (-4)^2} = \sqrt{49 + 16} = \sqrt{65} \approx 8.06 \text{ m}.

Following the tile lines, the robot would go 7 m across and 4 m down, 7 + 4 = 11 m in all. The straight path is the hypotenuse of that same right triangle, so it is shorter, by about 11 - 8.06 = 2.94 m.

Example 6

The perimeter of a triangle on the grid

Find the perimeter of the triangle with vertices A(-4, -2), B(4, -2) and C(1, 2).

Solution

The Perimeter is the sum of the three side lengths, so find each one.

A and B share the y-coordinate -2, so \overline{AB} is horizontal:

AB = |4 - (-4)| = 8.

For \overline{BC}, the changes are 1 - 4 = -3 and 2 - (-2) = 4:

BC = \sqrt{(-3)^2 + 4^2} = \sqrt{25} = 5.

For \overline{AC}, the changes are 1 - (-4) = 5 and 2 - (-2) = 4:

AC = \sqrt{5^2 + 4^2} = \sqrt{41} \approx 6.40.

The perimeter is

8 + 5 + \sqrt{41} = 13 + \sqrt{41} \approx 19.40.

The exact answer keeps \displaystyle \sqrt{41} as it is; the decimal is for a sense of size.

Example 7

What kind of triangle?

Show that P(-2, -1), Q(2, 1) and R(4, -3) are the vertices of a triangle that is both isosceles and right-angled, and name the right angle.

P Q R
x
y
Figure 4Two equal sides and a right angle at Q, both found from the coordinates alone.
Solution

The question is about equal sides and about whether a^2 + b^2 = c^2, so work with the squares of the side lengths and leave the square roots until the end. That keeps every number exact.

SideChange in xChange in yLength squared
PQ2 - (-2) = 41 - (-1) = 216 + 4 = 20
QR4 - 2 = 2-3 - 1 = -44 + 16 = 20
PR4 - (-2) = 6-3 - (-1) = -236 + 4 = 40

Equal squares mean equal lengths, since lengths are not negative. So \displaystyle PQ = QR = \sqrt{20}, and the triangle is isosceles.

The longest side is \overline{PR}, and

PQ^2 + QR^2 = 20 + 20 = 40 = PR^2.

By the converse of the Pythagorean theorem, a triangle whose side lengths satisfy a^2 + b^2 = c^2 is right-angled, and the right angle is opposite the longest side. So the right angle is \angle PQR, at Q.

Rounding first would have hidden this. \displaystyle \sqrt{20} \approx 4.47, and 4.47^2 + 4.47^2 = 39.9618, which is not 40. Exact squares settle the question; rounded lengths cannot.

Boundaries

Both axes must use the same unit. The legs of the triangle are added after squaring, which only makes sense if a step of 1 across and a step of 1 up are the same length. On a graph whose x-axis counts hours and whose y-axis counts kilometers, \displaystyle \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} adds hours to kilometers and measures nothing. The same goes for a map whose grid cells are rectangles rather than squares: the formula must first convert both changes to one unit.

It measures the straight path in a flat plane. It gives the length of the segment, not the length of a route that has to follow streets or grid lines, which is |x_2 - x_1| + |y_2 - y_1| and is longer unless the points share a row or column. It also assumes a flat surface: the distance between two cities from their latitude and longitude is not this formula, because the Earth is curved.

It is for two coordinates. Points in space have three coordinates, and the distance between them needs a third squared difference under the root (Coordinates and distance in three dimensions).

The result is a length. The square root is the one that is not negative, and the answer is 0 only when the two points are the same.

Where this goes next

The distance formula is the bridge between drawing and computing. With it, any length in a figure on the grid becomes a calculation, so perimeters of polygons follow at once, and so does deciding what kind of quadrilateral four points make, using equal sides together with slopes. Writing the corners of a figure with letters instead of numbers turns the formula into a tool for proving theorems with coordinates.

A circle is every point at one fixed distance from a center. Setting the distance formula equal to that radius gives the equation of a circle directly. In the same way, a parabola is every point as far from a fixed point as from a fixed line (The parabola as a locus), and the formula measures one of those two distances. The length of an arrow drawn on the grid, its magnitude, is the same calculation, and in space a third term joins the sum (Coordinates and distance in three dimensions). The shortest distance from a point to a whole line, rather than to another point, is a separate question with its own answer (Distance from a point to a line).

A close cousin answers a different question about the same two points: not how far apart they are, but where the point halfway between them sits. That is the midpoint, and the midpoint formula finds it by averaging the coordinates rather than subtracting them.

Exercises

Part 1: distances on the grid

Draw each pair of points on a grid, draw the right triangle, count its legs and find the distance. Give an exact answer, and a decimal to two places when it is not a whole number.

  1. (4, 3) and (7, 7)
  2. (0, 2) and (5, 14)
  3. (-6, 3) and (-6, -8)
  4. (-7, -2) and (5, -2)
  5. (1, 6) and (3, 2)
  6. (0, 0) and (6, 7)
  7. Find the distance from (7, 2) to (2, 9), and then from (2, 9) to (7, 2). Write down both changes in x and both changes in y, and show where the two calculations agree.
  8. A chess knight jumps two squares in one direction and one square at right angles to it. On a board whose squares are 5 cm on each side, how far does the center of the knight’s square move in one jump, in a straight line?
  9. Name the four points that are exactly 6 units from (3, -4) and lie in the same row or the same column as it.

Part 2: the formula

Use the distance formula. Give exact answers, with a decimal to two places when the answer is not a whole number.

  1. (-3, -4) and (5, 2)
  2. (-7, 1) and (-2, -11)
  3. (4, -6) and (-4, 9)
  4. (-3, -5) and (0, 2)
  5. (0, -3) and (-6, 0)
  6. (-4.5, 2) and (1.5, -6)

Part 2: perimeters and kinds of triangle

  1. Find the perimeter of the quadrilateral with vertices (-1, 2), (2, 6), (5, 2) and (2, -2), taken in that order.
  2. Find the perimeter of the triangle with vertices K(-4, -3), L(2, -3) and M(1, 3).
  3. Is the triangle with vertices A(-5, 2), B(-2, 3) and C(-4, 5) isosceles? Is it right-angled?
  4. Is the triangle with vertices P(-2, -4), Q(4, -1) and R(2, 3) isosceles? Is it right-angled? If it is right-angled, at which vertex?
  5. Is the triangle with vertices S(-2, -3), T(3, -2) and U(0, 1) isosceles, right-angled, both or neither?

Part 2: a missing coordinate

  1. The point (1, y) is 5 units from (4, 2). Find every possible value of y.
  2. Find the point on the x-axis that is the same distance from (0, 5) as from (7, 2).

Reasoning

  1. Explain why (x_2 - x_1)^2 and (x_1 - x_2)^2 are always equal, and what this says about the order in which two points are named.
  2. Explain why the straight-line distance between two points is never longer than the route that goes across and then up along grid lines, and say exactly when the two are equal.
  3. Two points share a row: (x_1, y) and (x_2, y). Show that the distance formula gives |x_2 - x_1|, the number-line distance.
Answers
  1. 5. Across 7 - 4 = 3, up 7 - 3 = 4, and \displaystyle \sqrt{3^2 + 4^2} = \sqrt{25} = 5.
  2. 13. Across 5 - 0 = 5, up 14 - 2 = 12, and \displaystyle \sqrt{25 + 144} = \sqrt{169} = 13.
  3. 11. Same column, so |3 - (-8)| = 11.
  4. 12. Same row, so |5 - (-7)| = 12.
  5. \displaystyle \sqrt{20} \approx 4.47. Across 3 - 1 = 2, down 6 - 2 = 4, and \displaystyle \sqrt{4 + 16} = \sqrt{20}.
  6. \displaystyle \sqrt{85} \approx 9.22. Across 6, up 7, and \displaystyle \sqrt{36 + 49} = \sqrt{85}.
  7. \displaystyle \sqrt{74} \approx 8.60 both ways. From (7, 2) the changes are 2 - 7 = -5 and 9 - 2 = 7; from (2, 9) they are 7 - 2 = 5 and 2 - 9 = -7. The signs differ, but the squares are 25 and 49 both times, so each distance is \displaystyle \sqrt{25 + 49} = \sqrt{74}.
  8. \displaystyle \sqrt{125} \approx 11.18 cm. The center moves 2 \times 5 = 10 cm one way and 5 cm at right angles, so \displaystyle \sqrt{10^2 + 5^2} = \sqrt{125}.
  9. (9, -4), (-3, -4), (3, 2) and (3, -10). In the same row, x = 3 + 6 or 3 - 6; in the same column, y = -4 + 6 or -4 - 6.
  10. 10. Changes 5 - (-3) = 8 and 2 - (-4) = 6, and \displaystyle \sqrt{64 + 36} = \sqrt{100} = 10.
  11. 13. Changes -2 - (-7) = 5 and -11 - 1 = -12, and \displaystyle \sqrt{25 + 144} = \sqrt{169} = 13.
  12. 17. Changes -4 - 4 = -8 and 9 - (-6) = 15, and \displaystyle \sqrt{64 + 225} = \sqrt{289} = 17.
  13. \displaystyle \sqrt{58} \approx 7.62. Changes 0 - (-3) = 3 and 2 - (-5) = 7, and \displaystyle \sqrt{9 + 49} = \sqrt{58}.
  14. \displaystyle \sqrt{45} \approx 6.71. Changes -6 - 0 = -6 and 0 - (-3) = 3, and \displaystyle \sqrt{36 + 9} = \sqrt{45}.
  15. 10. Changes 1.5 - (-4.5) = 6 and -6 - 2 = -8, and \displaystyle \sqrt{36 + 64} = \sqrt{100} = 10.
  16. 20. Each side has changes of 3 and 4 in size (for example (-1, 2) to (2, 6) is 3 across and 4 up), so each side is \displaystyle \sqrt{9 + 16} = 5, and 4 \times 5 = 20.
  17. \displaystyle 6 + \sqrt{37} + \sqrt{61} \approx 19.89. KL = |2 - (-4)| = 6 (same row); \displaystyle LM = \sqrt{(-1)^2 + 6^2} = \sqrt{37}; \displaystyle KM = \sqrt{5^2 + 6^2} = \sqrt{61}.
  18. Isosceles, not right-angled. AB^2 = 3^2 + 1^2 = 10, BC^2 = (-2)^2 + 2^2 = 8, AC^2 = 1^2 + 3^2 = 10. So \displaystyle AB = AC = \sqrt{10}. The largest square is 10, and 10 + 8 = 18 \ne 10, so it is not right-angled.
  19. Not isosceles; right-angled at Q. PQ^2 = 6^2 + 3^2 = 45, QR^2 = (-2)^2 + 4^2 = 20, PR^2 = 4^2 + 7^2 = 65. All three differ, and 45 + 20 = 65, so by the converse the right angle is opposite \overline{PR}, at Q.
  20. Neither. ST^2 = 5^2 + 1^2 = 26, TU^2 = (-3)^2 + 3^2 = 18, SU^2 = 2^2 + 4^2 = 20. All three differ, and 18 + 20 = 38 \ne 26.
  21. y = 6 or y = -2. (4 - 1)^2 + (y - 2)^2 = 25 gives (y - 2)^2 = 16, so y - 2 = 4 or y - 2 = -4.
  22. (2, 0). A point (x, 0) needs x^2 + 25 = (x - 7)^2 + 4. Expanding, x^2 + 25 = x^2 - 14x + 53, so 14x = 28 and x = 2. Check: both squared distances are 29.
  23. x_1 - x_2 = -(x_2 - x_1), so the two differences are opposites, and a number and its opposite have the same square because (-a)^2 = (-a)(-a) = a^2. The same holds for the y-differences, so the formula gives the same distance whichever point is named first.
  24. Let the legs be a = |x_2 - x_1| and b = |y_2 - y_1|. The route along grid lines is a + b, and (a + b)^2 = a^2 + 2ab + b^2, which is at least a^2 + b^2 = d^2 because 2ab is not negative. Two lengths that are not negative compare the same way as their squares, so d \le a + b. They are equal exactly when 2ab = 0, that is, when a = 0 or b = 0: the points share a row or a column.
  25. The changes are x_2 - x_1 and y - y = 0, so \displaystyle d = \sqrt{(x_2 - x_1)^2 + 0} = \sqrt{(x_2 - x_1)^2}. The square root that is not negative of a number’s square is that number’s absolute value, so d = |x_2 - x_1|.
kg1128 · updated 2026-10-09 · CC-BY-SA-4.0