Precalculus

Analytic Geometry

Analytic Geometry Logo

Distance from a Point to a Line on a Plane

The distance from a point M(x0, y0) to a straight line Ax + By + C = 0 in the plane is determined by the formula

\[d = \frac{\left|{Ax_0 + By_0 + C}\right|}{\sqrt{A^2 + B^2}}\]

Here (x0, y0) is the coordinate of the point M and A, B, C are the coefficients of the equation of the straight line.

Distance from a point to a straight line in plane
Figure 1.

This formula calculates the perpendicular distance d = MN between the point and the line. The formula can be proved as follows.

Proof

Let point N(x1, y1) be the foot of the perpendicular drawn from the point M(x0, y0) to the line Ax + By + C = 0. Find the slope of the line Ax + By + C = 0:

\[Ax + By + C = 0, \Rightarrow By = - Ax - C, \Rightarrow y = -\frac{A}{B}x - \frac{C}{B}.\]

Therefore, the slope is equal to \(k = -\frac{A}{B}.\)

Since the lines MN and Ax + By + C = 0 are perpendicular, the slope of line MN is equal to

\[k_{MN} = -\frac{1}{k} = -\frac{1}{-\frac{A}{B}} = \frac{B}{A}.\]

Hence the equation of the straight line MN has the form

\[y = \frac{B}{A}x + B_{MN}.\]

Find now the value of BMN. Since point M(x0, y0) belongs to this line, then its coordinates satisfy the equation:

\[y_0 = \frac{B}{A}x_0 + B_{MN}, \Rightarrow B_{MN} = y_0 - \frac{B}{A}x_0.\]

So

\[y = \frac{B}{A}x + y_0 - \frac{B}{A}x_0.\]

Point N(x1, y1) also belongs to the line MN, so its coordinates also satisfy this equation:

\[y_1 = \frac{B}{A}x_1 + y_0 - \frac{B}{A}x_0.\]

From here we get

\[y_1 - y_0 = \frac{B}{A}\left({x_1 - x_0}\right), \Rightarrow \frac{y_1 - y_0}{B} = \frac{x_1 - x_0}{A}.\]

We denote

\[\frac{y_1 - y_0}{B} = \frac{x_1 - x_0}{A} = q.\]

Then

\[y_1 - y_0 = Bq,\;x_1 - x_0 = Aq.\]

The distance between points M and N is determined by the formula

\[d\left({M,N}\right) = \sqrt{\left({x_1 - x_0}\right)^2 + \left({y_1 - y_0}\right)^2 }.\]

Therefore

\[d\left({M,N}\right) = \sqrt{\left({Aq}\right)^2 + \left({Bq}\right)^2} = |q|\sqrt{A^2 + B^2}.\]

Notice, that

\[y_1 - y_0 = Bq,\; x_1 - x_0 = Aq, \;\Rightarrow y_1 = y_0 + Bq,\; x_1 = x_0 + Aq.\]

Taking into account that the point N(x1, y1) lies on the line Ax + By + C = 0, we obtain

\[Ax_1 + By_1 + C = 0, \Rightarrow A\left({x_0 + Aq}\right) + B\left({y_0 + Bq}\right) + C = 0.\]

Find the value of q from this equation:

\[Ax_0 + A^2q + By_0 + B^2q + C = 0, \Rightarrow q\left({A^2 + B^2}\right) = - \left({Ax_0 + By_0 + C}\right), \Rightarrow q = -\frac{Ax_0 + By_0 + C}{A^2 + B^2}.\]

Substituting the value of \(q\) into the formula for the distance, we get

\[d\left({M,N}\right) = |-\frac{Ax_0 + By_0 + C}{A^2 + B^2}|\sqrt{A^2 + B^2}.\]

Using some algebra we get the final expression:

\[d\left({M,N}\right) = \frac{\left|{Ax_0 + By_0 + C}\right|}{\sqrt{A^2 + B^2}}\]

Solved Problems

Example 1.

Find the distance from the origin to the straight line \({6x - 8y + 5 = 0}.\)

