Presentation is loading. Please wait.

Presentation is loading. Please wait.

Polygon Triangulation Computational Geometry, WS 2007/08 Lecture 9 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.

Similar presentations


Presentation on theme: "Polygon Triangulation Computational Geometry, WS 2007/08 Lecture 9 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät."— Presentation transcript:

1 Polygon Triangulation Computational Geometry, WS 2007/08 Lecture 9 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg

2 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann2 Motivation: Guarding art galleries Art gallery theorem for simple polygons Partitioning of polygons into monotone pieces Triangulation of y-monotone polygons Agenda

3 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann3 Guarding art galleries “Art Gallery“ Problem Visibility polygon

4 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann4 Guarding art galleries The gallery is represented by a simple polygon A guard is represented by a point within the polygon Guards have a viewport of 360° A polygon is completely guarded, if every point within the polygon is guarded by at least one of the watchmen

5 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann5 Guarding art galleries We will consider the lower bound for the worst case: We want to determine the number of guards that suffice for an arbitrary polygon with n vertices. Even if two polygons have the same number of vertices, one may be easier to guard than the other.

6 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann6 Guarding a triangulated polygon

7 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann7 Triangulation of simple polygons w v u Does every simple polygon admit a triangulation? If yes, what is the number of triangles? Does any triangulation lead to the same number of triangles?

8 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann8 Theorem Theorem: Every simple polygon admits a triangulation, and any triangulation of a simple polygon with n vertices consists of exactly n-2 triangles. Proof:By induction on n. Let n>3, and assume theorem is true for all m<n. Let P be polygon with n vertices. We first prove the existence of a diagonal in P. Let v be leftmost vertex of P. Let u and w be two neighboring vertices of v. If uw lies in the interior of P we have found a diagonal. Else, there are one or more vertices inside the triangle defined by u, v, and w, or the diagonal uw. Let v´ be the farthest vertex from uw. The segment connecting v´ to v cannot intersect an edge of p (contradicts the definition of v´). Hence vv´ is a diagonal.

9 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann9 Consider leftmost vertex v of P Case 1: uw completely in P u v w u v w Case 2: uw not completely in P Proof of the existence of diagonals in P

10 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann10 Continuation of proof So a diagonal exists. Any diagonal cuts P in two simple sub- polygons P 1 and P 2. Let m 1 be the number of vertices of P 1 and m 2 the number of vertices of P 2. Both m 1 and m 2 must be smaller than n, so by induction P 1 and P 2 can be triangulated so P can be triangulated as well. Now we have to prove any triangulation of P contains n-2 triangles. Consider an arbitrary diagonal in some triangulation T p. This diagonal cuts P into 2 subpolygons with m 1 and m 2 vertices. Every vertex of P occurs in exactly one of 2 subpolygons. Hence m 1 +m 2 = n+2. So by induction any triangulation of P i contains m i -2 triangles  (m 1 -2) + (m 2 -2) = n-2 triangles.

11 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann11 Continuation of proof Number of triangles in any triangulation of a simple polygon with n vertices. Case 1: n=3 Case 2: n>3

12 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann12 Upper and lower bounds for the number of guards We know that for any simple polygon with n vertices (n-2) guards are always enough. But can we do better?

13 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann13 Upper and lower bounds for the number of guards Idea: Compute a 3-coloring of the vertices and place guards on a color. Result:  n/3  guards are sufficient.

14 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann14 Theorem Theorem: Each simple polygon is 3-colorable. Proof:Dual graph is a binary tree, this means that we can find a 3-coloring using a simple DFS. Corollary:  n/3  guards are always sufficient to guard a simple Polygon with n vertices.

15 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann15 Example

16 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann16 Art gallery theorem Theorem: For a simple polygon with n vertices,  n/3  cameras are occasionally necessary and always sufficient to have every point in the polygon visible from at least one of the cameras. Worst-case example?

17 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann17 Art gallery theorem Worst-case example:

18 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann18 Triangulation (Naive)

19 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann19 Triangulation of a convex polygon

20 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann20 l-Monotone Convex polygons are easy to triangulate. Unfortunately the partition into convex pieces is just as difficult as the triangulation. l-monotone l P A simple polygon is called monotone w.r.t. a line l if for any line l´ perpendicular to l the intersection of the polygon with l´ is connected (y-monotone, if l = y-axis). Observation: if P is y-monotone then P Consists of two y-monotone chains.

21 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann21 Two steps for triangulation 1. Divide P into y-monotone parts P 1,...,P k 2. Triangulate P 1,...,P k

22 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann22 Split and merge vertices = start vertex = end vertex = regular vertex = split vertex = merge vertex

23 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann23 Lemma:A polygon is y-monotone if it has no split vertices or merge vertices. Proof:Suppose P is not y-monotone  there is a horizontal line l that intersects P in more than one connected component. We show that P must have at least one split or merge vertex: pqr P split vertex (a) l r = p P q r´ merge vertex (b) Split and merge vertices

