Presentation is loading. Please wait.

Presentation is loading. Please wait.

Brute-Force Triangulation 1. Find a diagonal. 2. Triangulate the two resulting subpolygons recursively. w u v u v w How to find a diagonal? leftmost vertex.

Similar presentations


Presentation on theme: "Brute-Force Triangulation 1. Find a diagonal. 2. Triangulate the two resulting subpolygons recursively. w u v u v w How to find a diagonal? leftmost vertex."— Presentation transcript:

1 Brute-Force Triangulation 1. Find a diagonal. 2. Triangulate the two resulting subpolygons recursively. w u v u v w How to find a diagonal? leftmost vertex case 1 case 2 closest to v O(n) time to find a diagonal at every step.  (n ) time in the worst case. 2

2 Triangulating a Convex Polygon  (n) time! Idea: Decompose a simple polygon into convex pieces. Triangulate the pieces. monotone as difficult as triangulation

3 y-monotone Pieces y-axis y-monotone if any line perpendicular to the y-axis has a connected intersection with the polygon. walk always downward or horizontal lowest vertex highest vertex Stragegy: Partition the polygon into monotone pieces and then triangulate.

4 Turn Vertex Turn vertex is where the walk from highest vertex to the lowest vertex switches direction. v At vertex v  Both adjacent edges are below.  The polygon interior lies above. Choose a diagonal that goes up.

5 Five Types of Vertices Point p = (x, y) is “below” a different point q = (u, v) if y u. Otherwise p is “above” q. p q p q Start vetex : lies above its two neighbors and has interior angle < . End vetex : lies below its two neighbors and has interior angle < . Merge vetex : lies below its two neighbors and has interior angle > . Split vetex : lies above its two neighbors and has interior angle > . Regular vetex : the remaining vertices (no turn). 4 types of turn vertices What happens if we rotate the polygon by  ? start vertices  end vertices split vertices  merge vertices

6 Local Non-Monotonicity Lemma A polygon is y-monotone if it has no split or merge vertices. Proof Suppose the polygon is not y-monotone. We prove that it contains a split or merge vertex. r interior p q l exterior qp = r l exterior interior Start at q, traverse the boundary counterclockwise until it crosses the line l again at point r. r There exists a horizontal line l intersecting the polygon in >1 components, of which the leftmost is a segment between some vertices p (left) and q (right). r  pr  p The highest vertex during the traversal from q to r must be a split vertex. r = p Traverse in the oppose direction from q and crosses line l again at point r’. The lowest point during this traversal must be a merge vertex. split vertex merge vertex

7 Partitioning into Monotone Pieces The lemma implies that the polygon will have y-monotone pieces once its split and merge vertices are removed.  Add a downward diagonal at every merge vertex.  Add an upward diagonal at every split vertex. Use a downward plane sweep. No new event point will be created except the vertices. The event queue is implemented as priority queue (e.g., heap). The next event found in time O(log n).

8 Removal of a Split Vertex e i-1 e j e k e i v i h(e ) j e : edge immediately to its left. j v : split vertex i e : edge immediately to its right. k or the upper vertex of e if such vertex does not exist. j jk h(e ): lowest vertex above v and between e and e. j i Connect v to h(e ). ij edge helper

9 Removal of a Merge Vertex e j e k v i e : edge immediately to its left. j v : merge vertex i e : edge immediately to its right. k But why not all in the same sweep? Merge vertices can be handled the same way in an upward sweep as split vertices in a downward sweep. i Connect v to v. m v : highest vertex below the sweep line and between e and e. m j k v m Check if the old helper is a merge vertex and add the diagonal if so. (The diagonal is always added if the new helper is a split vertex). v will replace v as the helper of e. m i j In case the helper of e is not replaced any more, connect to its lower endpoint. j

10 Sweep-Line Status Implemented as a binary search tree. Only edges to the left of the polygon interior are stored. Edges are stored in the left-to-right order. This is because we are only interested in edges to the left of split and merge vertices. With every edge e its helper h(e) is also stored.

11 DCEL Representation n vertices + n edges + 2 faces (initially) Adding an edge can be done in O(1) time. Construct a doubly-connected edge list to represent the polygon. Edges in the status BST and corresponding ones in DCEL cross-point each other. Add in diagonals computed for split and merge vertices.

12 The Algorithm MakeMonotone(P) Input: A simple polygon P stored in DCEL D. Output: A partitioning of P into monotone subpolygons stored in D. 1. Q  priority queue storing vertices of P 2. T   // initialize the status as a binary search tree. 3. i  0 4. while Q   5. do v  the highest priority vertex from Q // removal from Q 6. case v of 7. start vertex: HandleStartVertex(v ) 8. end vertex: HandleEndVertex(v ) 9. split vertex: HandleSplitVertx(v ) 10. merge vertex: HandleMergeVertex(v ) 11. regular vertex: HandleRegularVertex(v ) 12. i  i + 1 i i i i i i i

