Your question, your audience. Choose who sees your identity—and your question—with question security.

If I have two lines in 3 dimensional space defined by:

Line 1: (x1,y1,z1) and (x2,y2,z2)

Line 2: (x3,y3,z3) and (x4,y4,z4)

Does anyone have the source code to solve this?

I am working in C#.Net

Line 1: (x1,y1,z1) and (x2,y2,z2)

Line 2: (x3,y3,z3) and (x4,y4,z4)

Does anyone have the source code to solve this?

I am working in C#.Net

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trialLine 1: (x1,y1,z1) and (x2,y2,z2)

Line 2: (x3,y3,z3) and (x4,y4,z4)

(x ,y ,z ) = (x1,y1,z1) = t*( x2-x1), (y2-y1), (z2-z1)) for the first line. t=0 gives (x1,y1,z1) and t=1 gives (x2,y2,z2)

In the example provided, the final answer is unclear to me (i.e. the (X,Y,Z) location of the intersection point).

Also as an aside, I'm not getting the cross product he is getting in his example (see below)

from article

a(V1 x V2) = a(-10,-11,-13)"

I get a(V x V2) = a (-10, 11, -13) (i.e. middle term positive).

In 3D there is another requirement: besides to be not parallel, the lines must be coplanar, say, they must be in a same plane.

The John Taylor's article Intersecting Lines in 3D: describes these conditions and gives some examples.

Jose

x = x1 + (x2 - x1)*t

y = y1 + (y2 - y1)*t

z = z1 + (z2 - z1)*t

if lines are

Line A --> (xa1,ya1, za1, xa2,ya2, za2) and

Line B --> (xb1,yb1, zb1, xb2,yb2, zb2),

first define the parametric equations

Line A

x = xa1 + (xa2 - xa1) * ta

y = ya1 + (ya2 - ya1) * ta

z = za1 + (za2 - za1) * ta

Line B

x = xb1 + (xb2 - xb1) * tb

y = yb1 + (yb2 - yb1) * tb

z = zb1 + (zb2 - zb1) * tb

To check if they are parallel, get the vectors for each line.

Line A

(the components of the vector are the coefficients of ta):

M1 = (xa2 - xa1) * i + (ya2 - ya1) * j + (za2 - za1) * k

Line B

(do the same as for Line A, by using the coefficients of tb):

M2 = (xb2 - xb1) * i + ...

If M1 and M2 are equal or proportional, the lines are parallel, so there is no interception point.

If not, go ahead.

Now set the x and y values.

Of course, x and y must be the same in both lines equations, so,

x = xa1 + (xa2 - xa1) * ta = xb1 + (xb2 - xb1) * tb

and

y = ya1 + (ya2 - ya1) * ta = yb1 + (yb2 - yb1) * tb

By solving tha above equations, we have values for ta and tb.

Now, just apply these values in the z equations to chek is they are true.

If so, you found the interception point, if not, they don't intercept each another.

Jose

Algorithms

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Experts Exchange Solution brought to you by

Enjoy your complimentary solution view.

Get every solution instantly with premium.
Start your 7-day free trial.