Solution.

The distance from a point M(x0, y0) to the line Ax + By + C = 0 is determined by the formula

\[d = \frac{\left|{Ax_0 + By_0 + C}\right|}{\sqrt{A^2 + B^2}}.\]

Substitute the coordinates of the origin O(0,0) and the coefficients of the line:

\[d = \frac{\left|{6 \cdot 0 - 8 \cdot 0 + 5}\right|}{\sqrt{6^2 + \left({-8}\right)^2}} = \frac{5}{\sqrt{100}} = \frac{5}{10} = \frac{1}{2}.\]

Example 2.

Find the length of the altitude \(BD\) in a triangle with vertices \({A\left({-3,0}\right)},\) \({B\left({2,5}\right)},\) and \({C\left({3,2}\right)}.\)

Solution.

A triangle ABC with altitude BD
Figure 2.

Write the equation of the line \(AC\) in two-point form:

\[\frac{y - y_A}{y_C - y_A} = \frac{x - x_A}{x_C - x_A},\; \Rightarrow \frac{y - 0}{2 - 0} = \frac{x + 3}{3 + 3},\; \Rightarrow \frac{y}{2} = \frac{x + 3}{6},\]

and convert it into the general form:

\[6y = 2\left({x+3}\right),\;\Rightarrow 2x - 6y + 6 = 0,\; \Rightarrow x - 3y + 3 = 0.\]

Calculate now the distance from point \(B\) to line \(AC,\) that is, the length of the segment \(BD:\)

\[d = \frac{\left|{Ax_B + By_B + C}\right|}{\sqrt{A^2 + B^2}} = \frac{\left|{1\cdot2 - 3\cdot5 + 3}\right|}{\sqrt{1^2 + \left({-3}\right)^2}} = \frac{\left|{2-15+3}\right|}{\sqrt{10}} = \frac{\left|{-10}\right|}{\sqrt{10}} = \frac{10}{\sqrt{10}} = \sqrt{10}.\]

Example 3.

Find the distance between two parallel lines \(Ax + By + C_1 = 0\) and \(Ax + By + C_2 = 0.\)

Solution.

Let the point \(M\left({x_0,y_0}\right)\) belong to the line \(Ax + By + C_1 = 0.\) The distance from point M to the straight line \(Ax + By + C_2 = 0\) is given by

\[d = \frac{\left|{Ax_0 + By_0 + C_2}\right|}{\sqrt{A^2 + B^2}}.\]

Since the point M belongs to the first line, we have

\[Ax_0 + By_0 + C_1 = 0, \Rightarrow Ax_0 + By_0 = -C_1.\]

Substituting this into the previous expression, we get

\[d = \frac{\left|{-C_1 + C_2}\right|}{\sqrt{A^2 + B^2}} = \frac{\left|{C_2 - C_1}\right|}{\sqrt{A^2 + B^2}}.\]

Example 4.

A line drawn through the origin at the same distance from points \(M\left({3,3}\right)\) and \(N\left({5,1}\right).\) Find the equation of this line.

Solution.

Since the line passes through the origin, its equation is \(Ax + By = 0.\) The distances from points M and N to the line are equal, therefore

\[d = \frac{\left|{Ax_M + By_M}\right|}{\sqrt{A^2 + B^2}} = \frac{\left|{Ax_N + By_N}\right|}{\sqrt{A^2 + B^2}},\Rightarrow \left|{3A + 3B}\right| = \left|{5A + B}\right|.\]

Expanding the absolute values, we get two solutions (two straight lines):

\[3A + 3B = \pm\left({5A + B}\right).\]

Find the equation of the first line:

\[3A + 3B = 5A + B, \Rightarrow 2A = 2B, \Rightarrow B = A, \Rightarrow x + y = 0.\]

The equation of the second straight line is written as

\[3A + 3B = -5A - B, \Rightarrow 8A = -4B, \Rightarrow B = -2A, \Rightarrow x - 2y = 0.\]

The location of these lines is shown in the figure below.

A line equidistant from two points
Figure 3.