Presentation is loading. Please wait.

Presentation is loading. Please wait.

Contest Algorithms January 2016 Triangulation & the Art Gallery Problem Contest Algorithms1.

Similar presentations


Presentation on theme: "Contest Algorithms January 2016 Triangulation & the Art Gallery Problem Contest Algorithms1."— Presentation transcript:

1 Contest Algorithms January 2016 Triangulation & the Art Gallery Problem Contest Algorithms1

2 1. Simple Polygons Some definitions would allow this as a “degenerate” simple polygon  P is a simple polygon is one which does not intersect with itself

3  A partition of P into triangles by a set of noncrossing diagonals. 2. Triangulation

4 create a stack with all of the vertices in CCW order; pop the top vertex off the stack and store in p0; pop the top vertex off the stack and store in pHelper; while the stack is not empty pop the top vertex off the stack and store in pTemp; create a triangle with vertices p0, pHelper, pTemp; let pHelper = pTemp Triangulation of Convex Polygons Contest Algorithms4

5  A simple polygon has a triangulation.  An n-gon with n  4 has a diagonal.  Any triangulation of a simple n-sided polygon has:  n-3 diagonals  n-2 triangles Triangulation Theory in 2D 5

6  A diagonal of the form v i-1 v i+1 is an ear diagonal ; the triangle v i-1 v i v i+1 is an ear, and v i is the ear tip  There are at most n ears (and a convex polygon has exactly n ears) Ears v i-1 v i+1 vivi

7 Ear Clipping Triangulation Contest Algorithms7

8 create a list of the vertices (in CCW order, starting anywhere) while true for every vertex let pPrev = the previous vertex in the list let pCur = the current vertex; let pNext = the next vertex in the list if the vertex is not an interior vertex; continue; if there are any vertices in the polygon inside the triangle made by the current vertex and the two adjacent ones continue; create the triangle with the points pPrev, pCur, pNext; remove pCur from the list; if no triangles were made in the above for loop break; Pseudo-code Contest Algorithms8 see triangulate() and isEar() in Polygon.java

9  Simple “ear-clipping” methods: O(n 2 )  Cases with simple O(n) algorithms:  Convex polygons (trivial!)  Monotone polygons, monotone mountains  General case (even with holes!):  Sweep algorithm to decompose into monotone mountains  O(n log n) Triangulation Running Times 9

10  A polygon is monotone with respect to a line L, if every line orthogonal to L intersects P at most twice.  allows for sweep-based triangulation methods Monotone Polygon Contest Algorithms10

11 Example (tri4.txt) Contest Algorithms 11 5 10 15 51015 20 0 1 2 3 4 5 7 6 8 9 10 11 12 13 14 15 16 17 18 0 10 7 12 3 20 8 13 17 10 12 12 14 14 9 8 10 6 14 10 15 7 17 0 16 1 13 2 15 5 8 -2 9 5

12 > java TriangulationTests tri4.txt Triangulation: Indicies: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] try ear: 17, 0, 1 > 1. Cut off: [ (5.000, 5.000) (0.000, 0.000) (10.000, 7.000) ] Indicies: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] try ear: 17, 1, 2 try ear: 1, 2, 3 > 2. Cut off: [ (10.000, 7.000) (12.000, 3.000) (20.000, 8.000) ] Indicies: [1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] try ear: 1, 3, 4 try ear: 3, 4, 5 try ear: 4, 5, 6 > 3. Cut off: [ (13.000, 17.000) (10.000, 12.000) (12.000, 14.000) ] Indicies: [1, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] try ear: 4, 6, 7 > 4. Cut off: [ (13.000, 17.000) (12.000, 14.000) (14.000, 9.000) ] Indicies: [1, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] try ear: 4, 7, 8 try ear: 7, 8, 9 try ear: 8, 9, 10 Execution Contest Algorithms12 see TriangulationTests.java

13 try ear: 9, 10, 11 > 5. Cut off: [ (6.000, 14.000) (10.000, 15.000) (7.000, 17.000) ] Indicies: [1, 3, 4, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17] try ear: 9, 11, 12 > 6. Cut off: [ (6.000, 14.000) (7.000, 17.000) (0.000, 16.000) ] Indicies: [1, 3, 4, 7, 8, 9, 12, 13, 14, 15, 16, 17] try ear: 9, 12, 13 try ear: 12, 13, 14 > 7. Cut off: [ (0.000, 16.000) (1.000, 13.000) (2.000, 15.000) ] Indicies: [1, 3, 4, 7, 8, 9, 12, 14, 15, 16, 17] try ear: 12, 14, 15 try ear: 14, 15, 16 try ear: 15, 16, 17 > 8. Cut off: [ (5.000, 8.000) (-2.000, 9.000) (5.000, 5.000) ] Indicies: [1, 3, 4, 7, 8, 9, 12, 14, 15, 17] try ear: 15, 17, 1 > 9. Cut off: [ (5.000, 8.000) (5.000, 5.000) (10.000, 7.000) ] Indicies: [1, 3, 4, 7, 8, 9, 12, 14, 15] try ear: 15, 1, 3 > 10. Cut off: [ (5.000, 8.000) (10.000, 7.000) (20.000, 8.000) ] Indicies: [3, 4, 7, 8, 9, 12, 14, 15] try ear: 15, 3, 4 : Contest Algorithms13

