Presentation is loading. Please wait.

Presentation is loading. Please wait.

POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009.

Similar presentations


Presentation on theme: "POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009."— Presentation transcript:

1 POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

2 CONTENTS Guarding and triangulations Guarding and triangulations Can we do better? Can we do better? 3-Coloring 3-Coloring The art galery theorem The art galery theorem Partitioning a polygon into monotone pieces Partitioning a polygon into monotone pieces Triangulating a Monotone polygon Triangulating a Monotone polygon

3 The Art Gallery Problem camera How many cameras are needed to guard a gallery and How should they be placed?

4 Transform to a Geometric Problem Floor plan may be sufficient and can be approximated as a simple polygon. Floor plan may be sufficient and can be approximated as a simple polygon. A simple polygon is a region enclosed by single closed polygonal chain that doesn’t self-intersect A simple polygon is a region enclosed by single closed polygonal chain that doesn’t self-intersect A camera’s position corresponds to a point in the polygon A camera’s position corresponds to a point in the polygon A camera sees those points in the polygon to which it can be connected with an open segment that lies in the interior of the polygon A camera sees those points in the polygon to which it can be connected with an open segment that lies in the interior of the polygon assuming we have omni-cam that sees all directionsassuming we have omni-cam that sees all directions

5 5 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

6 Simple Polygon Model Model the art gallery as a region bounded by some simple polygon (no self-crossing). Regions with holes are not allowed. convex polygon one camera an arbitrary n-gon (n vertices) Bad news: finding the minimum number of cameras for a given polygon is NP-hard (exponential time).

7 Triangulation Let P a simple polygon with n vertices Let P a simple polygon with n vertices We first decompose P into pieces that are easy to guard, namely triangles. We first decompose P into pieces that are easy to guard, namely triangles. DEFİNİTİON:A decomposition of a polygon into triangles by a maximal set of non- intersecting diagonals is called a triangulation of the polygon. DEFİNİTİON:A decomposition of a polygon into triangles by a maximal set of non- intersecting diagonals is called a triangulation of the polygon. Triangulations are usually NOT unique Triangulations are usually NOT unique Many applications: visibility, robotics, mesh generation, point location etc. Many applications: visibility, robotics, mesh generation, point location etc.

8 Triangulation To make things easier, we decompose a polygon into pieces that are easy to guard. Draw diagonals between pair of vertices. an open line segment that connects two vertices and lie in the interior of the polygon. Guard the polygon by placing a camera in every triangle …

9 9 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? THE QUESTION…

10 Theorem 1 Every simple polygon has a triangulation. Any triangulation of a simple polygon with n vertices consists of exactly n – 2 triangles. ProofBy induction. Trivial for n = 3. Assume true for all m < n. Existence Let v be the leftmost vertex and u and w its two neighbors.  uw in the interior of P  it is a diagonal. u v w P v w u v  Otherwise, the triangle determined by u, v, w contains at least one vertex. Let v be the one closest to v. Then vv is a diagonal. The diagonal splits the polygon into two (which by induction can be triangulated).

11 Proof Any diagonal splits P into two simple polygons with k and m vertices, respectively. # triangles = n – 2 By induction these two subpolygons can be triangulated. They are decomposed into k – 2 and m – 2 triangles, resp. Vertices defining the diagonal occur in each subpolygon once. Other vertices of P each occurs in exactly on one subpolygon. Thus k + m = n + 2. By induction, the triangulation of P has (k – 2) + (m – 2) = n – 2 triangles.

12 A camera on a diagonal guards two triangles.  # cameras can be reduced to roughly n/2. A vertex is adjacent to many triangles. So placing cameras at vertices can do even better … Theorem1 shows that any simple polygon with n vertices can be guarded with n-2 cameras. But placing a camera inside every triangle seems OVERKILL.

13 3-Coloring Idea: Select a set of vertices, such that any triangle has at least one selected vertex. Assign each vertex a color: pink, green, or yellow. Any two vertices connected by an edge or a diagonal must be assigned different colors. Thus the vertices of every triangle will be in three different colors. If 3-coloring exists, place cameras at all vertices of the same color. Choose the smallest color class to place the cameras.   n/3  cameras.

