Английская Википедия:Distance from a point to a line

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description In Euclidean geometry, the distance from a point to a line is the shortest distance from a given point to any point on an infinite straight line. It is the perpendicular distance of the point to the line, the length of the line segment which joins the point to nearest point on the line. The algebraic expression for calculating it can be derived and expressed in several ways.

Knowing the distance from a point to a line can be useful in various situations—for example, finding the shortest distance to reach a road, quantifying the scatter on a graph, etc. In Deming regression, a type of linear curve fitting, if the dependent and independent variables have equal variance this results in orthogonal regression in which the degree of imperfection of the fit is measured for each data point as the perpendicular distance of the point from the regression line.


Line defined by an equation

In the case of a line in the plane given by the equation Шаблон:Math, where Шаблон:Mvar, Шаблон:Mvar and Шаблон:Mvar are real constants with Шаблон:Mvar and Шаблон:Mvar not both zero, the distance from the line to a point Шаблон:Math is[1][2]Шаблон:Rp

<math>\operatorname{distance}(ax+by+c=0, (x_0, y_0)) = \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}}. </math>

The point on this line which is closest to Шаблон:Math has coordinates:[3]

<math>x = \frac{b(bx_0 - ay_0)-ac}{a^2 + b^2} \text{ and } y = \frac{a(-bx_0 + ay_0) - bc}{a^2+b^2}.</math>

Horizontal and vertical lines

In the general equation of a line, Шаблон:Math, Шаблон:Mvar and Шаблон:Mvar cannot both be zero unless Шаблон:Mvar is also zero, in which case the equation does not define a line. If Шаблон:Math and Шаблон:Math, the line is horizontal and has equation Шаблон:Math. The distance from Шаблон:Math to this line is measured along a vertical line segment of length Шаблон:Math in accordance with the formula. Similarly, for vertical lines (b = 0) the distance between the same point and the line is Шаблон:Math, as measured along a horizontal line segment.

Line defined by two points

If the line passes through two points Шаблон:Math and Шаблон:Math then the distance of Шаблон:Math from the line is:[4]

<math>\operatorname{distance}(P_1, P_2, (x_0, y_0)) = \frac{|(x_2-x_1)(y_1-y_0)-(x_1-x_0)(y_2-y_1)|}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}. </math>

The denominator of this expression is the distance between Шаблон:Math and Шаблон:Math. The numerator is twice the area of the triangle with its vertices at the three points, Шаблон:Math, Шаблон:Math and Шаблон:Math. See: Шаблон:Slink. The expression is equivalent to Шаблон:Math, which can be obtained by rearranging the standard formula for the area of a triangle: Шаблон:Math, where Шаблон:Mvar is the length of a side, and Шаблон:Mvar is the perpendicular height from the opposite vertex.

Line defined by point and angle

If the line passes through the point Шаблон:Math with angle Шаблон:Math, then the distance of some point Шаблон:Math to the line is

<math>\operatorname{distance}(P, \theta, (x_0, y_0)) = |\cos(\theta)(P_y-y_0) -\sin(\theta)(P_x-x_0)| </math>

Proofs

An algebraic proof

This proof is valid only if the line is neither vertical nor horizontal, that is, we assume that neither Шаблон:Mvar nor Шаблон:Mvar in the equation of the line is zero.

The line with equation Шаблон:Math has slope Шаблон:Math, so any line perpendicular to it will have slope Шаблон:Math (the negative reciprocal). Let Шаблон:Math be the point of intersection of the line Шаблон:Math and the line perpendicular to it which passes through the point (Шаблон:Math, Шаблон:Math). The line through these two points is perpendicular to the original line, so

<math>\frac{y_0 - n}{x_0 - m}=\frac{b}{a}.</math>

Thus, <math>a(y_0 -n) - b(x_0 - m) = 0,</math> and by squaring this equation we obtain:

<math>a^2(y_0 - n)^2 + b^2(x_0 - m)^2 = 2ab(y_0 - n)(x_0 - m).</math>

Now consider,

<math>

\begin{align} (a(x_0 - m) + b(y_0 - n))^2 & = a^2(x_0 - m)^2 + 2ab(y_0 -n)(x_0 - m) + b^2(y_0 - n)^2 \\

                           & = \left(a^2 + b^2\right) \left((x_0 - m)^2 + (y_0 - n)^2\right)

