How to determine if two lines in 3D intersect?

$\begingroup$

I've seen literally dozens of "line segment" intersect solutions from my trip around the Internet, but that's not ideal for my situation.

Given a single point on each line and a vector representing the direction of said line, is it possible to tell whether the lines intersect?

I'm going to be implementing an algorithm to do this in C++ if it's possible without defining endpoints which (due to integral / floating point precision) will undoubtedly cause accuracy errors when dealing with lines that push the bounds of precision.

$\endgroup$ 5

2 Answers

$\begingroup$

Two non-parallel lines $p_1+\mathbb R v_1$ and $p_2+\mathbb R v_2$ intersect if and only if $(v_1\times v_2)\cdot(p_1-p_2)=0$.

(But if you're implementing this in floating-point arithmetic, you're going to need to build in some safety margins anyway.)

$\endgroup$ 3 $\begingroup$

You have 2 lines in the parametric notation $(a_1 +tv_1,a_2 + tv_2, a_3 + tv_3)$ and $(b_1 +sw_1,b_2 + sw_2, b_3 + sw_3)$, just compare component by component and see if you can find $s$ and $t$ sotisfying all the 3 equations. Otherwise transoform them in 2 cartesian equations and substitute.

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like