14 A 3-Coloring Algorithm A 3-coloring can be found through a graph traversal (such as DFS). During DFS, maintain the invariant: All polygon vertices of encountered triangles have been colored such that no adjacent two have the same color. Start DFS at any node of G. Color the three vertices of the corresponding triangle. v u Suppose node v is visited from u.   Their triangles T(v) and T(u) are adjacent. Only one vertex of T(v) is not colored.  Its color is uniquely determined. Since G is a tree, the other nodes adjacent to v have not been visited yet. Otherwise there exists a cycle (which contradicts that G is a tree.) Apply the color to v.

15 15 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. Can we do better?

16 THE WORST CASE SCENARIO… THE WORST CASE SCENARIO…

17 A Worst Case A Worst Case A triangulated polygon can always be 3-colored.  Any simple polygon can be guarded with  n/3  cameras. a  n/3  prongs There exists no position at which a camera can oversee two prongs.  n/3  cameras are needed. The 3-coloring approach is optimal in the worst case.

18 Solution to the Art Gallery Problem 1. Triangulate a simple polygon with a fast algorithm. DCEL representation for the simple polygon so we can visit a neighbor from a triangle in constant time. 2. Generate a 3-coloring by DFS (as presented earlier). 3. Take the smallest color class to place the cameras.

19 THEOREM Let P be a simple polygon with n vertices.A set of [n/3] camera positions in P such that any point inside P is visible from at least one of the cameras can be computed in O(n logn) time. Let P be a simple polygon with n vertices.A set of [n/3] camera positions in P such that any point inside P is visible from at least one of the cameras can be computed in O(n logn) time.

20 PARTITIONING A POLYGON INTO MONOTONE PİECES We have just seen that a triangulation of P always exists.the proof of that theorem is constructive and leads to a recursive triangulation algorithm: We have just seen that a triangulation of P always exists.the proof of that theorem is constructive and leads to a recursive triangulation algorithm: Find a diagonal and triuanglate the two resulting subpolygons recursively. Find a diagonal and triuanglate the two resulting subpolygons recursively.

21 …  The triangulation algorithm will take quadratic time in the worst case. …  The triangulation algorithm will take quadratic time in the worst case. Can we do better? Can we do better?

22 Convex polygon Pick one vertex of the Pick one vertex of the Polygon and draw diagonals From this vertex to all other vertices except its neighbors. This takes only linear time.

23 For a non-convex polygon unfortunately,it is as difficult to partition a polygon into convex pieces as it is to trianglate it.Therefore we shall decompose P into so-called monotone pieces. For a non-convex polygon unfortunately,it is as difficult to partition a polygon into convex pieces as it is to trianglate it.Therefore we shall decompose P into so-called monotone pieces.

24 Monotone polygon A polygon P in the plane is called monotone with respect to a straight line L, if every line orthogonal to L intersects P at most twice. A polygon P in the plane is called monotone with respect to a straight line L, if every line orthogonal to L intersects P at most twice.polygon

25 Line sweep(top down) Line sweep(top down) Vertices where the direction changes downward<> are called turn vertices. Vertices where the direction changes downward<> are called turn vertices. To have y-monotone pieces,we need to get rid of turn vertices: To have y-monotone pieces,we need to get rid of turn vertices: When we encounter a turn vertex,it might be necessary to introduce a diagonal and split the polygon into pieces When we encounter a turn vertex,it might be necessary to introduce a diagonal and split the polygon into pieces We will not add diagonals at all turn vertices We will not add diagonals at all turn vertices

