Polygon Clipping Simulator: Sutherland-Hodgman & Beyond

simulator intermediate ~10 min
Loading simulation...
35% area retained after clipping

A pentagon clipped against a square at 50% overlap retains approximately 35% of its original area, producing a polygon with 5–7 vertices depending on exact geometry.

Formula

Sutherland-Hodgman: O(Sₛ × Sᶜ) — subject edges × clip edges
A = ½|Σ(xᵢyᵢ₊₁ − xᵢ₊₁yᵢ)| — shoelace area formula
Intersection: t = (n·(q−p₁)) / (n·(p₂−p₁)) — line-edge parameter

Cutting Shapes to Fit

Polygon clipping answers a simple question: what remains when you cut one polygon with another? This operation is essential every time your GPU renders a 3D scene (viewport clipping), every time a GIS computes land use overlap, and every time a CAD system performs a Boolean intersection. The Sutherland-Hodgman algorithm, published in 1974, remains the workhorse implementation.

Sutherland-Hodgman Algorithm

The algorithm processes the clip window one edge at a time. For each clip edge, it walks the subject polygon's vertices and classifies each as inside or outside. Four cases arise: inside-to-inside (keep vertex), inside-to-outside (output intersection), outside-to-outside (skip), outside-to-inside (output intersection then vertex). After all clip edges are processed, the surviving vertices form the clipped polygon.

Handling Complexity

When polygons are concave, clipping can produce multiple disconnected regions. Sutherland-Hodgman generates a single (possibly self-intersecting) polygon in this case. The Weiler-Atherton algorithm (1977) correctly handles concavity by tracing intersections around both polygons, producing separate output components. This simulator uses the simpler Sutherland-Hodgman approach with convex clip windows.

From Graphics to Geography

Every pixel on your screen has been polygon-clipped — the GPU's rasterizer clips triangles against the viewport frustum before shading. In GIS, polygon clipping overlays thematic maps: intersecting forest coverage with administrative boundaries reveals forest area per district. And in computational fabrication, clipping polygons against tool paths determines material removal — connecting abstract geometry to physical manufacturing.

FAQ

What is polygon clipping?

Polygon clipping computes the intersection of a subject polygon with a clip window (another polygon). The result is the portion of the subject that falls within the window. It is fundamental to computer graphics (viewport clipping), GIS (map overlay), and CAD (Boolean operations on shapes).

How does Sutherland-Hodgman clipping work?

The algorithm clips the subject polygon against each edge of the clip window sequentially. For each clip edge, it processes subject vertices one by one: if a vertex is inside, it is kept; if outside, it is discarded; edge crossings generate new intersection vertices. After processing all clip edges, the result is the clipped polygon.

Can polygon clipping produce multiple polygons?

Yes. When a concave subject polygon intersects a clip window, the result can be multiple disconnected polygons. Sutherland-Hodgman produces a single polygon (possibly self-intersecting). The Weiler-Atherton algorithm correctly handles this case, producing separate output polygons.

Where is polygon clipping used?

Viewport clipping in rendering pipelines, map overlay in GIS (intersection of land use and administrative boundaries), collision detection in physics engines, shadow computation in ray tracing, and Boolean operations (union, intersection, difference) in CAD systems.

Sources

Embed

<iframe src="https://homo-deus.com/lab/computational-geometry/polygon-clipping/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub