How to check if two line segments intersect?
Solution
Determining whether two line segments intersect is a fundamental problem in computational geometry.
This is not just about two infinite lines crossing — we need to verify if that intersection point actually lies within the finite bounds of both segments.
In the solution below, we express each segment parametrically, set up a system of equations, compute the determinant, and check parametric values to decide if, where and how the segments intersect.
By expressing both segments in a parametric form and solving for parameters \(t_1\) et \(t_2\), we can determine whether their lines intersect — and crucially, whether that intersection lies within each segment.
The use of the determinant provides a clean way to check for a unique intersection, while edge cases (parallel segments or overlapping) can also be handled.
This method is robust and widely used in geometry algorithms, computer graphics, and collision detection.
