Bentley-Ottmann Sweep Line
Process endpoint and crossing events while a balanced status order tests only neighboring segments.
Core idea
Sweep events from left to right while a balanced status structure orders segments by their current vertical position. Only neighboring segments can create the next unseen intersection.
Read the visualization
The sweep line advances through endpoint and crossing events. The status order inserts, removes, or swaps segments, and only newly adjacent pairs schedule tests.
Initialize endpoint events and an empty vertical sweep-line status.
Complexity and tradeoffs
Time: O((n+k) log n). Space: O(n+k). The output-sensitive bound reports k intersections without comparing every pair of n segments.
Where it fits
Bentley-Ottmann reports all intersections output-sensitively. Robust event ordering and exact predicates are essential in production geometry systems.