Picture a handful of pins stuck into a corkboard. Now imagine stretching a piece of gift-wrap ribbon taut against the outermost pin, then swinging it around like a rigid arm until it snaps flat against the next outermost pin, then the next, and so on until the ribbon has come full circle. That physical motion — sweep, snap, sweep, snap — is precisely the gift wrapping algorithm, discovered by R. A. Jarvis in 1973 and often called the Jarvis march.
It solves the same problem as the convex hull: find the smallest convex polygon that encloses every point. But instead of sorting everything up front, gift wrapping builds the boundary one vertex at a time by always asking a single local question: "starting from the edge I just placed, which point is furthest around to the outside?"
It's slower than the fastest hull algorithms in the worst case, but it has a charming property: its running time scales with the size of the answer (the hull), not just the size of the input. Wrap a cloud of a million points that happens to have only five points on the boundary, and gift wrapping barely breaks a sweat.
Comments
Loading comments...