Geometric Algorithms: Triangulating A Polygon
Geometric Algorithms: Triangulating A Polygon
Triangulating a polygon
Geometric Algorithms
Lecture 2: Triangulating a polygon
Geometric Algorithms
Two points in a simple polygon can see each other if their connecting line segment is in the polygon
Geometric Algorithms
Art Galley Problem: How many cameras are needed to guard a given art gallery so that every point is seen?
Geometric Algorithms
Geometric Algorithms
Triangulation, diagonal
Why are n/3 always enough? Assume polygon P is triangulated: a decomposition of P into disjoint triangles by a maximal set of non-intersecting diagonals Diagonal of P : open line segment that connects two vertices of P and fully lies in the interior of P
Geometric Algorithms
u v w u v w
In case 1, uw cuts the polygon into a triangle and a simple polygon with n 1 vertices, and we apply induction In case 2, vt cuts the polygon into two simple polygons with m and n m + 2 vertices 3 m n 1, and we also apply induction By induction, the two polygons can be triangulated using m 2 and n m + 2 2 = n m triangles. So the original polygon is triangulated using m 2 + n m = n 2 triangles
Geometric Algorithms
Geometric Algorithms
Geometric Algorithms
For a 3-colored, triangulated simple polygon, one of the color classes is used by at most n/3 colors. Place the cameras at these vertices This argument is called the pigeon-hole principle
Geometric Algorithms
Question: Why does the proof fail when the polygon has holes?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Using the two-ears theorem: (an ear consists of three consecutive vertices u, v, w where uw is a diagonal) Find an ear, cut it o with a diagonal, triangulate the rest iteratively Question: Why does every simple polygon have an ear? Question: How ecient is this algorithm?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Overview
A simple polygon is y-monotone i any horizontal line intersects it in a connected set (or not at all) Use plane sweep to partition the polygon into y monotone polygons Then triangulate each y-monotone polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Monotone polygons
A y-monotone polygon has a top vertex, a bottom vertex, and two y-monotone chains between top and bottom as its boundary Any simple polygon with one top vertex and one bottom vertex is y-monotone
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Vertex types
What types of vertices does a general simple polygon have? start stop split merge regular . . . imagining a sweep line going top to bottom
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
Find diagonals from each merge vertex down, and from each split vertex up A simple polygon with no split or merge vertices can have at most one start and one stop vertex, so it is y-monotone
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
Find diagonals from each merge vertex down, and from each split vertex up A simple polygon with no split or merge vertices can have at most one start and one stop vertex, so it is y-monotone
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
explored explored
unexplored
Geometric Algorithms
unexplored
Lecture 2: Triangulating a polygon
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
Where can a diagonal from a split vertex go? Perhaps the upper endpoint of the edge immediately left of the merge vertex?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
Where can a diagonal from a split vertex go? Perhaps the upper endpoint of the edge immediately left of the merge vertex?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
Where can a diagonal from a split vertex go? Perhaps the upper endpoint of the edge immediately left of the merge vertex?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
Where can a diagonal from a split vertex go? Perhaps the last vertex passed in the same component?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
Where can a diagonal from a split vertex go? Perhaps the last vertex passed in the same component?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Sweep ideas
Where can a diagonal from a split vertex go? Perhaps the last vertex passed in the same component?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Status of sweep
The status is the set of edges intersecting the sweep line that have the polygon to their right, sorted from left to right, and each with their helper: the last vertex passed in that component
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Helpers of edges
The helper for an edge e that has the polygon right of it, and a position of the sweep line, is the lowest vertex v above the sweep line such that the horizontal line segment connecting e and v is inside the polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
The status structure stores all edges that have the polygon to the right, with their helper, sorted from left to right in the leaves of a balanced binary search tree The events happen only at the vertices: sort them by y-coordinate and put them in a list (or array, or tree)
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Main algorithm
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Event handling
Start vertex v: Insert the counterclockwise incident edge in T with v as the helper
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Event handling
End vertex v: Delete the clockwise incident edge and its helper from T
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Event handling
Regular vertex v: If the polygon is right of the two incident edges, then replace the upper edge by the lower edge in T , and make v the helper If the polygon is left of the two incident edges, then nd the edge e directly left of v, and replace its helper by v
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Event handling
Merge vertex v: Remove the edge clockwise from v from T Find the edge e directly left of v, and replace its helper by v
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Event handling
Split vertex v: Find the edge e directly left of v, and choose as a diagonal the edge between its helper and v Replace the helper of e by v Insert the edge counterclockwise from v in T , with v as its helper
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Eciency
Sorting all events by y-coordinate takes O(n log n) time Every event takes O(log n) time, because it only involves querying, inserting and deleting in T
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Degenerate cases
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Representation
A simple polygon with some diagonals is a subdivision use a DCEL Question: How many diagonals may be chosen to the same vertex?
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
More sweeping
With an upward sweep in each subpolygon, we can nd a diagonal down from every merge vertex (which is a split vertex for an upward sweep!) This makes all subpolygons y-monotone
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Result
Theorem: A simple polygon with n vertices can be partitioned into y-monotone pieces in O(n log n) time
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
The algorithm
Sort the vertices top-to-bottom by a merge of the two chains Initialize a stack. Pop the rst two vertices Take the next vertex v, and triangulate as much as possible, top-down, while popping the stack Push v onto the stack
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Result
Theorem: A simple polygon with n vertices can be partitioned into y-monotone pieces in O(n log n) time Theorem: A monotone polygon with n vertices can be triangulated O(n) time Can we immediately conclude: A simple polygon with n vertices can be triangulated O(n log n) time ???
Geometric Algorithms
Towards an ecient algorithm Partitioning into monotone pieces Triangulating a monotone polygon Triangulating a simple polygon
Result
We need to argue that all monotone polygons together that we will triangulate have O(n) vertices Initially we had n edges. We add at most n 3 diagonals in the sweeps. So all monotone polygons together have at most 2n 3 edges, and therefore at most 2n 3 vertices Hence we can conclude that triangulating all monotone polygons together takes only O(n) time Theorem: A simple polygon with n vertices can be triangulated O(n log n) time
Geometric Algorithms