\end{align} </math> using the above squared equation. But we also have,

<math> (a(x_0 - m) + b(y_0 - n))^2 = (ax_0 + by_0 - am - bn)^2 = (ax_0 + by_0 + c)^2</math>

since Шаблон:Math is on Шаблон:Math. Thus,

<math>\left(a^2 + b^2\right) \left((x_0 - m)^2 + (y_0 - n)^2\right) = (ax_0 + by_0 + c)^2 </math>

and we obtain the length of the line segment determined by these two points,

<math>d=\sqrt{(x_0 - m)^2+(y_0 - n)^2} = \frac{|ax_0+ by_0 +c|}{\sqrt{a^2+b^2}}.</math>[5]

A geometric proof

Файл:Point-to-line2.svg
Diagram for geometric proof

This proof is valid only if the line is not horizontal or vertical.[6]

Drop a perpendicular from the point P with coordinates (x0, y0) to the line with equation Ax + By + C = 0. Label the foot of the perpendicular R. Draw the vertical line through P and label its intersection with the given line S. At any point T on the line, draw a right triangle TVU whose sides are horizontal and vertical line segments with hypotenuse TU on the given line and horizontal side of length |B| (see diagram). The vertical side of ∆TVU will have length |A| since the line has slope -A/B.

PRS and ∆TVU are similar triangles, since they are both right triangles and ∠PSR ≅ ∠TUV since they are corresponding angles of a transversal to the parallel lines PS and UV (both are vertical lines).[7] Corresponding sides of these triangles are in the same ratio, so:

<math>\frac{|\overline{PR}|}{|\overline{PS}|} = \frac{|\overline{TV}|}{|\overline{TU}|}.</math>

If point S has coordinates (x0,m) then |PS| = |y0 - m| and the distance from P to the line is:

<math> |\overline{PR} | = \frac{|y_0 - m||B|}{\sqrt{A^2 + B^2}}.</math>

Since S is on the line, we can find the value of m,

<math>m = \frac{-Ax_0 - C}{B},</math>

and finally obtain:[8]

<math> |\overline{PR}| = \frac{|Ax_0 + By_0 + C|}{\sqrt{A^2 + B^2}}.</math>

A variation of this proof is to place V at P and compute the area of the triangle ∆UVT two ways to obtain that <math>D|\overline{TU}| = |\overline{VU}||\overline{VT}|</math> where D is the altitude of ∆UVT drawn to the hypotenuse of ∆UVT from P. The distance formula can then used to express <math>|\overline{TU}|</math>, <math>|\overline{VU}|</math>, and <math>|\overline{VT}|</math>in terms of the coordinates of P and the coefficients of the equation of the line to get the indicated formula.Шаблон:Citation needed

A vector projection proof

Diagram for vector projection proof
Diagram for vector projection proof

Let P be the point with coordinates (x0, y0) and let the given line have equation ax + by + c = 0. Also, let Q = (x1, y1) be any point on this line and n the vector (a, b) starting at point Q. The vector n is perpendicular to the line, and the distance d from point P to the line is equal to the length of the orthogonal projection of <math>\overrightarrow{QP}</math> on n. The length of this projection is given by:

<math>d = \frac{|\overrightarrow{QP} \cdot \mathbf{n}|}{\| \mathbf{n}\|}.</math>

Now,

<math> \overrightarrow{QP} = (x_0 - x_1, y_0 - y_1),</math> so <math> \overrightarrow{QP} \cdot \mathbf{n} = a(x_0 - x_1) + b(y_0 - y_1)</math> and <math> \| \mathbf{n} \| = \sqrt{a^2 + b^2},</math>

thus

<math> d = \frac{|a(x_0 - x_1) + b(y_0 - y_1)|}{\sqrt{a^2 + b^2}}.</math>

Since Q is a point on the line, <math>c = -ax_1 - by_1</math>, and so,[9]

<math> d = \frac{|ax_0 + by_0 + c|}{\sqrt{a^2 + b^2}}.</math>

Although the distance is given as a modulus, the sign can be useful to determine which side of the line the point is on, in a sense determined by the direction of normal vector (a,b)

Another formula

It is possible to produce another expression to find the shortest distance of a point to a line. This derivation also requires that the line be not vertical or horizontal.