13 Handling Start & End Vertices v 5 e 5 v 7 v 6 v 8 v 10 v 9 v 12 v 11 v 13 v 15 v 14 v 1 v 2 v 3 v 4 e 4 e 6 e 7 e 8 e 10 e 9 e 11 e 12 e 14 e 13 e 15 e 3 e 2 e 1 HandleStartVertex(v ) 1. T  T  { e } 2. h(e )  v // set the helper ii i i insert into T HandleEndVertex(v ) 1.if h(e ) is a merge vertex 2. then insert the diagonal connecting v to h(e ) in D 3. T  T – { e } i i –1 i -1 i –1 i

14 Handling Split Vertex v 5 e 5 v 7 v 6 v 8 v 10 v 9 v 12 v 11 v 13 v 15 v 14 v 1 v 2 v 3 v 4 e 4 e 6 e 7 e 8 e 10 e 9 e 11 e 12 e 14 e 13 e 15 e 3 e 2 e 1 HandleSplitVertex(v ) 1.Search in T to find e directly left of v 2.insert the diagonal connect v to h(e ) into D 3.h(e )  v 4. T  T + { e } 5. h(e )  v i i i j j j i i ii

15 Handling Merge Vertex (1) v 5 e 5 v 7 v 6 v 8 v 10 v 9 v 12 v 11 v 13 v 15 v 14 v 1 v 2 v 3 v 4 e 4 e 6 e 7 e 8 e 10 e 9 e 11 e 12 e 14 e 13 e 15 e 3 e 2 e 1 HandleMergeVertex(v ) 1.if h(e ) is a merge vertex 2. then insert the diagonal connecting v to h(e ) in D 3. T  T – { e } 4.Search in T to find the edge e directly left of v. 5. if h(e ) is a merge vertex then insert the diagonal connecting v to h(e ) in D 6. h(e )  v i i –1 i -1 i –1 i j j i i i j j

16 Handling Merge Vertex (2) HandleMergeVertex(v ) 1.if h(e ) is a merge vertex 2. then insert the diagonal connecting v to h(e ) in D 3. T  T – { e } 4.Search in T to find the edge e directly left of v. 5. if h(e ) is a merge vertex then insert the diagonal connecting v to h(e ) in D 6. h(e )  v i i –1 i -1 i –1 i j j i i i j j v i e j h(e ) j e i – 1 h(e ) i –1

17 Handling Regular Vertices (1) v 5 e 5 v 7 v 6 v 8 v 10 v 9 v 12 v 11 v 13 v 15 v 14 v 1 v 2 v 3 v 4 e 4 e 6 e 7 e 8 e 10 e 9 e 11 e 12 e 14 e 13 e 15 e 3 e 2 e 1 HandleRegularVertex(v ) 1.if the polygon interior lies to the right of v 2. then if h(e ) is a merge vertex 3. then insert the diagonal connecting v to h(e ) in D 4. T  T – { e } 5. T  T + { e } 6. h(e )  v 7. else search in T to find the edge e directly left of v. 8. if h(e ) is a merge vertex then insert the diagonal connecting v to h(e ) in D 9. h(e )  v i i –1 i -1 i –1 i j i i i j i i i i j j

18 Handling Regular Vertices (2) HandleRegularVertex(v ) 1.if the polygon interior lies to the right of v 2. then if h(e ) is a merge vertex 3. then insert the diagonal connecting v to h(e ) in D 4. T  T – { e } 5. T  T + { e } 6. h(e )  v 7. else search in T to find the edge e directly left of v. 8. if h(e ) is a merge vertex then insert the diagonal connecting v to h(e ) in D 9. h(e )  v i i –1 i -1 i –1 i j i i i j i i i i j j v i e j h(e ) j

19 Correctness Theorem The algorithm adds a set of non-intersecting diagonals that partitions the polygon into monotone pieces. Proof The pieces that result from the partitioning contain no split or merge vertices. Hence they are monotone by an earlier lemma. We need only prove that the added segments are diagonals that intersect neither the polygon edges nor each other. Establish the above claim for the handling of each of the five type of vertices during the sweep. (Read the textbook on how to do this for the case of a split vertex.)

20 Running Time on Partitioning MakeMonotone(P) Input: A simple polygon P stored in DCEL D. Output: A partitioning of P into monotone subpolygons stored in D. 1. Q  priority queue storing vertices of P 2. T   3. i  0 4. while Q   5. do v  the highest priority vertex from Q 6. case v of 7. start vertex: HandleStartVertex(v ) 8. end vertex: HandleEndVertex(v ) 9. split vertex: HandleSplitVertx(v ) 10. merge vertex: HandleMergeVertex(v ) 11. regular vertex: HanleRegularVertex(v ) 12. i  i + 1 i i i i i i i // O(n) heap construction // O(log n) // O(log n) each case // queries and updates // in O(log n) time and // insertion of a diagonal // in O(1) time. Total time: O(n log n)Total storage: O(n)

