Presentation is loading. Please wait.

Presentation is loading. Please wait.

Polygon Triangulation. Triangulation We already know that any polygon can be triangulated by means of diagonals (Theorem 3.1) It is easy to triangulate.

Similar presentations


Presentation on theme: "Polygon Triangulation. Triangulation We already know that any polygon can be triangulated by means of diagonals (Theorem 3.1) It is easy to triangulate."— Presentation transcript:

1 Polygon Triangulation

2 Triangulation We already know that any polygon can be triangulated by means of diagonals (Theorem 3.1) It is easy to triangulate a convex polygon Therefore the first idea is to decompose a polygon by means of diagonals into convex pieces and then triangulate each piece Unfortunately, to decompose a polygon into convex pieces is as hard as to triangulate it!

3 Strategy Partition a polygon into monotone pieces Triangulate each monotone piece

4 Partitioning into monotone pieces

5 Idea We will use plane sweep method to partition pieces into y-monotone pieces, i.e. the pieces which are monotone with respect to the y-axis

6 Move line downward and note how the form of the intersection of the line with the polygon changes Sweeping a polygon

7 Types of vertices: start end regular split merge

8 Formal definitions With respect to the y-axis, a vertex v is called  start v. if its two neighbors lie below it and the interior angle at v is < 180 o  end v. if its two neighbors lie above it and the interior angle at v is < 180 o  split v. if its two neighbors lie below it and the interior angle at v is > 180 o  merge v. if its two neighbors lie above it and the interior angle at v is > 180 o other vertices are called regular v v v v

9 Note In the previous definition, a point q is below another point p if p y >q y or p y =q y and p x < q x For example, the following is a split vertex: v

10 Lemma 3.4 A polygon without horizontal edges is y-monotone (i.e. monotone with respect to the y-axis) if an only if it has no split or merge vertices y

11 Proof  Proof by contradiction: assume that P has a split vertex v (similarly for the case of a merge vertex)  Let l be a horizontal line below v such that the distance between v and l is less then the distance between l and any other vertex of P  Then the intersection of l and P is not connected y-monotone implies no merge or split vertices v l

12 Proof No merge or split vertices implies monotone  Proof by contradiction: assume that P is not monotone  Let l be a horizontal line such that the intersection of l and P is not connected  Then there exists two points, a and b, in the intersection of l and P, such that the open interval (ab) is in the complement of P  Then there exists a chain av i v i+1 …v k b, where v i v i+1 …v k are consecutive vertices of P, such that this chain does not intersect (ab), and such that the interior of the polygon av i v i+1 …v k ba lies completely outside of P  Suppose that v i v i+1 …v k there are vertices above the line l (the case when there are vertices only below is similar)  Let v be the highest of such vertices  It is easy to see that v is a split vertex

13 Proof No merge or split vertices implies monotone l a b v

14 Monotone pieces Thus to partition a polygon into monotone pieces we need to "get rid" of all split and merge vertices We will do this by adding diagonals during the plane sweep:  A diagonal going "upward" from each split vertex  A diagonal going "downward" from each merge vertex

15 Plane sweep: preparation Event points are vertices of polygon P Vertices are ordered as follows: p>q if p y >q y or p y =q y and p x < q x It takes O(n log n) time to order vertices No new event points are generated during the plane sweep! Let v 1,v 2,…,v n be vertices of P in counterclockwise order Let e 1,e 2,…,e n be edges of P such that e i = v i v i+1 Each time when the sweep line reaches split vertex we add a diagonal to a vertex lying above the sweep line In the case of merge vertices, diagonals are added later during the algorithm

16 Helper of an edge For a given position of the sweep line, the helper of an edge e, helper (e), is defined as the lowest vertex above the sweep line such that the horizontal segment connecting the vertex to e lies inside polygon P e diagonal helper(e)

17 Helper of an edge Note: a helper of an edge can be the upper endpoint of this edge! e' helper(e')

18 Handling a split vertex Suppose that the sweep line reached a split vertex v We need to connect it to some other vertex so that the diagonal is inside P Therefore a good candidate for this other vertex is a vertex which is close to v in some sense, e.g. in vertical direction If e is the edge immediately to the left of v on the sweep line, we can connect v to the helper(e) Note: v becomes the new helper of e

19 Handling a split vertex e helper(e) v New helper(e) e is immediately to the left of v on the sweep line

20 Example ? We met a merge vertex It is logical to connect it to vertex 6, which is below! 4 5 6

21 Handling a merge vertex Suppose that the sweep line reached a merge vertex v We need to connect it to some other vertex so that the diagonal is inside P We will find this vertex below the sweep line Namely, If e is the edge immediately to the left of v on the sweep line, then v becomes helper(e) We will connect v to the new helper(e) at the moment when it changes! If the helper of e is never replaced, we connect v to the lower endpoint of e

22 Example v v becomes helper of e e a a becomes new helper of e, so we connect a and v!

23 Example v v becomes helper of e e a The helper of e never changed until we reached the lower endpoint of e, so we connect the lower endpoint of e and v

24 Data structures Event (priority) queue Q (contains vertices of P in the order of decreasing y-coordinates) Self-balancing binary search tree T  The edges of P intersecting the sweep line are stored in T  With each edge in T we store its helper  Note: due to the nature of the algorithm, we need to store in T only those edges of P that have the interior of P to their right T, together with helpers, form the status of the algorithm The status changes as the sweep line moves (we update information about edges and helpers) DCEL to store information about P and subsequently added diagonals

