How Fortune’s algorithm sweeps a Voronoi diagram

Short answer: Fortune’s algorithm computes the Voronoi diagram of a planar point set by sweeping a horizontal line downward and maintaining a beach line of parabolic arcs. Each site above the sweep line owns the points closer to it than to the sweep line, and the boundary of those regions is a sequence of parabolas. Site events insert an arc. Circle events, where three arcs meet and the middle one disappears, record a Voronoi vertex. The sweep runs in O(n log n) time.


What the problem actually asks

The Voronoi cell of a site is the set of points closer to that site than to any other. A direct construction of every perpendicular bisector is quadratic. The sweep turns the global definition into a local one: above the sweep line the diagram is finished, and on the beach line the only arcs that can interact are neighbors. A new site splits one arc. A circle event removes an arc when the sweep reaches the bottom of a circle through three consecutive sites.

The priority queue holds site events, known in advance, and circle events, discovered when three consecutive arcs on the beach line have a circle whose lowest point is still below the sweep. A circle event is discarded if one of the arcs has already disappeared.


What the algorithm guarantees

The algorithm produces the Voronoi diagram, a planar graph with O(n) vertices and edges, in O(n log n) time. Extra memory is the beach line, usually a balanced tree of arcs, and the event queue. Degenerate cases, four cocircular sites or two sites on the same horizontal line, need a tie break or a symbolic perturbation. The Delaunay triangulation is the dual: connect sites whose cells share an edge. Computing the Delaunay triangulation and dualizing is an alternative route to the same diagram.

The beach line is not a polyline of bisectors already in the final diagram. The arcs move as the sweep moves. The stored output is the sequence of breakpoints and the vertices emitted at circle events.


The working steps

  1. Sort the sites by decreasing y. Insert them as site events in a priority queue. The beach line starts empty.
  2. On a site event, find the arc directly above the site on the current beach line, split it, and create two new breakpoints that trace a Voronoi edge. Check the new consecutive triples for circle events and queue any whose bottom lies below the sweep.
  3. On a circle event, record a Voronoi vertex at the circle’s center, delete the middle arc, and join the edges. Check the new neighboring triples for circle events. Drop the event if the arc is already gone.
  4. After the queue empties, attach the unfinished edges to a bounding box or leave them as infinite rays.
  5. The Delaunay triangulation connects the two sites that defined each finished Voronoi edge.

The n log n bound requires a logarithmic beach-line search. An array scan of the beach line at every event makes the algorithm quadratic. Cocircular degeneracies must be defined. A Delaunay triangulation computed another way is the dual, not a different geometric object.


Approaches that look simpler and fail

Approach Why it fails when a disappeared arc still fires its circle event
Process every queued circle event even after an arc was deleted The triple no longer exists on the beach line. The event would insert a vertex that is not in the diagram. Test that the arc is still there.
Scan the entire beach line as an array at every site The diagram can still be right and the time is O(n²). The beach line has to be a search tree keyed by x.
Ignore two sites with the same y The sweep hits them together. Without a tie break the arc insertion order is undefined and edges can cross.
Expect the beach-line parabolas to be stored as the output They are the sweep state. The output is the vertices and edges left behind.

The dual graph is the Delaunay triangulation. A convex hull is the limit of a Voronoi diagram with a point at infinity, and it is computed directly by Andrew or Graham. Fortune’s algorithm is the beach-line sweep.


A working example

This Python fragment sweeps sites from top to bottom, splits the beach arc above each site, and closes an arc when the sweep hits the bottom of a circle event. The three sites (0, 0), (2, 0), and (1, 2) produce one Voronoi vertex at 1.00 0.75.

import heapq
sites = [(0.0, 0.0), (2.0, 0.0), (1.0, 2.0)]

class Arc:
    def __init__(self, site):
        self.site = site
        self.event = None

def cross(a, b, c):
    return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])

def circle(a, b, c):
    d = 2 * (a[0] * (b[1] - c[1]) + b[0] * (c[1] - a[1]) + c[0] * (a[1] - b[1]))
    if abs(d) < 1e-12:
        return None
    ux = ((a[0] ** 2 + a[1] ** 2) * (b[1] - c[1]) + (b[0] ** 2 + b[1] ** 2) * (c[1] - a[1]) + (c[0] ** 2 + c[1] ** 2) * (a[1] - b[1])) / d
    uy = ((a[0] ** 2 + a[1] ** 2) * (c[0] - b[0]) + (b[0] ** 2 + b[1] ** 2) * (a[0] - c[0]) + (c[0] ** 2 + c[1] ** 2) * (b[0] - a[0])) / d
    r = ((ux - a[0]) ** 2 + (uy - a[1]) ** 2) ** 0.5
    return (ux, uy), r

