Sub topic 8
Distance from a Point to a Line
This chapter assumes you can write a line in general form ax + by + c = 0, find a slope, and recognise perpendicular lines from earlier chapters. It also assumes the distance formula and basic square-root arithmetic.
What "distance to a line" means
A line extends forever, so many segments join a point P to it. The distance from P to the line is the length of the shortest one. That segment is always perpendicular to the line, and its other end is the foot of the perpendicular.
CAT uses this distance in several ways. It gives the height of a triangle when one side lies on a known line. It gives the radius of a circle tangent to a line. It also gives the gap between two parallel lines.
The formula
For a point (x₀, y₀) and a line ax + by + c = 0, the distance is:
d = |a·x₀ + b·y₀ + c| / √(a² + b²)
The numerator is the line's expression evaluated at the point, with the absolute value applied. The denominator is the length of the vector (a, b), which is normal (perpendicular) to the line.
def point_line_distance(x0, y0, a, b, c):
# distance from (x0, y0) to the line ax + by + c = 0
return abs(a * x0 + b * y0 + c) / (a ** 2 + b ** 2) ** 0.5
print(point_line_distance(1, 2, 3, 4, -10))For the point (1, 2) and the line 3x + 4y − 10 = 0, the numerator is |3 + 8 − 10| = 1. The denominator is √(9 + 16) = 5. The distance is 0.2, which is what the code prints.
Why it works
Take any point Q = (x₁, y₁) on the line, so a·x₁ + b·y₁ + c = 0. The vector from Q to P is (x₀ − x₁, y₀ − y₁). The normal vector n = (a, b) is perpendicular to the line. The distance is the length of the component of QP along n:
d = |QP · n| / |n| = |a(x₀ − x₁) + b(y₀ − y₁)| / √(a² + b²)
Expanding the numerator gives a·x₀ + b·y₀ − (a·x₁ + b·y₁). Since a·x₁ + b·y₁ = −c, this equals a·x₀ + b·y₀ + c. That is the formula.
A second derivation uses areas. Let the line meet the axes at A and B, and let P be the point. The area of triangle PAB is ½ · AB · d, and the shoelace method gives the same area from coordinates. Equating the two yields the same result. You do not need this in an exam, but it shows the formula is the "height = 2 × area / base" idea in disguise.
Worked examples
Example 1: a line given in slope-intercept form
Find the distance from (2, −3) to y = 2x + 1.
Rewrite as 2x − y + 1 = 0, so a = 2, b = −1, c = 1.
- Numerator: |2·2 − 1·(−3) + 1| = |4 + 3 + 1| = 8.
- Denominator: √(4 + 1) = √5.
The distance is 8/√5 ≈ 3.58.
Example 2: a triangle's height
Triangle ABC has A = (0, 0), B = (6, 0) and C = (2, 5). Find the distance from C to the line AB.
Line AB is y = 0, so a = 0, b = 1, c = 0. The distance is |5| / 1 = 5. Here the formula is overkill, because the height is just the y-coordinate. Check for horizontal and vertical lines before applying anything.
A harder case: find the altitude from A to BC.
- Slope of BC = (5 − 0)/(2 − 6) = −5/4.
- Line BC through B(6, 0): y = −(5/4)(x − 6), so 4y = −5x + 30, giving 5x + 4y − 30 = 0.
- Distance from A(0, 0): |−30| / √(25 + 16) = 30/√41.
Check with area: the area is ½ · 6 · 5 = 15. BC = √(16 + 25) = √41. The altitude is 2 · 15 / √41 = 30/√41. Both routes agree.
Example 3: the sign of the expression
The unsigned distance hides which side of the line the point is on. The value a·x₀ + b·y₀ + c, before taking the absolute value, is positive on one side of the line and negative on the other. Two points are on the same side if their values have the same sign.
For the line x + y − 4 = 0:
- (0, 0) gives −4, which is negative.
- (3, 3) gives +2, which is positive.
- (1, 1) gives −2, which is negative.
So (0, 0) and (1, 1) lie on the same side, and (3, 3) lies on the opposite side. The line segment from (0, 0) to (3, 3) therefore crosses the line. This test appears in questions about whether a segment meets a line, or whether a point is inside a region bounded by lines.
Distance between parallel lines
Parallel lines share the same direction, so they have the same a and b up to a common multiple. Write both with the same a and b:
- ax + by + c₁ = 0
- ax + by + c₂ = 0
Choose any point on the first line and measure to the second. The result simplifies to:
d = |c₁ − c₂| / √(a² + b²)
def parallel_distance(a, b, c1, c2):
# distance between ax + by + c1 = 0 and ax + by + c2 = 0
return abs(c1 - c2) / (a ** 2 + b ** 2) ** 0.5
print(parallel_distance(3, 4, 5, -10))This prints 3.0, since |5 − (−10)| / 5 = 3.
Common errors
| Error | What goes wrong | Fix |
|---|---|---|
| Forgetting to move everything to one side | The constant c has the wrong sign or size | Write the line as `ax + by + c = 0` before substituting |
| Reading c from `y = mx + k` as k | The correct form is mx − y + k = 0, so c is k only with b = −1 | Rewrite the equation explicitly |
| Dropping the absolute value | You get a negative distance | Always take the modulus for a distance |
| Using unequal x and y coefficients for parallel lines | Constants are not comparable | Scale one equation to match the other |
| Dividing by a + b instead of √(a² + b²) | The denominator is wrong | Square, add, then take the root |
Using the distance in other problems
Tangent circles
A circle with centre (h, k) is tangent to a line when its radius equals the distance from the centre to the line. A circle centred at (1, 2) that touches 3x + 4y − 10 = 0 has radius 0.2, using the earlier computation. If the distance is less than the radius, the line cuts the circle at two points. If it is greater, the line misses the circle.
Locus of points at a fixed distance
The points at distance d from ax + by + c = 0 form two parallel lines: ax + by + c = ±d√(a² + b²). For example, the points at distance 2 from 3x + 4y = 0 satisfy 3x + 4y = ±10.
Angle bisectors
A point on an angle bisector is equidistant from both lines. Setting |a₁x + b₁y + c₁| / √(a₁² + b₁²) equal to |a₂x + b₂y + c₂| / √(a₂² + b₂²) gives two lines. They are the bisectors of the angle and its supplement. This also applies to the incentre of a triangle, which is equidistant from all three sides.
Minimising a distance
The shortest distance from a point to a line is the perpendicular distance, so any "minimum value of √((x − p)² + (y − q)²) subject to ax + by + c = 0" question reduces to this formula. Recognising the pattern saves a calculus or completing-the-square step.
CAT strategies for this topic
- Check for horizontal or vertical lines first. For x = k, the distance from (x₀, y₀) is |x₀ − k|. For y = k, it is |y₀ − k|.
- If the line passes through the origin (c = 0), the numerator is just |a·x₀ + b·y₀|.
- When the numbers are a Pythagorean triple (3-4-5, 5-12-13, 8-15-17), the denominator is an integer, which hints that the intended path uses this formula.
- For a triangle with known vertices, compare two ways of finding the height: the formula, or 2 × area / base. Pick whichever needs less arithmetic.
- Estimate before you compute. Plot the point and the line roughly. If your answer is larger than the distance to an obvious point on the line, recheck it.
Exercise
Find the distance from the point (4, −1) to the line 5x − 12y + 7 = 0.
Show answer
Numerator: |5·4 − 12·(−1) + 7| = |20 + 12 + 7| = 39. Denominator: √(25 + 144) = 13. The distance is 39/13 = 3.
Exercise
Find the distance between the parallel lines 2x + 3y − 6 = 0 and 4x + 6y + 5 = 0.
Show answer
Divide the second line by 2 to get 2x + 3y + 2.5 = 0. Then d = |−6 − 2.5| / √(4 + 9) = 8.5/√13 ≈ 2.36.
Exercise
A circle has its centre at (3, 1) and touches the line x + y + 2 = 0. Find its radius and area in terms of π.
Show answer
The radius equals the distance from the centre to the line: |3 + 1 + 2| / √2 = 6/√2 = 3√2. The area is π r² = π · 18 = 18π.
Exercise
Do the points (1, 1) and (4, 0) lie on the same side of the line x + 2y − 5 = 0?
Show answer
At (1, 1): 1 + 2 − 5 = −2. At (4, 0): 4 + 0 − 5 = −1. Both values are negative, so the points are on the same side.