Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about intersection of 3-d lines--how to code?

Status
Not open for further replies.

Weber1

Programmer
Sep 9, 2000
20
US
For a program I am writing, I am trying to find the intersection of (2) 3-dimensional lines, each line represented by a class that is an array of (2) 3-dimensional points.
That is, each line is described by two points. The points are, of course, points on the line, but not necessarily the endpoints since the line is considered infinite.
At any rate, I am looking for a simple way to calculate the point at which the lines intersect (I can already check (true/false) for intersection). I have tried many approaches, including:
(1) Algrebraic solution using linear relationship of x,y,z per line--this is problematic because to calculate y(x) or z(y), for examples, you need the ratio of the two using the endpoints (a partial slope, so to speak) and the ratio can be infinite (x, y, or z can be independent of the other variables, such as a line along the x-axis would have no dependence on y or z. There are something line 64 special cases I'd have to test for.)
(2) Solution by linear systems of equations of cross products (without going into too much detail, this didn't work for me, either)
(3) Solution using unit vectors along the lines and from one line to the other along with the Law of Sines to calculate the distance from one of the points to the point of intersection (This is close to working, but it has problems, too.)

Does anyone know of any code out there that would perform this task or of a simple mathematical way to calculate this simpler? Any help would be greatly appreciated.
 
Well i do not code your solution but bring you the basic idea:

1)
line1:
l1.v1: l1.v1.x l1.v1.y l1.v1.z
l1.v2: l1.v2.x l1.v2.y l1.v2.z

line2:
l2.v1: l2.v1.x l2.v1.y l2.v1.z
l2.v2: l2.v2.x l2.v2.y l2.v2.z

with this you can find the two equations of each line:
with the form: Ax+By+Cz=D Ex+Fy+Gz=H for each one.

Then take 3 of these eq and solve it to find the x y and z
which is the point of intersection.

One of the eq is redundant because you can find the intersection point of a line with a plane (2eqs for the line and 1 for the plane).

You must evaluate x y and z by hand and put it into terms of the l1 and l2 members... its a little boring to do it... maybe later i put it to you, or maybe not.

XD See you!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top