Line Segment Intersection
Use orientation cross products and bounding checks to classify proper, endpoint, collinear, and disjoint cases.
Core idea
Orientation cross products tell which side of one directed line each endpoint of the other segment occupies. Opposite sides imply a proper crossing; zero orientations require on-segment checks.
Read the visualization
The plane highlights both segments, endpoint orientations, and bounding boxes before labeling a proper crossing, endpoint touch, collinear overlap, or disjoint result.
Load both closed segments and their four endpoints.
Complexity and tradeoffs
Time: O(1). Space: O(1). Robust implementations must handle zero orientation and numeric precision explicitly.
Where it fits
Segment intersection is a primitive for clipping, polygon validity, collision detection, and sweep-line algorithms. Integer coordinates help avoid floating-point sign errors.