24 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann24 Five types of vertices = start vertex = end vertex = regular vertex = split vertex = merge vertex

25 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann25 Removal of Split and Merge nodes helper(e j ) is lowest vertex above the sweep line such that the horizontal segment connecting the vertex to e j lies inside P. ejej helper(e j ) ekek vivi e i-1 eiei l ejej ekek vivi vmvm Merge-nodes are split nodes in reverse. v i is the new helper of e j. We would like to connect v i to the highest vertex below the sweep line in between e j and e k

26 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann26 Removal of Split Vertices ejej ekek vivi e i-1 eiei l v i split vertex

27 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann27 Removal of Merge Vertices ejej ekek vivi vmvm v i merge vertex

28 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann28 Example vThelper a b c d e ! f g h i j ! k l m ! n o g a b c d e f h i j k l m n o

29 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann29 Example vThelper a ad ad = a b ad,bc bc = b c ad,ce ce = c d ce ce = d e ! ei ei = e f ei g ei,gl gl = g h ei,gl i gl gl = i j ! gl,jo jo = gl = j k gl l ln ln = l m ! ln,mo ln = mo = m n mo o a b c d e f g h i j k l m n o

30 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann30 Algorithm: MakeMonotone Input:A simple polygon P stored in a doubly-connected edge list D Output:A partitioning of P into monotone sub-polygons, stored in D Construct a priority queue Q on the vertices of P. Initialize an empty binary search tree T. while Q is not empty do remove the vertex v i with highest priority from Q call appropriate procedure to handle the vertex.

31 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann31 Handling start, end, and split vertices HandleStartVertex(v i ):T = T  {e i }, helper(e i ) = v i vivi eiei

32 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann32 Handling start, end, and split vertices a b c d e f g h i j k l m n o

33 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann33 Handling start, end and split vertices HandleEndVertex(v i ):if (helper(e i-i ) is merge vertex) then insert diagonal connecting v i to helper(e i-1 ) in D. T = T-{e i-1 } e i-1 vivi

34 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann34 Handling start, end and split vertices 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 and set helper(e i ) to v i vivi ejej eiei

35 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann35 Handling merge vertices HandleMergeVertex(v i ) : if helper(e i-1 ) is a merge vertex then Insert diagonal connecting v i to helper(e i-1 ) in D. Delete e i-1 from T. Search in T to find the edge e j left of v i. if helper(e j ) is a merge vertex then Insert diagonal connecting v i to helper(e j ) in D. helper(e j ) = v i vivi e i-1 ejej

36 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann36 Handling regular vertices 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 v i to helper(e i-1 ) in D delete e i-1 from T. insert e i in T and set helper(e i ) to v i. else search in T to find the edge e j 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 helper(e j ) = v i vivi e i-1 eiei

37 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann37 Handling regular vertices 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 v i to helper(e i-1 ) in D delete e i-1 from T. insert e i in T and set helper(e i ) to v i. else search in T to find the edge e j 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 helper(e j ) = v i vivi ejej

38 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann38 Theorem A simple polygon with n vertices can be partitioned into y-monotone polygons in O(n log n) time with an algorithm that uses O(n) storage.

39 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann39 Triangulation of y-monotone Polygon reflex chain: a polygonal chain is called a reflex chain, if the vertices v 2 thru v n-1 are concave. vnvn v1v1

40 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann40 Triangulation of y-monotone Polygon Idea: Process vertices in decreasing y-order; add as many diagonals as possible Invariant: Vertices in stack form a reflex chain When processing next vertex v: Case 1: v is on same side as top vertex in stack Case 2: v is on opposite side as top vertex in stack

41 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann41 Triangulation of y-monotone Polygon Case 1: v is on same side as top vertex in stack

42 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann42 Triangulation of y-monotone Polygon Case 1: v is on same side as top vertex in stack

43 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann43 Triangulation of y-monotone Polygon Case 2: v is on opposite side as top vertex in stack

44 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann44 Example 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

45 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann45 Implementation 1.S.push(u 1 ), S.push(u 2 ) 2. for j = 3,...,n-1 3. if (side(u j )  side(S.top)) 4. while (S   ) v = S.pop, diag(u j,v) 5. S.push(u j-1 ) 6. S.push(u j ) 7. else 8. while (diag(S.top, u j ) in P) 9. diag(S.top, u j ) 10. S.pop 11. S.push(last) 12. S.push(u j ) Theorem: time O(n) Proof: number of pops < number of pushes

46 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann46 Theorem Theorem: A strictly y-monotone polygon with n vertices can be triangulated in O(n) time. Theorem: A simple polygon with n vertices can be triangulated in O(n log n) time with an algorithm that uses O(n) storage. Theorem: A planar subdivision with n vertices in total can be triangulated in O(n log n) time with an algorithm that uses O(n) storage.


Download ppt "Polygon Triangulation Computational Geometry, WS 2007/08 Lecture 9 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät."

Similar presentations


Ads by Google