25 Algorithm MakeMonotone(P) Input. A simple polygon P stored in a doubly-connected edge list D Output. A partitioning of P into monotone subpolygons, stored in D  Construct a priority queue Q on the vertices of P  use y-coordinates to determine priority  if two points have the same y-coordinate, the one with smaller x-coordinate has higher priority  Initialize an empty binary search tree T  While Q is not empty Do  remove the vertex v i with the highest priority from Q  call the appropriate procedure to handle the vertex, depending on the type of the vertex  End Do

26 HandleStartVertex(v i )  Insert e i in T  helper(e i )=v i HandleEndVertex(v i )  If helper(e i-1 ) is a merge vertex  Insert the diagonal connecting vi to helper(e i-1 ) in D  Delete e i-1 from T vivi eiei v i+1 e i-1 vivi v i-1 helper(e i-1 )

27 HandleSplitVertex(v i )  search in T to find the edge e j directly left of v i  insert the diagonal, connecting v i to helper(e j ), in D  helper(e j ) = v i  insert e i in T  helper(e i ) = v i ejej helper( e j ) vivi New helper(e j ) and helper(e i ) eiei

28 HandleMergeVertex(v i )  If helper(e i−1 ) is a merge vertex  insert the diagonal connecting vi to helper(e i−1 ) in D  delete e i−1 from T  search in T to find the edge e j directly left of v i  If helper(e j ) is a merge vertex  Insert the diagonal connecting v i to helper(e j ) in D  helper(e j ) = v i vivi e i-1 h(e j ) New helper(e j ) ejej h(e i-1 )

29 HandleRegularVertex(v i )  If the interior of P lies to the right of v i Then  If helper(e i−1 ) is a merge vertex Then  Insert the diagonal connecting vi to helper(e i−1 ) in D  End If  Delete e i−1 from T  Insert e i in T  helper(e i ) = v i vivi e i-1 eiei helper(e i−1 )

30  Else (i.e. interior of P lies to the left of v i )  Search in T to find the edge e j directly left of v i  If helper(e j ) is a merge vertex Then  Insert the diagonal connecting v i to helper( e j ) in D  End If  helper(e j ) = v i  End If vivi e i-1 eiei ejej helper(e j ) Note: in this case we do not modify T since there is no interior of P immediately to the right of e i or e i-1

31 Running time Claim. The algorithm MakeMonotone(P), that partitions P into monotone pieces, requires O(n log n) time Notes  The algorithm described above is due to Lee and Preparata (1977)  It was an open problem whether a faster than O(n log n) time algorithm exists for triangulation of a simple polygon  In 1990 Chazelle found an O(n)-time algorithm

32 Algorithm MakeMonotone(P)  Construct a priority queue Q on the vertices of P  use y-coordinates to determine priority  if two points have the same y-coordinate, the one with smaller x-coordinate has higher priority  Initialize an empty binary search tree T  While Q is not empty Do  remove the vertex v i with the highest priority from Q  call the appropriate procedure to handle the vertex, depending on the type of the vertex  End Do O (n log n) n times O(log n) O(n log n)

33 HandleStartVertex(v i )  Insert e i in T  helper(e i )=v i HandleEndVertex(v i )  If helper(e i-1 ) is a merge vertex  Insert the diagonal connecting vi to helper(e i-1 ) in D  Delete e i-1 from T vivi eiei v i+1 e i-1 vivi v i-1 helper(e i-1 ) O(log n) O(1) O(log n)

34 HandleSplitVertex(v i )  search in T to find the edge e j directly left of v i  insert the diagonal, connecting v i to helper(e j ), in D  helper(e j ) = v i  insert e i in T  helper(e i ) = v i ejej helper( e j ) vivi New helper(e j ) and helper(e i ) eiei O(1) O(log n)

35 HandleMergeVertex(v i )  If helper(e i−1 ) is a merge vertex  insert the diagonal connecting vi to helper(e i−1 ) in D  delete e i−1 from T  search in T to find the edge e j directly left of v i  If helper(e j ) is a merge vertex  Insert the diagonal connecting v i to helper(e j ) in D  helper(e j ) = v i vivi e i-1 h(e j ) New helper(e j ) ejej h(e i-1 ) O(1) O(log n) O(1)

36 HandleRegularVertex(v i )  If the interior of P lies to the right of v i Then  If helper(e i−1 ) is a merge vertex Then  Insert the diagonal connecting vi to helper(e i−1 ) in D  End If  Delete e i−1 from T  Insert e i in T  helper(e i ) = v i vivi e i-1 eiei helper(e i−1 ) O(1) O(log n)

37  Else (i.e. interior of P lies to the left of v i )  Search in T to find the edge e j directly left of v i  If helper(e j ) is a merge vertex Then  Insert the diagonal connecting v i to helper( e j ) in D  End If  helper(e j ) = v i  End If vivi e i-1 eiei ejej helper(e j ) Note: in this case we do not modify T since there is no interior of P immediately to the right of e i or e i-1 O(1) O(log n)


Download ppt "Polygon Triangulation. Triangulation We already know that any polygon can be triangulated by means of diagonals (Theorem 3.1) It is easy to triangulate."

Similar presentations


Ads by Google