Minimum distance between a point and a bounded line in 3D

In summary: And I should have said "closest to P0" not "closest to P3".In summary, to calculate the minimum distance between a point (P0) and a line specified by its end points (P1 and P2), you can use vector notation to find the point (P4) on the line closest to the external point (P0). This is done by setting up parametric equations for both the line and the plane perpendicular to the line and containing P0, and solving for the intersection point. If the value of t is between 0 and 1, then P4 is between P1 and P2. If it is not, then the minimum distance is the distance to either P1 or P2
  • #1
DHeshMan
5
0
I have a point in 3D specified by its coordinates (x0, y0, z0)

I have a line in 3D specified and bounded by its end points (x1, y1, z1) and (x2, y2, z2)

How do I calculate the minimum distance between the point and the line, keeping in mind that it may not be the perpendicular distance between the point and the extrapolated line because the line is bounded by its end points.

I would also like to know the point (x4, y4, z4) on the line that is closest to the external point.
 
Mathematics news on Phys.org
  • #2
Calculate the distance to the extended line (perpendicular). Check if the minimum point is between the bounds. If it is, you're done. If not, check the distances to the end points. The smaller of the two is then the minimum.
 
  • #3
Can you provide details on how to calculate the perpedicular distance to the extended line?
 
  • #4
It is best done using vector notation.
Let Pk=(xk,yk,zk)
Let A=(P3-P1)x(P2-P1), (x = vector cross product) A is a vector perpendicular to the plane of the Pk's.
Let B=P3-P2, B is the direction of the line joining P2 and P3.
Let C=AxB, C is a vector (used in the plane of the Pk's) perpendicular to B.

The line from P1 to the line containing the P2 to P3 interval is P1+sC.
The line through P2 and P3 is P2+tB.
In the above s and t are scalars.
To find s and t you need to set P1+sC=P2+tB. (3 equation in 2 unknowns - use 2 to solve and the third one is a check.) The point of intersection of the 2 lines is given by the solution.
 
  • #5
I'm a little confused. My original problem statement used P0, P1, P2, and P4 (I inadvertently skipped P3). P0 is the external point, P1 and P2 are the end points of the line, and P4 was the point on the line closest to P0.

Your solution uses P1, P2, and P3? If I follow your theory correctly, your P1 is my P0? your P2 is my P1? your P3 is my P2? and your P1 + sC = P2 + tB = my P4?
 
  • #6
The line through [itex]P1= (x_1, y_1, z_1)[/itex] and [itex]P2= (x_2, y_2, z_2)[/itex] is given by parametric equations [itex]x= x_1+ t(x_2- x_1)[/itex], [itex]y= y_1+ t(y_2- y_1)[/itex], [itex]z= z_1+ t(z_2- z_1)[/itex]. The plane, perpendicular to that line and containing [itex]P0= (x_0, y_0, z_0)[/itex], is given by [itex](x_2- x_1)(x- x_0)+ (y_2- y_1)(y- y_0)+ (z_1- z_0)(z- z_0)= 0[/itex].

Replacing x, y, and z in the equation of the plane by the parametric equations for the line gives an equation for t where the line intersects the plane. That point is the point, P4, on the line closest to P0.
 
  • #7
Thank you. For those that want a little more clarification, I have the following:

Using the dot product:

point Pn = <xn, yn, zn>
direction dPn = (dxn, dyn, dzn)

A = The line through P1 and P2 = <x1, y1, z1> + t(x2-x1, y2-y1, z2-z1)

B = The line through P0 and P4 = <x0, y0, z0> + s(x4-x0, y4-y0, z4-z0)

If A and B are perpedicular, the dot product dA . dB = 0
(x2-x1) (x4-x0) + (y2-y1) (y4-y0) + (z2-z1) (z4-z0) = 0

Knowing that P4 is a point somewhere on line A
x4 = x1 + t(x2-x1); y4 = y1 + t(y2-y1); z4 = z1 + t(z2-z1)

(x2-x1) (x1 + t(x2-x1) -x0) + (y2-y1) (y1 + t(y2-y1) -y0) + (z2-z1) (z1 + t(z2-z1) -z0) = 0

Solving for t we get

t = ( (x2-x1) (x0-x1) + (y2-y1) (y0-y1) + (z2-z1) (z0-z1) ) / ( (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2 )

Knowing t we can find P4, since t is bounded by P1 and P2; 0 <= t <= 1

If t < 0 then P4 = P1; If t > 1 then P4 = P2; otherwise P4 is calculated using t and the parameterization of A

And the distance can be calculated

dist = sqrt ( (x4-x0)^2 + (y4-y0)^2 + (z4-z0)^2 )
 
Last edited:
  • #8
DHeshMan said:
I'm a little confused. My original problem statement used P0, P1, P2, and P4 (I inadvertently skipped P3). P0 is the external point, P1 and P2 are the end points of the line, and P4 was the point on the line closest to P0.

Your solution uses P1, P2, and P3? If I follow your theory correctly, your P1 is my P0? your P2 is my P1? your P3 is my P2? and your P1 + sC = P2 + tB = my P4?

You are correct. I was careless - I should have said P0, P1, P2 not P1, P2, P3.
 

FAQ: Minimum distance between a point and a bounded line in 3D

What is the minimum distance between a point and a bounded line in 3D?

The minimum distance between a point and a bounded line in 3D is the shortest distance between the point and any point on the bounded line.

How is the minimum distance calculated between a point and a bounded line in 3D?

The minimum distance can be calculated using the formula: d = |(p-q) x (r-s)| / |r-s|, where p is the point, q is any point on the bounded line, and r and s are two points defining the bounded line segment.

Can the minimum distance between a point and a bounded line be negative?

No, the minimum distance between a point and a bounded line cannot be negative. It is always a positive value representing the shortest distance between the two objects.

What is the significance of calculating the minimum distance between a point and a bounded line?

Calculating the minimum distance between a point and a bounded line is important in various applications such as computer graphics, robotics, and navigation. It helps in determining the closest point on a bounded line for a given point and can be used to optimize path planning and collision avoidance algorithms.

Is the minimum distance between a point and a bounded line affected by the orientation of the line in 3D space?

Yes, the minimum distance between a point and a bounded line is affected by the orientation of the line in 3D space. It can vary depending on the angle between the line and the point. For example, the minimum distance would be shorter if the point is perpendicular to the line compared to if it is at an oblique angle.

Similar threads

Replies
3
Views
1K
Replies
4
Views
2K
Replies
2
Views
1K
Replies
2
Views
2K
Replies
11
Views
6K
Replies
17
Views
2K
Back
Top