def intersections(p, q, ly):
    px, py = p
    qx, qy = q
    dp, dq = py - ly, qy - ly
    if abs(dp) < 1e-12:
        return [px]
    if abs(dq) < 1e-12:
        return [qx]
    a = dq - dp
    b = -2 * px * dq + 2 * qx * dp
    c = dq * px * px - dp * qx * qx + dp * dq * (py - qy)
    if abs(a) < 1e-12:
        return [] if abs(b) < 1e-12 else [-c / b]
    disc = b * b - 4 * a * c
    if disc < 0:
        return []
    root = disc ** 0.5
    return [(-b - root) / (2 * a), (-b + root) / (2 * a)]

def breakpoint(left, right, ly):
    xs = intersections(left, right, ly)
    if not xs:
        return (left[0] + right[0]) / 2
    def on_beach(focus, x):
        return (x - focus[0]) ** 2 / (2 * (focus[1] - ly)) + (focus[1] + ly) / 2
    chosen = xs[0]
    for x in xs:
        if abs(left[1] - ly) < 1e-12 or abs(right[1] - ly) < 1e-12:
            return x
        if on_beach(left, x - 1e-4) <= on_beach(right, x - 1e-4):
            chosen = x
    return chosen

arcs = []
events = []
stamp = 0
vertices = []
for site in sites:
    stamp += 1
    heapq.heappush(events, (-site[1], site[0], stamp, "site", site))

def arc_at(x, ly):
    for i in range(len(arcs) - 1):
        if x < breakpoint(arcs[i].site, arcs[i + 1].site, ly):
            return i
    return len(arcs) - 1

def consider(i, ly):
    global stamp
    if i <= 0 or i >= len(arcs) - 1:
        return
    a, b, c = arcs[i - 1], arcs[i], arcs[i + 1]
    if cross(a.site, b.site, c.site) >= 0:
        return
    got = circle(a.site, b.site, c.site)
    if got is None:
        return
    center, radius = got
    bottom = center[1] - radius
    if bottom > ly + 1e-8:
        return
    stamp += 1
    b.event = stamp
    heapq.heappush(events, (-bottom, center[0], stamp, "circle", (b, center)))

while events:
    neg_y, _, eid, kind, payload = heapq.heappop(events)
    ly = -neg_y
    if kind == "site":
        site = payload
        if not arcs:
            arcs.append(Arc(site))
            continue
        i = arc_at(site[0], ly - 1e-8)
        arcs[i].event = None
        arcs[i:i + 1] = [Arc(arcs[i].site), Arc(site), Arc(arcs[i].site)]
        consider(i, ly)
        consider(i + 1, ly)
        consider(i + 2, ly)
    else:
        arc, center = payload
        if arc.event != eid or arc not in arcs:
            continue
        i = arcs.index(arc)
        vertices.append(center)
        arcs[i - 1].event = None
        arcs[i + 1].event = None
        del arcs[i]
        consider(i - 1, ly)
        consider(i, ly)

assert len(vertices) == 1
vx, vy = vertices[0]
assert abs(vx - 1) < 1e-6 and abs(vy - 0.75) < 1e-6
print(f"{vx:.2f}", f"{vy:.2f}")

Where it is used

Fortune’s sweep builds a Voronoi diagram, the nearest-region map used in GIS and in facility location. Computational-geometry libraries also compute the same diagram from a convex hull in one higher dimension. A k-d tree answers nearest neighbor queries without drawing the cells.


When you can drop this algorithm

Drop a quadratic bisector loop for any large point set. Use the sweep, with a real search tree for the beach line and a cancellation test on circle events.


Why this stays published

We publish this so a search for Fortune’s algorithm returns the beach line, the site and circle events, and the O(n log n) bound. Fortune’s algorithm computes a Voronoi diagram in O(n log n) time by sweeping a beach line of parabolic arcs and emitting a vertex at each valid circle event.

本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。

Leave a Reply

Your email address will not be published. Required fields are marked *