Sweep Line (Plane Sweep)

A vertical line sweeps left→right; events drive a status structure; intersections are detected when neighbors meet.

Simple sweep: O(n log n) Bentley–Ottmann: O((n + k) log n) Naive all-pairs: O(n²)

Plane & Sweep Line

segment active (in status) being tested intersection sweep line
Sweep x:  |  Events: 0  |  Active: 0  |  Intersections (k): 0  |  Neighbor tests: 0
Slow Fast
Custom segments (x1,y1,x2,y2 per line)

Event Queue (sorted by x)

Status Structure (y-order)

What's happening

Press Run to start the sweep, or Step to advance one event at a time. The orange vertical line is the sweep line; it stops only at events.

Complexity

OperationCost
Sort all eventsO(n log n)
Status insert / delete / neighborO(log n)
Event-queue extract-min / insertO(log n)
Bentley–Ottmann (report all)O((n + k) log n)
Naive all-pairs baselineO(n²)

Operation Log