Distance between a point and a straight line

The distance between a point P and a straight line r is the minimum of the distances between P and any point on the straight line.

We can distinguish two cases:

  • If P belongs to the straight line r, d(P,r)=0.
  • If P does not belong to the straight line r, d(P,r), it is the module of the vector QP, where Q is the intersection point between the straight line r and the perpendicular to r that crosses P.

Let Ax+By+C=0 be the general equation of the straight line r, and P=(p1,p2) the given point and A=(a1,a2) any point of the straight line.

If we take a perpendicular vector to r, for example n=(A,B) for the properties of the scalar product in the vectors projection we have: d(P,r)=|APn|n=|Ap1+Bp2(Aa1+Ba2)|A2+B2 But since A=(a1,a2) is a point of the straight line r, it verifies its equation: Aa1+Ba2+C=0Aa1+Ba2=C Therefore we obtain the following formula: d(P,r)=|Ap1+Bp2+C|A2+B2

Example

Let P=(1,2) be a point and r:4x3y+1=0 a straight line. Calculate the distance between the point and the straight line.

Applying the previous formula we have: d(P,r)=Ap1+Bp2+CA2+B2=|4(1)+(3)2+1|42+(3)2=95