26 Types of Turn Vertices Start Vertex - its two neighbors lie below it and the interior angle < 180° Start Vertex - its two neighbors lie below it and the interior angle < 180° End Vertex - its two neighbors lie above it and the interior angle < 180° End Vertex - its two neighbors lie above it and the interior angle < 180° Split Vertex - its two neighbors lie below it and the interior angle > 180° Split Vertex - its two neighbors lie below it and the interior angle > 180° Merge Vertex - its two neighbors lie above it and the interior angle > 180° Merge Vertex - its two neighbors lie above it and the interior angle > 180° If we want to define the different types of turn vertices carefully,we should pay special attention to vertices with equal y-coordinate.We do this by defining the notions of “below” and “above” as follows ; a point p is below another point q if

27 VERTEX ONTOLOGY

28 The split and merge vertices are sources of local non-monotonicity.The following stronger stament is true. The split and merge vertices are sources of local non-monotonicity.The following stronger stament is true. LEMMA:A polygon is y-monotone if it has no split vertices or merge vertices. LEMMA:A polygon is y-monotone if it has no split vertices or merge vertices.

29 Adding diagonals * The partition p into y- monotone pieces, get rid of split and merge vertices * The partition p into y- monotone pieces, get rid of split and merge vertices 1. Add a diagonal going upward each split vertex. 2. Add a diagonal going downward from each merge vertex. * Where do the edges go? * Where do the edges go?

30 Helpers Let helper helper( e j ) be the lowest vertex above the sweep-line Let helper helper( e j ) be the lowest vertex above the sweep-line Such that the horizontal segment connecting the vertex to e j lies inside P Such that the horizontal segment connecting the vertex to e j lies inside P

31 Removing Split Vertices For a split vertex v i,let be the edge immediately to the left of it. For a split vertex v i,let be the edge immediately to the left of it. Add a diagonal from v i to helper e j Add a diagonal from v i to helper e j

32 Removing merge vertex For a merge vertex v i let e j be edge immediately to the left of it For a merge vertex v i let e j be edge immediately to the left of it v i becomes helper( e j ) ones we reach it v i becomes helper( e j ) ones we reach it Whenever the helper( e j ) is replaced by some vertex v m,add a diagonal from v m to v i Whenever the helper( e j ) is replaced by some vertex v m,add a diagonal from v m to v i If v i is never replaced as helper( e j ), we can connect it to the lower endpoint of e j.. If v i is never replaced as helper( e j ), we can connect it to the lower endpoint of e j..

33 Removing Split/Merge Vertices v 1 … v n : a counter-clock enumeration of vertices of P v 1 … v n : a counter-clock enumeration of vertices of P e 1 … e n : a set of edges of P, where e i = segment (v i, v i+1 ) e 1 … e n : a set of edges of P, where e i = segment (v i, v i+1 ) Events are stored in event queue, ordered by y-coord. Events are stored in event queue, ordered by y-coord. If a split vertex, connect it to the lowest vertex (helper of its left edge) between the edges to its left and right If a split vertex, connect it to the lowest vertex (helper of its left edge) between the edges to its left and right If a merge vertex, connect it to the highest vertex between the edges to its left and right If a merge vertex, connect it to the highest vertex between the edges to its left and right Store the edges (and their helpers) of P in the leaves of dynamic binary search tree T, left-to-right order reflects in order of leaves. Helpers may be replaced. Store only edges that have P to their right (or the left edges). Store the edges (and their helpers) of P in the leaves of dynamic binary search tree T, left-to-right order reflects in order of leaves. Helpers may be replaced. Store only edges that have P to their right (or the left edges).

34 THE ALGORITHM…

35 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 1. Construct a priority queue Q on the vertices of P, using their y- coordinates as priority. If two points have the same y- coordinates, the one with smaller x has higher priority 2. Initialize an empty binary search tree T 3. while Q is not empty 4. do Remove v i with the highest priority from Q 5. Call the appropriate procedure to handle the vertex, depending on its type depending on its type

36 HandleStartVertex(V i ) 1. Insert e i in T and set helper(e i ) to v i

37

38 HandleEndVertex(V i ) 1. if helper(e i-1 ) is a merge vertex 2. then Insert diagonal connecting v i to helper(e i-1 ) in D 3. Delete e i-1 from T

39