21 Triangulating a y-Monotone Polygon Assumption The polygon is strictly y-monotone (no horizontal edges). It is for clarity of presentation and will be easily removed later. Order of processing: in decreasing y-coordinate. A stack S: vertices that have been encountered and may still need diagonals. Idea: add as many diagonals from the current vertex handled to those on the stack as possible. lowest vertex on top. funnel Invariants of iteration: One boundary of the funnel is a polygon edge. The other boundary is a chain of reflex vertices (with interior angles >  ) plus one convex vertex (the highest) at bottom of the stack. reflex vertices convex vertex current vertex

22 Case 1: Next Vertex on Opposite Chain current vertex u j u j –1 u j –4 u j –2 u j –3 e This vertex must be the lower endpoint of the single edge e bounding the chain. u j –1 u j –4 u j –3 u j –2 Pop these vertices from the stack. Add diagonals from the current vertex to them (except the bottom one) as they are popped. u j u j –1 Push the previous top of the stack and the current vertex back onto the stack.

23 Case 2: Next Vertex on the Same Chain current vertex u j u j –1 u j –4 u j –2 u j –3 The vertices that can connect to the current vertex are all on the stack. u j –2 u j –5 u j –4 u j –3 Pop one vertex from the stack. It shares an edge with the current vertex. u j u j –5 Pop other vertices from the stack as long as they are visible from the current vertex. Draw a diagonal between each of them and the current vertex. u j –5 Pushed the last popped vertex back onto the stack followed by the current vertex. u j –1 u j –4

24 The Triangulation Algorithm 2 1 j j j TriangulateMonotonePolygon(P) Input: A strictly y-monotone polygon P stored in DCEL D. Output: A triangulation of P stored in D. 1.Merge the vertices on the left and right chains into one sequence sorted in decreasing y-coordinate. (In case there is a tie, the one with smaller x-coordinate comes first.) 2. Push(u, S) 3.Push(u, S) 4.for j  3 to n – 1 5. do if u and Top(S) are on different chains 6. then while Next(Top(S))  NULL 7. v  Top(S) 8. Pop(S) 9. insert a diagonal from u to v 10. Pop(S) 11. Push(u, S) 12. Push(u, S) 13. else Pop(S) 14. while Top(S) is visible from u inside the polygon 15. v  Top(S) 16. insert a diagonal between u and v 17. Pop(S) 18. Push the last popped vertex back onto S 19. Push(u, S) j j j –1 j

25 An Example u 1 u 2 u 3 u 8 u 5 u 4 u 7 u 6 u 10 u 9 u 14 u 13 u 11 u 12 u 15 u 16 u 17 u 19 u 18 u 20 u 2 u 1 Start: u 2 u 1 u 3 j =3: j =4: u 2 u 1 u 3 u 4 j =5: u 1 u 2 u 4 u 5 j =6: u 1 u 5 u 5 u 6

26 Example (cont’d) u 1 u 2 u 3 u 8 u 5 u 4 u 7 u 6 u 10 u 9 u 14 u 13 u 11 u 12 u 15 u 16 u 17 u 19 u 18 u 20 u 6 u 5 j = 7: u 6 u 7 j =8: j =9: u 8 u 9 j =10: u 8 u 9 j =11: u 10 u 8 u u 6 u 7 u 7 u 8 u u 11

27 Example (Cont’d) u 1 u 2 u 3 u 8 u 5 u 4 u 7 u 6 u 10 u 9 u 14 u 13 u 11 u 12 u 15 u 16 u 17 u 19 u 18 u 20 j = 15: u 10 u 15 j = 16: u 10 u 15 u 16 j = 17: u 10 u 16 u 15 u 17 u 10 j = 18:j = 19: u 17 u 18 u 17 u 19 u 18 u 17

28 Removal of Strict y-monotonicity The running time of TriangulateMonotonePolygon is  (n). #pushes  2n – 4 (  2 vertices pushed each of n – 3 iteration steps plus 2 at the beginning) #pops  #pushes What to do if some vertices have the same y-coordinates? Treat them from left to right. The effect of this is equivalent to that of rotating the plane slightly clockwise and then every vertex will have different y coordinate.

29 Time Complexity of Triangulation 1. Partition a simple polygon into monotone pieces. 2. Triangulate each monotone piece. O(n log n)  (n) for all monotone pieces together Theorem A simple polygon can be triangulated in O(n log n) time and O(n) storage.

30 Triangulation of a Planar Subdivision The algorithm for splitting a polygon into monotone pieces does not use the fact that the polygon was simple. The plane sweep for decomposition of a polygon into monotone pieces takes as input only edges that lie to the left of the interior. This easily generalizes to a planar subdivision in a bounding box. Thus a planar subdivision with n vertices can also be triangulated in O(n log n) time using O(n) storage.


Download ppt "Brute-Force Triangulation 1. Find a diagonal. 2. Triangulate the two resulting subpolygons recursively. w u v u v w How to find a diagonal? leftmost vertex."

Similar presentations


Ads by Google