Presentation is loading. Please wait.

Presentation is loading. Please wait.

Triangulating a monotone polygon

Similar presentations


Presentation on theme: "Triangulating a monotone polygon"— Presentation transcript:

1 Triangulating a monotone polygon

2 y-monotone polygon: left and right chains
Left chain We will also assume that the polygon is strictly y-monotone, i.e. it is y-monotone and has no horizontal edges. Additionally, you may assume that no two vertices have the same y-coordinate

3 1 Idea of the algorithm: 2 3 We handle vertices in order of decreasing y-coordinates and add diagonals going up whenever possible 4 5 6 7 8 9 10 11 12 13 14

4 Invariant of the algorithm
1 Invariant of the algorithm 2 3 The part above the sweep line that has not been triangulated yet has the form of a “funnel”: 4 5 6 Reflex vertices one side of the boundary consists of a part of a single edge of the polygon; vertices on the other side of the boundary (except for the highest vertex) are reflex vertices, i.e. the interior angle at these vertices is at least 180o 7 8 funnel 9 10 11 12 13 14

5 Invariant of the algorithm
1 Invariant of the algorithm 2 3 4 5 6 7 8 9 10 11 12 13 14

6 Strategy Handle vertices from top to bottom
Use stack S to store vertices The lowest vertex encountered so far is on the top of the stack Add diagonals (going up) from the active vertex to other vertices on the stack as long as it is possible, and remove (pop) the vertices to which the diagonals are drawn, from the stack, except the last one Push the active vertex onto the stack S Note: at every moment, vertices on the stack are reflex vertices

7 1 Stack S 2 3 13 12 11 10 9 8 7 6 5 4 3 2 1 4 5 6 7 8 9 10 11 12 13 14

8 If next vertex is on the opposite chain to the vertices on the stack…

9 If next vertex is on the same chain as the vertices on the stack…
Case 1 Case 2

10 Algorithm TriangulateMonotonePolygon(P)
Input. A strictly y-monotone polygon P stored in a doubly-connected edge list D Output. A triangulation of P stored in the doubly-connected edge list D Merge the vertices on the left chain and the vertices on the right chain of P into one sequence (priority queue), sorted on decreasing y-coordinate. Let u1 , …, un denote the sorted sequence. Initialize an empty stack S, and push u1 and u2 onto it

11 For i = 3 to n – 1 Do If ui and the vertex on top of S are on different chains Then pop all vertices from S insert into D a diagonal from ui to each popped vertex, except the last one push ui-1 and ui onto S

12 Else (i.e. when they are on the same chain)
Pop one vertex from S Pop the other vertices from S as long as the diagonals from ui to them are inside P Insert these diagonals into D Push the last vertex that has been popped back onto S Push ui onto S End If End For Add diagonals from un to all stack vertices except the first and the last one.

13 Running Time Theorem 3.7 A y-monotone polygon with n vertices can be triangulated in linear time, i.e. in O(n) time Taking into account that a simple polygon can be split into monotone pieces in O(n log n) time, we obtain the following theorem: Theorem 3.8 A simple polygon with n vertices can be triangulated O(n log n) time

14 (n-3) executions of the For loop
For i = 3 to n – 1 Do If ui and the vertex on top of S are on different chains Then pop all vertices from S insert into D a diagonal from ui to each popped vertex, except the last one push ui-1 and ui onto S Several vertices are popped 2 vertices are pushed onto stack

15 Else (i.e. when they are on the same chain)
Pop one vertex from S Pop the other vertices from S as long as the diagonals from ui to them are inside P Insert these diagonals into D Push the last vertex that has been popped back onto S Push ui onto S End If End For Add diagonals from un to all stack vertices except the first and the last one. Several vertices are popped 2 vertex are pushed onto stack

16 Running time Thus, for each execution of the For loop:
At most 2 vertices are pushed Several vertices are popped Thus the total number of pushes is 2(n-3) = O(n) But the number of popped vertices cannot exceed the number of pushed vertices, so the number of pops is also O(n) Therefore the total number of operations is O(n), as required


Download ppt "Triangulating a monotone polygon"

Similar presentations


Ads by Google