14 [ (5.000, 5.000) (0.000, 0.000) (10.000, 7.000) ] [ (10.000, 7.000) (12.000, 3.000) (20.000, 8.000) ] [ (13.000, 17.000) (10.000, 12.000) (12.000, 14.000) ] [ (13.000, 17.000) (12.000, 14.000) (14.000, 9.000) ] [ (6.000, 14.000) (10.000, 15.000) (7.000, 17.000) ] [ (6.000, 14.000) (7.000, 17.000) (0.000, 16.000) ] [ (0.000, 16.000) (1.000, 13.000) (2.000, 15.000) ] [ (5.000, 8.000) (-2.000, 9.000) (5.000, 5.000) ] [ (5.000, 8.000) (5.000, 5.000) (10.000, 7.000) ] [ (5.000, 8.000) (10.000, 7.000) (20.000, 8.000) ] [ (20.000, 8.000) (13.000, 17.000) (14.000, 9.000) ] [ (6.000, 14.000) (0.000, 16.000) (2.000, 15.000) ] [ (6.000, 14.000) (2.000, 15.000) (5.000, 8.000) ] [ (5.000, 8.000) (20.000, 8.000) (14.000, 9.000) ] [ (5.000, 8.000) (14.000, 9.000) (8.000, 10.000) ] [ (5.000, 8.000) (8.000, 10.000) (6.000, 14.000) ] try ear: 3, 4, 7 > 11. Cut off : [ (20.000, 8.000) (13.000, 17.000) (14.000, 9.000) ] Indicies: [3, 7, 8, 9, 12, 14, 15] try ear: 3, 7, 8 Collinear problem near point 3 try ear: 7, 8, 9 try ear: 8, 9, 12 try ear: 9, 12, 14 > 12. Cut off : [ (6.000, 14.000) (0.000, 16.000) (2.000, 15.000) ] Indicies: [3, 7, 8, 9, 14, 15] try ear: 9, 14, 15 > 13. Cut off: [ (6.000, 14.000) (2.000, 15.000) (5.000, 8.000) ] Indicies: [3, 7, 8, 9, 15] try ear: 9, 15, 3 try ear: 15, 3, 7 > 14. Cut off : [ (5.000, 8.000) (20.000, 8.000) (14.000, 9.000) ] Indicies: [7, 8, 9, 15] try ear: 15, 7, 8 > 15. Cut off : [ (5.000, 8.000) (14.000, 9.000) (8.000, 10.000) ] Indicies: [8, 9, 15] try ear: 15, 8, 9 > 16. Cut off : [ (5.000, 8.000) (8.000, 10.000) (6.000, 14.000) ] Indicies: [9, 15] Contest Algorithms14 16 triangles for 18-sided polygon 2 points left at end; 16 used

15 Result Contest Algorithms15 5 10 15 51015 20 0 1 2 3 4 5 7 6 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 triangles and 15 diagonals for 18-sided polygon

16 3. The Art Gallery Problem Question: How many guards are needed to guard an art gallery? Guard: (camera, motion sensors, fire detectors, …) - 2  range visibility - infinite distance - cannot see through walls x y z

17 Some Gallery Examples n=3 n=4 n=5 n=6 the best guard position; 1 guard needed

18 n=6 n=9 n=3k

19  Put one guard in each triangle. Since the triangle is convex, the guard can see the whole triangle. Guard Positioning Using Triangulation

20  An assignment of one out of three colors to each vertex. Adjacent vertices must have different colors. 3-Coloring

21 Theorem; For any simple polygon with n vertices guards are sufficient to guard the whole polygon -- this means less guards might be possible There are polygons for which guards are necessary -- less is not possible, e.g: Art Gallery Theorem n3n3    n3n3   


Download ppt "Contest Algorithms January 2016 Triangulation & the Art Gallery Problem Contest Algorithms1."

Similar presentations


Ads by Google