Drag a selection box over a map and only the streets inside it should stay visible. Zoom a camera in a game and only the part of the world inside the view frustum gets drawn. Both are the same question in disguise: given two polygons, what shape is their intersection?
If the two shapes were simple rectangles aligned to the axes, this would be nothing — compare four numbers and you're done. But real shapes are irregular: coastlines, building footprints, camera frustums, a lasso the user just drew freehand. Any edge of one polygon can cross any edge of the other, sometimes many times, and the boundary of the answer is stitched together from pieces of both shapes.
The problem is called polygon clipping, and turning "trace where they overlap" into a precise, always-correct algorithm took computer scientists real effort — mostly in the 1970s and 90s.
Comments
Loading comments...