mam oto taki post
Closest point on a line to another line in 3D
kuroioranda Member since: 4/16/2007
Posted - 1/8/2009 7:29:59 PM
Assuming two lines in 3D space that may or may not intersect (definied by points of origin and direction vectors, really a ray), how do I determine what the closest point on line A to line B is? I understand how to find the closest point on a line to a discrete point, but having to solve for an unknown point on a line has me stumped.
User Rating: 1024 | Rate This User Report this Post to a Moderator | Link
hallucinogenic Member since: 7/15/2004 From: Vancouver, Canada
Posted - 1/8/2009 8:30:46 PM
If you define your lines as follows (parameterized vector functions):
A(s) = PA1 + (PA2 - PA1)s
B(t) = PB1 + (PB2 - PB1)t
Then the distance between your two lines is:
D(s, t) = B(t) - A(s)
From calculating the distance of a point to a line, we know that the closest point occurs when the vector from the point on the line to the point in space is perpendicular to the direction of the line.
Similarly, this must be the case for two lines, too. However, it must be maintained for *both* lines.
Let La = (PA2 - PA1),
Lb = (PB2 - PB1)
Thus, La . D(s, t) = 0, and
Lb . D(s, t) = 0
Substituting, we get:
La . (B(t) - A(s)) = 0, and
Lb . (B(t) - A(s)) = 0
Expanding, we get:
La . ( (PB1 - PA1) + Lb * t - La * s) ) = 0, and
Lb . ( (PB1 - PA1) + Lb * t - La * s) ) = 0
Expanding again, we get:
La . (PB1 - PA1) + La . Lb * t - La . La * s = 0, and
Lb . (PB1 - PA1) + Lb . Lb * t - Lb . La * s = 0
Finally, rearranging the equation, we end up with:
(La . La)s - (La . Lb)t = La . (PB1 - PA1), and
(La . Lb)s - (Lb . Lb)t = Lb . (PB1 - PA1)
This is a system of equations in s and t that should be easy enough to solve.
Chodzi dokladnie o ostatnie linijki
Finally, rearranging the equation, we end up with:
(La . La)s - (La . Lb)t = La . (PB1 - PA1), and
(La . Lb)s - (Lb . Lb)t = Lb . (PB1 - PA1)
Za cholere nie moge pojacco to jest (La . La) itp. coto jest ta kropka i czy zamiast La mam podstawic (PA2 - PA1) nie kumam tego prosilbym o pomoc :]