Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Intersection of lines in 3D space

Author
Message
The Bellmaker
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Over here
Posted: 11th Mar 2010 19:07
Is there a way to find the intersection of lines in 3D space or the points on the lines that are closest to each other without using a guess and check method? For example, I have the code



the parameters for the function are a point on each line and the components of the vector on that line for both lines. t1 and t2 are the varibales determining the location on each respective line. "mind" is the minimum distance between the lines. Distance() is a function to find distance between points. As you can see, this method is purely guess and check. However, is has limited accuracy and causes my cpu to lag a little bit.

My question: Is there another method to find intersections of lines, or a better was to use guess and check?

pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342177067... and yet I still have a life.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Mar 2010 19:43
Quote: "My question: Is there another method to find intersections of lines"


Yes - and no guessing is involved.

You can proceed as follows:

1. Express each line in the form P + tD where P is an arbitrary point on the line and D is a direction vector along the line. Then different values of the scalar t will give you different points along the line. So, for line 1 you might have P1, D1 and t, and P2, D2 and s for line 2. P1, D1, P2 and D2 will be fixed, t and s will be adjustable.

2. You then need the values of s and t which correspond to the points which are closest to each other. This happens when the line E joining the two points is perpendicular to each of the two lines - hold two pencils crossing at angles to each other to see why this works. Those two values can be found easily from a pair of simultaneous equations for s and t obtained by using the fact that the directions D1 and D2 must both be perpendicular to the direction of the line E.

I'm sure you can find details and examples of all this if you do a Google search of the web using your question.
The Bellmaker
18
Years of Service
User Offline
Joined: 22nd Dec 2007
Location: Over here
Posted: 11th Mar 2010 21:46
You are a genius thanks for the help

pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342177067... and yet I still have a life.
Mnemonix
23
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 13th Mar 2010 10:28
His genius is supreme!

Well he IS (was?) a maths professor

Your signature has been erased by a mod because it's larger than 600x120
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 13th Mar 2010 11:45
I think you just promoted me.

Login to post a reply

Server time is: 2026-07-26 23:41:07
Your offset time is: 2026-07-26 23:41:07