40 HandleSplitVertex(V i ) 1. Search in T to find the edge e j directly left of v i 2. Insert diagonal connecting v i to helper(e j ) in D 3. helper(e j )  v i 4. Insert e i in T and set helper(e i ) to v i

41

42 HandleMergeVertex(V i ) 1. if helper(e i-1 ) is a merge vertex 2. then Insert diagonal connecting v i to helper(e i-1 ) in D 3. Delete e i-1 from T 4. Search in T to find the edge e j e j directly left of v i 5. if helper(e j ) is a merge vertex 6. then Insert diagonal connecting v i to helper(e j ) in D 7. helper(e j )  v i

43

44 HandleRegularVertex(V i ) 1. if the interior of P lies to the right of v i 2. then if helper(e i-1 ) is a merge vertex 3. then Insert diag. connect v i to helper(e i-1 ) in D 4. Delete e i-1 from T 5. Insert e i in T and set helper(e i ) to v i 6. else Search in T to find the edge e j directly left of v i 5. if helper(e j ) is a merge vertex 6. then Insert diag. connect v i to helper(e j ) in D 7. helper(e j )  v i

45

46 Partitioning Algorithm Analysis Construct priority queue: O(n) Construct priority queue: O(n) Initialize T: O(1) Initialize T: O(1) Handle an event: O(log n) Handle an event: O(log n) one operation on Q: O(logn)one operation on Q: O(logn) at most 1 query, 1 insertion & 1 deletion on T : O(logn)at most 1 query, 1 insertion & 1 deletion on T : O(logn) insert at most 2 diagonals into D : O(1)insert at most 2 diagonals into D : O(1) Total run time: O(n log n) Total run time: O(n log n) Storage: O(n) Storage: O(n)

47 An attempt was made to triangulate the following polygon, this time with respect to the horizontal, can you guess why the triangulation wasn't successful? Monotonic triangulation that failed because the polygon is not monotonic Monotonic triangulation that failed because the polygon is not monotonic

