Notifications
Clear all

[Closed] Two skew lines intersection algorithm?

I know the lines don’t intersect.

Has anyone ever written a function for finding an intersection between two lines in 3d (simple equation IF the lines do intersect), and if they don’t intersect find the point in the middle of the shortest distance between the lines.

Basically finding the intersection point if there is one, or the closest point to the intersection point if lines do not intersect?

Hope what I’m saying is clear enough.

I found equations for intersection – but these assume the lines intesect.
I found equations for smallest distance between 2 skew lines – but these don’t deal with points on the lines, meaning they don’t calculate the closest points at any moment

Anyone solved this problem before?

4 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

it’s not enough for me. What is the distance to an intersection point if the lines do not intersect?

from my understanding there is only one shortest distance between two lines. If the distance equals Zero the lines are intersected.

oh!.. I got it. You want to know the coordinates of the points that make the common perpendicular to two lines (the distance between these two points is the shortest distance between the lines). Well… If you can’t or don’t want to read the theory behind http://atheist4.narod.ru/mw/distance.htm written on Russian (for any reason ;))
just skip it and go directly to http://atheist4.narod.ru/programs/dist.rar

PS. eh… the pure math… how I miss it sometimes.

I also managed to find some math solutions on some college forums
Will try to implement it, and post the function here if I succeed

The most aggravating thing about this is, that 5-8 years ago it would’ve taken me 15min to calculate it all myself – but now I see that n-dimesional trigonometry just doesn’t stay with you :)))

Got it:

 
fn findLinesIntersection pA a pB b = ( -- function returns the closest point on line A, closest point on line B and distance between lines
	local pBA=pB-pA
	local M=cross b a
	local m2=dot M M
	local R=(cross pBA M)/m2
 
	local tA=dot R b
	local tB=dot R a
	local p1=pA+tA*a
	local p2=pB+tB*b
 
	local dist=abs (dot pBA M)/(sqrt m2)
 
	#(p1,p2,dist)
)