Distance from a point to a line · Mathematics Class 11–12 | StemPy Lab
Course 6.2·Lesson 2 of 3
Distance from a point to a line
The distance of (x1,y1)
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
The shortest road to a line
Stand at a point P and walk to a straight road. Which way is shortest? Straight across, at a right angle to the road. The distance from a point to a line is the length of that perpendicular.
A coordinate grid with the line 3x + 4y - 10 = 0 drawn in blue, sloping down from the upper left to the lower right. An orange dot marks the point P(5, 1) to the right of the line. A red dashed segment runs from P to a green dot on the line at (3.92, -0.44), the foot of the perpendicular. A small right-angle mark at the foot shows the segment meets the line at 90 degrees. The segment is labelled d = 1.8. The title says the shortest distance from P to the line is along the perpendicular.
The formula
The distance of the point (x1,y1) from the line Ax+By+C=0 is
d=A2+B2∣Ax1+By1+C∣.
Put the point into the left side of the equation, take the size of the result, and divide by A2+B2.
Example. Find the distance of (5,1) from 3x+4y−10=0.
Step 1. Put the point in.3(5)+4(1)−10=9.
Step 2. Divide.32+42=5, so d=59=1.8.
Where the formula comes from
Write the line in normal form: xcosα+ysinα=p. The line through P parallel to it is xcosα+ysinα=p′, where p′=x1cosα+y1sinα.
Two parallel lines with the same unit normal (cosα,sinα) are ∣p′−p∣ apart. So
d=∣x1cosα+y1sinα−p∣.
Now put cosα=RA, sinα=RB and p=−RC, where R=A2+B2 and the signs are chosen as in the normal form. The result is R∣Ax1+By1+C∣. The size bars cover the choice of sign.
Drag P to the other side of the line. The value of Ax+By+C changes sign, and the distance stays positive.
The distance of the origin
Put x1=y1=0. The distance of the origin from Ax+By+C=0 is
A2+B2∣C∣,
which is the number p of the normal form.
The distance between parallel lines
Two parallel lines Ax+By+C1=0 and Ax+By+C2=0 are
d=A2+B2∣C1−C2∣
apart. The formula needs the sameA and B in both equations.
Example. Find the distance between 3x+4y−10=0 and 6x+8y+10=0.
Step 1. Match the coefficients. Divide the second equation by 2: 3x+4y+5=0.
Step 2. Apply the formula.d=32+42∣−10−5∣=515=3.
A common slip is to use −10 and +10 with the coefficients 3 and 4. That gives 4, which is wrong, because the second line was never scaled.
Which side of a line?
The expression Ax+By+C is 0 on the line, positive on one side and negative on the other. Two points are on the same side when it has the same sign at both. They are on opposite sides when the signs differ.
Example. Where do (3,1) and (1,1) lie compared with the line 2x−y−4=0?
Step 1. Test each point. At (3,1): 6−1−4=1, positive. At (1,1): 2−1−4=−3, negative.
Step 2. Compare the signs. The signs differ, so the points are on opposite sides. The segment between them crosses the line.
The origin is a handy test point. Its value is just C, so a point is on the origin's side when its value has the same sign as C.
Points at a given distance
Example. Find the points on the x-axis that are 5 units from 5x+12y−10=0.
Step 1. Write the point. It is (a,0).
Step 2. Use the formula.13∣5a−10∣=5, so ∣5a−10∣=65.
Step 3. Solve both cases.5a−10=65 gives a=15. 5a−10=−65 gives a=−11.
Answer:(15,0) and (−11,0). The absolute value always gives two cases.
Practise with new numbers
Try it in Python
The program finds the distance twice. First by the formula. Then by walking along the line in steps of 0.001 and keeping the nearest point.
Common mistakes
Leaving out the absolute value. A distance is never negative.
Forgetting the square root. The bottom is A2+B2, not A2+B2 and not A+B.
Using the formula for parallel lines with different coefficients. Make A and B the same in both equations first.
Putting the point into the equation with the signs wrong. The equation must have 0 on the right, so 3x+4y=10 becomes 3x+4y−10.
Deciding the side from the size of the value. Only the sign matters.
Remember these
d=A2+B2∣Ax1+By1+C∣, and for the origin d=A2+B2∣C∣.
Parallel lines: d=A2+B2∣C1−C2∣, after the coefficients are matched.
The sign of Ax1+By1+C tells the side: the same sign means the same side.
A point at a given distance leads to ∣…∣= a number, which gives two cases.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Find the distance of the origin from 3x+4y−15=0.
Find the distance of (3,−1) from 4x−3y+6=0.
Find the distance between 3x+4y+7=0 and 3x+4y−3=0.
Are (2,3) and (−1,4) on the same side of x−y+2=0?
Find the points on the y-axis that are 3 units from 3x+4y−5=0.
Enroll free in General Form, Distances and Families of Lines
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.