[Math] How to determine if two lines in 3D intersect

3dlinear algebra

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.

Best Answer

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.)