Sub topic 12
The Distance Between Any Two Points
This chapter assumes you can plot ordered pairs, subtract positive and negative numbers, and use square roots. You will use the Pythagorean theorem to find the straight-line distance between two points.
Horizontal and vertical distances
Suppose two points are \(P(x1, y1)\) and \(Q(x2, y2)\). Their coordinates tell you how far apart they are in each direction:
- Horizontal distance: \(\lvert x2 - x1\rvert\)
- Vertical distance: \(\lvert y2 - y1\rvert\)
The absolute value symbol \(\lvert\ \rvert\) means distance from zero, so the result is never negative.
If two points have the same \(y\)-coordinate, they lie on a horizontal line. Their distance is the difference between their \(x\)-coordinates.
For example, the horizontal distance from \((-3, 4)\) to \((5, 4)\) is
\[ \lvert 5 - (-3)\rvert = \lvert 8\rvert = 8. \]
If two points have the same \(x\)-coordinate, they lie on a vertical line. Their distance is the difference between their \(y\)-coordinates.
| Type of segment | Distance |
|---|---|
| Horizontal | \(\lvert x_2-x_1\rvert\) |
| Vertical | \(\lvert y_2-y_1\rvert\) |
The distance formula
When two points are not on the same horizontal or vertical line, draw a right triangle using the points as endpoints of the hypotenuse. The horizontal and vertical distances are the triangle's legs.
The Pythagorean theorem says
\[ a^2+b^2=c^2. \]
Therefore, the distance between \(P(x1,y1)\) and \(Q(x2,y2)\) is
\[ d=\sqrt{(x2-x1)^2+(y2-y1)^2}. \]
The order of subtraction does not matter after squaring. However, use matching coordinates together: subtract the two \(x\)-values and subtract the two \(y\)-values.
Worked example
Find the distance between \(A(-2,1)\) and \(B(4,9)\).
First find each change:
\[ x2-x1=4-(-2)=6 \]
\[ y2-y1=9-1=8 \]
Then substitute into the formula:
\[ d=\sqrt{6^2+8^2} =\sqrt{36+64} =\sqrt{100} =10. \]
The points are 10 units apart. The horizontal and vertical changes form a \(6\)-\(8\)-\(10\) right triangle.
import math
def distance_between(p, q):
horizontal = q[0] - p[0]
vertical = q[1] - p[1]
return math.sqrt(horizontal**2 + vertical**2)
a = (-2, 1)
b = (4, 9)
print(distance_between(a, b))The program prints:
10.0Python also provides math.dist(a, b), which performs the same calculation for two coordinate pairs.
Checking and interpreting an answer
A distance cannot be negative. If your result is negative, you have calculated a directed change rather than a distance.
You can estimate the answer before calculating. In the worked example, the legs are 6 and 8, so the hypotenuse must be longer than 8 but shorter than 14. The exact answer, 10, fits this check.
For points with integer coordinates, the distance may be an irrational number such as \(\sqrt{13}\). Leave it in radical form when an exact answer is required, or use a decimal approximation when the problem asks for one.
Exercise
Find the distance between \(C(1,-4)\) and \(D(7,4)\).
Show answer
The horizontal change is \(7-1=6\), and the vertical change is \(4-(-4)=8\). Thus \(d=\sqrt{6^2+8^2}=\sqrt{100}=10\) units.