48 After a slight modification to the polygon (it doesn't look like a donkey anymore), the polygon now looks like this and can be triangulated using the concept. A successful monotonic triangulation of the modified polygon

49 LEMMA Algorithm MAKE MONOTONE adds set of non-intersecting diagonals that partitions P into monotone subpolygons. Algorithm MAKE MONOTONE adds set of non-intersecting diagonals that partitions P into monotone subpolygons.

50 Proof: We shall prove for the segment added in HANDLE-SPLİT-VERTEX ; the proof for the segments added in HANDLE- END-VERTEX,HANDLE-REGULAR- VERTEX,and HANDLE-MERGE-VERTEX is similar. We shall prove for the segment added in HANDLE-SPLİT-VERTEX ; the proof for the segments added in HANDLE- END-VERTEX,HANDLE-REGULAR- VERTEX,and HANDLE-MERGE-VERTEX is similar. We assume that no two vertices have the same y-coordinate. We assume that no two vertices have the same y-coordinate.

51 Consider a segment v m v i that is added by HANDLE-SPLİT-VERTEX when v i is reached. Consider a segment v m v i that is added by HANDLE-SPLİT-VERTEX when v i is reached. Let e j be the edge to the left of v i and let Let e j be the edge to the left of v i and let Be the edge to right of v i.Thus helper( e j )= v m Be the edge to right of v i.Thus helper( e j )= v m When we reach v i. When we reach v i. We first argue that v m v i does not intersect an edge of P. We first argue that v m v i does not intersect an edge of P. To see this, consider the quadrilateral To see this, consider the quadrilateral Q bounded by the horizantel lines through v m and v i, and by e j and e k.There are no vertices of P inside Q, otherwise v m would not be the helper of e j. Q bounded by the horizantel lines through v m and v i, and by e j and e k.There are no vertices of P inside Q, otherwise v m would not be the helper of e j.

52 It is supposed that there would be an edge of P intersecting v m v i.Since the edge cannot have an endpoint inside Q and polygon edges do not intersect each other, it would have to intersect the horizontal segment connecting v m to e j or the horizontel segment connecting v i to e j.Both are impossible, since for both v m and v i, the edge e j lies immediately to the left.Hence, no edge of P can intersect v m v i. It is supposed that there would be an edge of P intersecting v m v i.Since the edge cannot have an endpoint inside Q and polygon edges do not intersect each other, it would have to intersect the horizontal segment connecting v m to e j or the horizontel segment connecting v i to e j.Both are impossible, since for both v m and v i, the edge e j lies immediately to the left.Hence, no edge of P can intersect v m v i.

53 Since there are no vertices of P inside Q, and any previously added diagonal must have both of its endpoints above v i Since there are no vertices of P inside Q, and any previously added diagonal must have both of its endpoints above v i it can can not intersect v m v i. it can can not intersect v m v i.

54 Triangulating a Monotone Polygon The main idea behind the algorithm is quite simple. First the vertices are sorted with respect to the line of monotonicity, which in the first case is the y-axis (which involves sorting the vertices by their y-coordinate), and in the second case it is the x-axis. Sorting becomes more complex when the line of monotonicity is neither the x nor the y-axis, yet it is not impossible. However, finding the line of monotonicity can be quite difficult to implement. This issue requires more effort and it lies beyond the scope of this report. After sorting the vertices from top to bottom, the triangles are cut off from the top. The main idea behind the algorithm is quite simple. First the vertices are sorted with respect to the line of monotonicity, which in the first case is the y-axis (which involves sorting the vertices by their y-coordinate), and in the second case it is the x-axis. Sorting becomes more complex when the line of monotonicity is neither the x nor the y-axis, yet it is not impossible. However, finding the line of monotonicity can be quite difficult to implement. This issue requires more effort and it lies beyond the scope of this report. After sorting the vertices from top to bottom, the triangles are cut off from the top.

55

56 Triangulation Algorithm Analysis A strictly y-montone polygon with n vertices can be triangulated in linear time A strictly y-montone polygon with n vertices can be triangulated in linear time A simple polygon with n vertices can be triangulated in O(n log n) time with an algorithm that uses O(n) storage A simple polygon with n vertices can be triangulated in O(n log n) time with an algorithm that uses O(n) storage A planar subdivision with n vertices can be triangulated in O(n log n) time with an algorithm that uses O(n) storage A planar subdivision with n vertices can be triangulated in O(n log n) time with an algorithm that uses O(n) storage

57 Triangulation History Triangulation History 1. A really naive algorithm is O(n*4): check all 1. A really naive algorithm is O(n*4): check all n*2 choices for a diagonal, each in O(n) time. Repeat this n ¡ 1 times. 2. A better naive algorithm is O(n*2); find an 2. A better naive algorithm is O(n*2); find an ear in O(n) time; then recurse. 3. First non-trivial algorithm: O(n log n) 3. First non-trivial algorithm: O(n log n)[GJPT-78] 4. A long series of papers and algorithms in 4. A long series of papers and algorithms in 80s until Chazelle produced an optimal O(n) algorithm in 1991. 5. Linear time algorithm insanely 5. Linear time algorithm insanely complicated; there are randomized, expected linear time that are more accessible. 6. We content ourselves with O(n log n) 6. We content ourselves with O(n log n)

58 MORE… Computational Geometry-algorithms and applications Computational Geometry-algorithms and applications http://www.me.cmu.edu/faculty1/shi mada/cg97/bader/index.html http://www.me.cmu.edu/faculty1/shi mada/cg97/bader/index.html http://www.me.cmu.edu/faculty1/shi mada/cg97/bader/index.html http://www.me.cmu.edu/faculty1/shi mada/cg97/bader/index.html http://cgm.cs.mcgill.ca/~godfried/te aching/cg- projects/97/Thierry/thierry507webprj /artgallery.html http://cgm.cs.mcgill.ca/~godfried/te aching/cg- projects/97/Thierry/thierry507webprj /artgallery.html

59 DANKE SCHÖN… TEŞEKKÜRLER… TEŞEKKÜRLER…


Download ppt "POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009."

Similar presentations


Ads by Google