Point-Line Distance--3-Dimensional

DOWNLOAD Mathematica Notebook PointLineDistance3D

Let a line in three dimensions be specified by two points x_1=(x_1,y_1,z_1) and x_2=(x_2,y_2,z_2) lying on it, so a vector along the line is given by

 v=[x_1+(x_2-x_1)t; y_1+(y_2-y_1)t; z_1+(z_2-z_1)t].
(1)

The squared distance between a point on the line with parameter t and a point x_0=(x_0,y_0,z_0) is therefore

 d^2=[(x_1-x_0)+(x_2-x_1)t]^2+[(y_1-y_0)+(y_2-y_1)t]^2+[(z_1-z_0)+(z_2-z_1)t]^2.
(2)

To minimize the distance, set d(d^2)/dt=0 and solve for t to obtain

 t=-((x_1-x_0)·(x_2-x_1))/(|x_2-x_1|^2),
(3)

where · denotes the dot product. The minimum distance can then be found by plugging t back into (2) to obtain

d^2=(x_1-x_0)^2+(y_1-y_0)^2+(z_1-z_0)^2+2t[(x_2-x_1)(x_1-x_0)+(y_2-y_1)(y_1-y_0)+(z_2-z_1)(z_1-z_0)]+t^2[(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2]
(4)
=|x_1-x_0|^2-2([(x_1-x_0)·(x_2-x_1)]^2)/(|x_2-x_1|^2)+([(x_1-x_0)·(x_2-x_1)]^2)/(|x_2-x_1|^2)
(5)
=(|x_1-x_0|^2|x_2-x_1|^2-[(x_1-x_0)·(x_2-x_1)]^2)/(|x_2-x_1|^2).
(6)

Using the vector quadruple product

 (AxB)^2=A^2B^2-(A·B)^2
(7)

where x denotes the cross product then gives

 d^2=(|(x_2-x_1)x(x_1-x_0)|^2)/(|x_2-x_1|^2),
(8)

and taking the square root results in the beautiful formula

d=(|(x_2-x_1)x(x_1-x_0)|)/(|x_2-x_1|)
(9)
=(|(x_0-x_1)x(x_0-x_2)|)/(|x_2-x_1|)
(10)
.
(11)

Here, the numerator is simply twice the area of the triangle formed by points x_0, x_1, and x_2, and the denominator is the length of one of the bases of the triangle, which follows since, from the usual triangle area formula, Delta=bd/2.

Wolfram Web Resources

Mathematica »

The #1 tool for creating Demonstrations and anything technical.

Wolfram|Alpha »

Explore anything with the first computational knowledge engine.

Wolfram Demonstrations Project »

Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.

Computerbasedmath.org »

Join the initiative for modernizing math education.

Online Integral Calculator »

Solve integrals with Wolfram|Alpha.

Step-by-step Solutions »

Walk through homework problems step-by-step from beginning to end. Hints help you try the next step on your own.

Wolfram Problem Generator »

Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet.

Wolfram Education Portal »

Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more.

Wolfram Language »

Knowledge-based programming for everyone.