The point P is given with coordinates (<math>x_0, y_0</math>). The equation of a line is given by <math>y=mx+k</math>. The equation of the normal of that line which passes through the point P is given <math>y=\frac{x_0-x}{m}+y_0</math>.

The point at which these two lines intersect is the closest point on the original line to the point P. Hence:

<math>mx+k=\frac{x_0-x}{m}+y_0.</math>

We can solve this equation for x,

<math>x=\frac{x_0+my_0-mk}{m^2+1}.</math>

The y coordinate of the point of intersection can be found by substituting this value of x into the equation of the original line,

<math>y=m\frac{(x_0+my_0-mk)}{m^2+1}+k.</math>

Using the equation for finding the distance between 2 points, <math>d=\sqrt{(X_2-X_1)^2+(Y_2-Y_1)^2}</math>, we can deduce that the formula to find the shortest distance between a line and a point is the following:

<math>d=\sqrt{ \left( {\frac{x_0 + m y_0-mk}{m^2+1}-x_0 } \right) ^2 + \left( {m\frac{x_0+m y_0-mk}{m^2+1}+k-y_0 }\right) ^2 } = \frac{|k + m x_0 - y_0|}\sqrt{1 + m^2} .</math>

Recalling that m = -a/b and k = - c/b for the line with equation ax + by + c = 0, a little algebraic simplification reduces this to the standard expression.[3]

Vector formulation

Файл:Distance from a point to a line.svg
Illustration of the vector formulation.

The equation of a line can be given in vector form:

<math> \mathbf{x} = \mathbf{a} + t\mathbf{n}</math>

Here Шаблон:Math is a point on the line, and Шаблон:Math is a unit vector in the direction of the line. Then as scalar t varies, Шаблон:Math gives the locus of the line.

The distance of an arbitrary point Шаблон:Math to this line is given by

<math>\operatorname{distance}(\mathbf{x} = \mathbf{a} + t\mathbf{n}, \mathbf{p}) = \| (\mathbf{p}-\mathbf{a}) - ((\mathbf{p}-\mathbf{a}) \cdot \mathbf{n})\mathbf{n} \|. </math>

This formula can be derived as follows: <math>\mathbf{p}-\mathbf{a}</math> is a vector from Шаблон:Math to the point Шаблон:Math. Then <math>(\mathbf{p} - \mathbf{a}) \cdot \mathbf{n}</math> is the projected length onto the line and so

<math>\mathbf{a} + ((\mathbf{p} - \mathbf{a}) \cdot \mathbf{n})\mathbf{n}</math>

is a vector that is the projection of <math>\mathbf{p}-\mathbf{a}</math> onto the line and represents the point on the line closest to <math>\mathbf{p}</math>. Thus

<math>(\mathbf{p}-\mathbf{a}) - ((\mathbf{p}-\mathbf{a}) \cdot \mathbf{n})\mathbf{n}</math>

is the component of <math>\mathbf{p}-\mathbf{a}</math> perpendicular to the line. The distance from the point to the line is then just the norm of that vector.[4] This more general formula is not restricted to two dimensions.

Another vector formulation

If the vector space is orthonormal and if the line goes through point Шаблон:Math and has a direction vector Шаблон:Math, the distance between point Шаблон:Math and the line is[10]

<math>\operatorname{distance}(\mathbf{x} = \mathbf{a} + t\mathbf{n}, \mathbf{p}) = \frac{\left\|(\mathbf{p}-\mathbf{a}) \times \mathbf{n}\right\|}{\|\mathbf{n}\|}.</math>

Note that cross products only exist in dimensions 3 and 7.

See also

Notes

Шаблон:Reflist

References

Further reading

  1. Шаблон:Harvnb
  2. Шаблон:Harvnb
  3. 3,0 3,1 Шаблон:Harvnb
  4. 4,0 4,1 Шаблон:Cite web
  5. Between Certainty and Uncertainty: Statistics and Probability in Five Units With Notes on Historical Origins and Illustrative Numerical Examples
  6. Шаблон:Harvnb do not mention this restriction in their article
  7. If the two triangles are on opposite sides of the line, these angles are congruent because they are alternate interior angles.
  8. Шаблон:Harvnb
  9. Шаблон:Harvnb
  10. Шаблон:Cite web