Intersection of lines in 3d space

How do you work out the intersection point of 2 lines in 3d space?



First check that they’re in the same plane. If they aren’t, they don’t. If they are, do the regular 2D case (in that plane, or just extend it to 3D).

The lines always intersect and are always on the same plane, so your solution is OK.

If they weren’t in the same plane, then I’ve worked out that you would need to solve a simultaneous equation of the form:

r = a1 + s(b1-a1)
r = a2 + t(b2-a2)

r = resultant intersection vertex (x,y,z) where the lines can have same co-ordinates.

a1 = start point of first line (x,y,z)
b1 = endpoint of first line (x,y,z)

a2 = start point of 2nd line (x,y,z)
b2 = end point of 2nd line (x,y,z)

Does anyone know of a fast routine that would be able to solve a simultaneous equation of this nature to gain s & t and therefore the solution? I can do it on paper, but I’ve never attempted to code something like this…



My poiunt was that if they are not in the same plane, they will not intersect. Ever. Thus, your question forumlation is not generally solvable for most inputs.

If you want to find the point on the two lines closest to the other line, you would have to write the distance between them as an equation in t1 and t2, and solve for t1, t2 with a local minimum solver (which might be simple enough to do analythically).