Plane sweep and segment intersections
Maintain a local ordering while defining exactly which intersections are reported.
On this page
The question for today
What you’ll understand
- Explain why only neighboring active segments generate the next proper crossing event.
- Trace event-order changes and an output-sensitive intersection bound.
- Distinguish isolated crossings from shared endpoints and overlapping segments.
Testing every pair of segments ignores most of the geometry when intersections are sparse. A plane sweep moves an imaginary vertical line across the input and maintains the order of segments it currently meets. Endpoint and crossing events update that order. We first analyze nonvertical closed segments with distinct event x-coordinates, no shared endpoints, no triple crossings, and no collinear overlap. Every intersection is then a proper isolated crossing, and counts both crossing points and crossing pairs. Later tie policies must explicitly broaden this restricted input model.
The status is an order between events
The event queue is ordered by horizontal position, while a balanced status structure stores active segments from bottom to top immediately to the right of the current event. In an interval with no event, two active segments cannot reverse order without crossing. At an insertion or deletion, only the new neighboring pairs need to be checked. At a proper crossing, the two involved adjacent segments exchange order, and their newly exposed neighbors may create future events.
Why are adjacent pairs sufficient? Just before two segments cross in general position, no third active segment can remain strictly between them at their common point. Otherwise continuity would force another event first or produce the excluded triple intersection. This is a local certificate for the next crossing, not a claim that every pair of intersecting segments is adjacent throughout the sweep. A status comparator must use the intended side of an event consistently; changing a comparison coordinate without repairing the tree can invalidate its ordering.
Event coordinates are geometric constructions
Orientation signs classify whether finite segments cross, but the queue must also compare the constructed crossing coordinates. For rational input these coordinates are rational and can be compared exactly with suitable arithmetic. Robust input predicates alone do not certify a queue built from uncontrolled rounded intersections. The mathematical running time counts these comparisons at unit cost; exact rational numerator sizes and arithmetic work belong to a separate bit analysis. Output storage also costs at least one operation per reported intersection.
A standard event-queue implementation and stored output may use space proportional to the input plus the number of scheduled or reported events. The logarithmic running-time expression does not mean the sweep uses constant memory or that a dense arrangement is cheap. When the number of crossings is quadratic, explicitly listing them is already quadratic work. An intersection-existence problem can stop after its first certificate and is a different output task from reporting every crossing.
Ties must become part of the event definition
Closed segments can meet at endpoints, several segments can cross at one location, and different event points can have the same horizontal coordinate. A robust broader algorithm groups coincident events, declares a consistent ordering such as lexicographic coordinates, and processes all incident starting, ending, and crossing segments together. Vertical segments require an appropriate local range operation or a sweep convention designed for them. The simple adjacent-pair swap proof above does not, by itself, establish correctness for those cases.
Collinear overlaps are more fundamental: their intersection may be a whole interval containing infinitely many points. A finite crossing-point output is then the wrong specification. One can report overlapping segment pairs with overlap intervals, or split the union into elementary pieces with incidence information. Those choices have different output sizes and event logic. Before extending a sweep implementation, decide whether multiplicity counts points, pairs, or arrangement features; otherwise even the meaning of the claimed output-sensitive bound is unclear.
Work it through
Three crossings discovered in a changing order
Sweep segments , , and . Find their crossings in event order and trace the bottom-to-top order while all three are active.
Their supporting equations are , , and . At , their heights are , so the order is .
Solving pairs gives , , and . All lie strictly inside both corresponding segments and have distinct horizontal coordinates.
At the first event the order becomes , making and adjacent and exposing their crossing at . The second event gives , and the third gives .
There are three proper crossing points, so . The initially nonadjacent pair B,C becomes relevant after an earlier event rather than being checked as an arbitrary all-pairs candidate.
The living notebook
Explore the model
Interactive lab · function
Construct two crossing tangent segments
Pause/Reset and set BOTH controls to , : the tangent is . For a fresh comparison Pause/Reset and set BOTH to , : it is . Restrict both lines to and predict their crossing and reversed vertical order on either side. Control changes retain the paused clock.
- y at chosen x
- 0.608
- Tangent slope · 2ax
- 1.35
- Signed area · ax³/3
- 0.182
This lab uses only y = ax². Playback traces the curve within the fixed integration interval from 0 to x; it does not estimate numerical error or change the chosen point. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forThe quadratic instrument supplies each tangent’s point and slope. The segment restriction and sweep-order calculation are manual; it is not a segment-intersection sweep.
Pause & reason
Check your understanding
Your turn
Try it yourself
Two closed segments run from to and from to . Describe their exact intersection and give two sensible finite reporting conventions. Why cannot k simply mean the number of distinct intersection points?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Intersect the one-dimensional coordinate intervals before deciding what the reporting API should return.
Compare with the solution
Their intersection is the entire segment from to , containing infinitely many points. One finite convention reports the intersecting input pair together with this overlap interval. Another outputs elementary union pieces with the set of covering segment identifiers, including a doubly covered piece between two and four. Counting distinct intersection points is infinite here, so it cannot serve as the finite k in the isolated-crossing complexity theorem.
Keep the idea
Take it with you
- Neighbor certificates and event updates maintain the sweep order between crossings.
- Constructed event coordinates need arithmetic guarantees as well as orientation tests.
- Endpoint, concurrency, vertical, and overlap cases need explicit event and output policies.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.