Download presentation
Presentation is loading. Please wait.
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
Sweeping a polygon Move line downward and note how the form of the intersection of the line with the polygon changes
7
Sweeping a polygon 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 < 180o end v. if its two neighbors lie above it and the interior angle at v is < 180o split v. if its two neighbors lie below it and the interior angle at v is > 180o merge v. if its two neighbors lie above it and the interior angle at v is > 180o other vertices are called regular v v v v
9
Note In the previous definition, a point q is below another point p if py>qy or py=qy and px < qx 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 l y-monotone implies no merge or split vertices
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 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 avi vi+1…vkb, where vi vi+1…vk are consecutive vertices of P, such that this chain does not intersect (ab), and such that the interior of the polygon avi vi+1…vkba lies completely outside of P Suppose that vi vi+1…vk 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 v l a b
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 py>qy or py=qy and px < qx It takes O(n log n) time to order vertices No new event points are generated during the plane sweep! Let v1,v2,…,vn be vertices of P in counterclockwise order Let e1,e2,…,en be edges of P such that ei = vivi+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 helper(e) e diagonal
17
Helper of an edge Note: a helper of an edge can be the upper endpoint of this edge! helper(e') 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 is immediately to the left of v on the sweep line helper(e) e v New helper(e)
20
? Example 1 11 9 2 12 7 10 We met a merge vertex
It is logical to connect it to vertex 6, which is below! 6 4 8 5 3
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 e v a a becomes new helper of e, so we connect a and v!
v becomes helper of e v e a a becomes new helper of e, so we connect a and v!
23
Example v becomes helper of e v 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 vi 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(vi)
HandleEndVertex(vi) Insert ei in T helper(ei)=vi If helper(ei-1) is a merge vertex Insert the diagonal connecting vi to helper(ei-1) in D Delete ei-1 from T vi helper(ei-1) ei vi-1 ei-1 vi+1 vi
27
HandleSplitVertex(vi)
search in T to find the edge ej directly left of vi insert the diagonal, connecting vi to helper(ej), in D helper(ej) = vi insert ei in T helper(ei) = vi helper(ej) ej vi ei New helper(ej) and helper(ei)
28
HandleMergeVertex(vi)
If helper(ei−1) is a merge vertex insert the diagonal connecting vi to helper(ei−1) in D delete ei−1 from T search in T to find the edge ej directly left of vi If helper(ej) is a merge vertex Insert the diagonal connecting vi to helper(ej) in D helper(ej) = vi ei-1 h(ei-1) ej h(ej) vi New helper(ej)
29
HandleRegularVertex(vi)
If the interior of P lies to the right of vi Then If helper(ei−1) is a merge vertex Then Insert the diagonal connecting vi to helper(ei−1) in D End If Delete ei−1 from T Insert ei in T helper(ei) = vi helper(ei−1) ei-1 vi ei
30
ei ej vi ei-1 Else (i.e. interior of P lies to the left of vi)
Search in T to find the edge ej directly left of vi If helper(ej) is a merge vertex Then Insert the diagonal connecting vi to helper(ej) in D End If helper(ej) = vi helper(ej) ei ej vi ei-1 Note: in this case we do not modify T since there is no interior of P immediately to the right of ei or ei-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 vi 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(n log n) O(log n)
33
HandleStartVertex(vi)
HandleEndVertex(vi) Insert ei in T helper(ei)=vi O(log n) If helper(ei-1) is a merge vertex Insert the diagonal connecting vi to helper(ei-1) in D Delete ei-1 from T O(1) vi O(log n) helper(ei-1) ei vi-1 ei-1 vi+1 vi
34
HandleSplitVertex(vi)
search in T to find the edge ej directly left of vi insert the diagonal, connecting vi to helper(ej), in D helper(ej) = vi insert ei in T helper(ei) = vi O(log n) O(1) helper(ej) ej vi ei New helper(ej) and helper(ei)
35
HandleMergeVertex(vi)
If helper(ei−1) is a merge vertex insert the diagonal connecting vi to helper(ei−1) in D delete ei−1 from T search in T to find the edge ej directly left of vi If helper(ej) is a merge vertex Insert the diagonal connecting vi to helper(ej) in D helper(ej) = vi O(1) O(log n) O(log n) ei-1 O(1) h(ei-1) ej h(ej) vi New helper(ej)
36
HandleRegularVertex(vi)
If the interior of P lies to the right of vi Then If helper(ei−1) is a merge vertex Then Insert the diagonal connecting vi to helper(ei−1) in D End If Delete ei−1 from T Insert ei in T helper(ei) = vi O(1) helper(ei−1) O(log n) ei-1 O(log n) vi ei
37
ei ej vi ei-1 Else (i.e. interior of P lies to the left of vi)
Search in T to find the edge ej directly left of vi If helper(ej) is a merge vertex Then Insert the diagonal connecting vi to helper(ej) in D End If helper(ej) = vi O(log n) O(1) helper(ej) ei ej vi ei-1 Note: in this case we do not modify T since there is no interior of P immediately to the right of ei or ei-1
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.