242-535 ADA: 16. CG Topics1 Objective o an examination of four important CG topics o just a taster of a very large research area Algorithm Design and Analysis.

Slides:



Advertisements
Similar presentations
Two Segments Intersect?
Advertisements

Polygon Triangulation
1/13/15CMPS 3130/6130: Computational Geometry1 CMPS 3130/6130: Computational Geometry Spring 2015 Convex Hulls Carola Wenk.
Brute-Force Triangulation
2/3/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Triangulations and Guarding Art Galleries II Carola Wenk.
Computing Convex Hulls CLRS 33.3
Convex Hull obstacle start end Convex Hull Convex Hull
CS16: Introduction to Data Structures & Algorithms
C o m p u t i n g C O N V E X H U L L S by Kok Lim Low 10 Nov 1998 COMP Presentation.
UNC Chapel Hill M. C. Lin Polygon Triangulation Chapter 3 of the Textbook Driving Applications –Guarding an Art Gallery –3D Morphing.
9/12/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries II Carola Wenk.
I. The Problem of Molding Does a given object have a mold from which it can be removed? object not removable mold 1 object removable Assumptions The object.
Convex Hulls in Two Dimensions Definitions Basic algorithms Gift Wrapping (algorithm of Jarvis ) Graham scan Divide and conquer Convex Hull for line intersections.
CS4413 Divide-and-Conquer
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 6 Ack : Carola Wenk nad Dr. Thomas Ottmann tutorials.
By Groysman Maxim. Let S be a set of sites in the plane. Each point in the plane is influenced by each point of S. We would like to decompose the plane.
Convex Sets & Concave Sets A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R.
1 Convex Hull in Two Dimensions Jyun-Ming Chen Refs: deBerg et al. (Chap. 1) O’Rourke (Chap. 3)
Computational Geometry
1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem.
What does that mean? To get the taste we will just look only at some sample problems... [Adapted from S.Suri]
9/5/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Plane Sweep Algorithms and Segment Intersection Carola Wenk.
Intersections. Intersection Problem 3 Intersection Detection: Given two geometric objects, do they intersect? Intersection detection (test) is frequently.
November 4, Algorithms and Data Structures Lecture XIV Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,
N Line Segments Problem Given a set of n line segments in the plane, determine whether or not any intersection exists. It is not required to output all.
Convex Hulls Computational Geometry, WS 2006/07 Lecture 2 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
UMass Lowell Computer Science Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2007 Lecture 3 Chapter 3: 2D Convex Hulls Friday,
Lecture 3: Polygon Triangulation Computational Geometry Prof. Dr. Th. Ottmann Polygon Triangulation Motivation: Guarding art galleries Art gallery theorem.
Computational Geometry Overview from Cormen, et al. Chapter 33
Point Location Computational Geometry, WS 2007/08 Lecture 5 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
Polygon Triangulation Computational Geometry, WS 2007/08 Lecture 9 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
UMass Lowell Computer Science Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2001 Lecture 2 Chapter 2: Polygon Partitioning.
Lection 1: Introduction Computational Geometry Prof.Dr.Th.Ottmann 1 History: Proof-based, algorithmic, axiomatic geometry, computational geometry today.
The Art Gallery Problem
Brute-Force Triangulation
The Art Gallery Problem
Advanced Algorithm Design and Analysis (Lecture 9) SW5 fall 2004 Simonas Šaltenis E1-215b
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
9/7/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Triangulations and Guarding Art Galleries Carola Wenk.
Triangulating a monotone polygon
Convex Hull. What is the Convex Hull? Imagine a set of points on a board with a nail hammered into each point. Now stretch a rubber band over all the.
1 Computational Geometry Instructor: yedeshi
UNC Chapel Hill M. C. Lin Line Segment Intersection Chapter 2 of the Textbook Driving Applications –Map overlap problems –3D Polyhedral Morphing.
C o m p u t i n g C O N V E X H U L L S. Presentation Outline 2D Convex Hulls –Definitions and Properties –Approaches: Brute Force Gift Wrapping QuickHull.
Fundamental Data Structures and Algorithms Klaus Sutner April 27, 2004 Computational Geometry.
Fundamental Data Structures and Algorithms Margaret Reid-Miller 27 April 2004 Computational Geometry.
Convex Hull. University of Manchester biologists used lasers to measure the minimum amount of skin required to wrap around the skeletons of modern-day.
1/29/15CMPS 3130/6130 Computational Geometry1 CMPS 3130/6130 Computational Geometry Spring 2015 Triangulations and Guarding Art Galleries Carola Wenk.
15. Computational Geometry Topics
Computational Geometry 2D Convex Hulls
A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave.
Convex Sets & Concave Sets A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R.
9/8/10CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2010 Triangulations and Guarding Art Galleries Carola Wenk.
Convex Hulls Guo Qi, Chen Zhenghai, Wang Guanhua, Shen Shiqi, Himeshi De Silva.
Polygon Triangulation
CMPS 3130/6130 Computational Geometry Spring 2017
3. Polygon Triangulation
Convex Hull.
The Art Gallery Problem
Computational Geometry Capter:1-2.1
The Art Gallery Problem
Polygon Triangulation
Convex Sets & Concave Sets
I. The Problem of Molding
Convex Hull 1/1/ :28 AM Convex Hull obstacle start end.
CHAPTER 33 Computational Geometry
CMPS 3130/6130: Computational Geometry Spring 2017
Computational Geometry
Algorithms and Data Structures Lecture XIV
Presentation transcript:

ADA: 16. CG Topics1 Objective o an examination of four important CG topics o just a taster of a very large research area Algorithm Design and Analysis (ADA) , Semester Computational Geometry Topics

ADA: 16. CG Topics2 1.Intersection of Multiple Line Segments o the sweeping algorithm 2.Finding the Convex Hull o Graham Scan, Jarvis' March, QuickHull 3.Finding the Closest Pair of Points o divide-and-conquer 4.The Art Gallery ProblemOverview

ADA: 16. CG Topics Multiple Line Segments 1.2. A Brute-Force Algorithm 1.3. The Sweeping Algorithm 1.4. Implementing Sweeping 1. Intersection of Multiple Line Segments

1.1. Multiple Line Segments Input: a set of n line segments in the plane. Output : all intersections, and for each intersection the involved segments..

1.2. A Brute-Force Algorithm Look at each pair of segments, and check if they intersect. If so, output the intersection. n(n-1)/2 comparison are needed in the worst case, so the running time is O(n 2 ) Most segments do not intersect, or if they do, only with a few other segments Need a faster algorithm that deals with such situations! But the lines are sparsly distributed in practice:

1.3. The Sweeping Algorithm Avoid testing pairs of segments that are far apart. Idea: imagine a vertical sweep line passes through the given set of line segments, from left to right. Sweep line also known as the "Bentley-Ottmann" Algorithm and the Sweep Line Algorithm also known as the "Bentley-Ottmann" Algorithm and the Sweep Line Algorithm

Non-Degeneracy Assumptions No segment is vertical. // this means that the sweep line will always hit a segment at a point. If an input segment is vertical, then it is rotated clockwise by a tiny angle.

Sweep Line Status Sweep Line Status The set of segments intersecting the sweep line. It changes as the sweep line moves, but not continuously. Updates of status happen only at event points. endpoints intersections event points A G C T

Ordering Segments A total order over the segments that intersect the current position of the sweep line: A B C D E B > C > D (A and E not in the ordering) C > D (B drops out of the ordering) At an event point, the sequence of segments changes:  Update the status.  Detect the intersections. later

Status Update (1)  A new segment L intersecting the sweep line L M K  Check if L intersects with the segment above (K) and the segment below (M). new event point  Intersection(s) are new event points. Event point is the left endpoint of a segment. N K, M, NK, L, M, N O

Status Update (2)  The two intersecting segments (L and M) change order. L M K  Check intersection with new neighbors (M with O and L with N).  Intersection(s) are new event points. Event point is an intersection. N O O, L, M, N O, M, L, N

Status Update (3)  The two neighbors (O and L) become adjacent. L M K  Check if they (O and L) intersect.  Intersection is new event point. Event point is a lower endpoint of a segment. N O, M, L, NO, L, N O

ADA: 16. CG Topics13 The algorithm manages two kinds of data: 1. The sweep line status gives the relationships among the objects intersected by the sweep line. 2. The event point queue is a sequence of event points that defines the halting positions of the sweep line Implementing Sweeping

Event Point Queue Operations Data structure: a balanced binary search tree (e.g., red-black tree). Manages the ordering of event points: by x-coordinates by y-coordinates in case of a tie in x-coordinates Supports the following operations on a segment s.  inserting an event  fetching the next event Every event point p is stored with all segments starting at p. // O(log m) m = # event points currently being managed m = # event points currently being managed

ADA: 16. CG Topics15 The sweep line status (T) requires the following operations: INSERT(T, s): insert segment s into T. DELETE(T, s): delete segment s from T. ABOVE(T, s): return the segment immediately above segment s in T. BELOW(T, s): return the segment immediately below segment s in T. Use a balanced binary search tree for T (e.g. Red-black trees): O(log n) for each operation Sweep Line Operations

ADA: 16. CG Topics16 ANY-SEGMENTS-INTERSECT(S) 1 T = Ø 2 sort the endpoints of the segments in S from left to right, breaking ties by putting left endpoints before right endpoints and breaking further ties by putting points with lower y-coordinates first 3 for (each point p in the sorted list of endpoints) { 4 if (p is the left endpoint of a segment s) { 5 INSERT(T, s) 6 if (ABOVE(T, s) exists and intersects s) or (BELOW(T, s) exists and intersects s) 7 return TRUE } 8 if (p is the right endpoint of a segment s) { 9 if (both ABOVE(T, s) and BELOW(T, s) exist) and (ABOVE(T, s) intersects BELOW(T, s)) 10 return TRUE 11 DELETE(T, s) } } 12 return FALSE Segments intersect Pseudocode

ADA: 16. CG Topics17 Execution Example edbedb the intersection of segments d and b is detected when segment c is deleted

ADA: 16. CG Topics18 If the segment set contains n segments, then ANY-SEGMENTS-INTERSECT runs in time O(n log n) o Line 1 takes O(1) time. o Line 2 takes O(n log n) time, using merge sort or heapsort. o The for loop of lines 3–11 iterates at most once per event point, and so with 2n event points, the loop iterates at most 2n times. o Each iteration takes O(log n) time, since each tree operation takes O(log n) time and each intersection test takes O(1) time (by using the intersection function from part 15). o Total cost = O(1) + O(n * (log n + 1)) = O(n log n) Running Time

ADA: 16. CG Topics Convex & Concave Sets 2.2. The Convex Hull 2.3. The Graham Scan 2.4. Jarvis’ March 2.5. QuickHull 2.6. Lower Bound of O(n log n) 2. Finding the Convex Hull

2.1. Convex and Concave Sets A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave. Convex p q R 1 p q R 2 Concave

2.2. The Convex Hull The convex hull CH(P) of a set of points P is the smallest convex region that contains all of P. Rubber band When P is finite, its convex hull is the unique convex polygon whose vertices are from P and that contains all points of P.

The Convex Hull Problem Input: a set P = { p, p, …, p } of points Output: a list of vertices of CH(P) in counterclockwise order. 1 2 n Example 8 p p p p p p p p p p CH(P) = [ p 5, p 9, p 2, p 8, p 10, p 7 ] Not all the points in P are in CH(P) Not all the points in P are in CH(P)

Edges of a Convex Hull For every edge both endpoints p, q  P. p q All other points in P lie to the same side of the line passing through p and q all points on this side of the q – p edge

Floating Arithmetic is not Exact p r q Nearly colinear points p, q, r. p to the left of qr. q to the left of rp. r to the left of qp. All three accepted as edges! The algorithm is not robust – it could fail due to small numerical error.

2.3. The Graham Scan p 0 p p p p p p p p p p p The center point has the minimum y-coordinate Labels are in the polar angle order. (What if two points have the same polar angle?) How to break a tie? sort by polar angle handling degeneracies

ADA: 16. CG Topics26 Consider each of the points in the sorted sequence. For each point, is moving from the two previously considered points to this point a "left turn" or "right turn"? " Right turn ": this means that the second-to-last point is not part of the convex hull and should be removed. o this process is continued for as long as the set of the last three points is a "right turn" " Left turn ": the algorithm moves to the next point in the sequence. A Turning Algorithm

ADA: 16. CG Topics27 Turning in Action C is a left turn compared to A – B; add C D is a right turn compared to B - C; remove C D is a left turn compared to A - B; add D X

Graham-Scan(P) let p0 be the point in P with minimum y-coordinate let  p1, p2, …, pn-1  be the remaining points in P sorted in counterclockwise order by polar angle around p0 Stack s = new Stack(); s.push(p0) s.push(p1) s.push(p2) for i = 3 to n  1 while ( pi makes a nonleft turn from the line segment determined by s.top() and s.nextToTop() ) s.pop() s.push(pi) return s The Graham Scan Algorithm the convex hull points are stored on a stack the convex hull points are stored on a stack

Stack Usage p p p p p p p p p p p p p p p S 0 1 2

p p p p p p p p pp p p p p p S 0 1 3

p p p p p p p p pp p p p p p S 0 1 4

p p p p p p p p pp p p p p p S p 5

p p p p p p p p pp p p p p p S p 6

p p p p p p p p pp p p p p p S p 6 p 7 p 8

p p p p p p p p pp p p p p p S p 6 p 7

p p p p p p p p pp p p p p p S p 6 p 9 p 10

p p p p p p p p pp p p p p p S p 6 p 9 p

Finish p p p p p p p p pp p p p p p S p 6 p 9 p

Proof of Correctness Each point popped from stack S is not a vertex of CH(P). p p p p 0 i j k p p p p 0 i j k Two cases when pj is popped: In neither case can pj become a vertex of CH(P). Proof pk is a right turn compared to pi - pj pk is a right turn compared to pi - pj pk is a 0 angle turn compared to pi - pj pk is a 0 angle turn compared to pi - pj X X

The points on stack S always form the vertices of a convex polygon in counterclockwise order (an invariant). Popping a point from S preserves the invariant. The region containing pi The invariant still holds. Proof The claim holds at S initialization when p0, p1, p2 form a triangle (which is obviously convex) Consider a point pi being pushed onto S. p 0 p j p i

Running Time The running time of Graham’s Scan is O(n log n). #operations time / operation total Push n O(1)  (n) Pop  n  2 O(1) O(n) Sorting 1 O(n log n) O(n log n) Why? Finding p 0 1  (n)  (n)

2.4. Jarvis’ March A “package/gift wrapping” technique using two "chains"

ADA: 16. CG Topics43 We choose the first vertex as the lowest point p0, and start the right chain. o The next vertex, p1, has the smallest polar angle of any point with respect to p0. o Then, p2 has the smallest polar angle with respect to p1. o The right chain goes as high as the highest point p3. Then,we return to p0 and build the left chain by finding smallest polar angles with respect to the negative x-axis. The Operation of Jarvis’ March

Running Time of Jarvis’ March Let h be the number of vertices of the convex hull. For each vertex, finding the point with the minimum Polar angle, that is, the next vertex, takes time O(n) The comparison between two polar angles can be done using the cross product. Thus O(nh) time in total.

ADA: 16. CG Topics45 Concentrate on points close to hull boundary Named for similarity to Quicksort o O(n log n) 2.5. QuickHull Set QuickHull(a, b, S) if S = 0 return {} else c = index of point with max distance from a-b A = points strictly right of (a, c) B = points strictly right of (c, b) return QuickHull(a, c, A) + {c} + QuickHull(c, b, B) a b finds one of upper or lower hull c A

ADA: 16. CG Topics46 The worst-case time to find the convex hull of n points using a decision tree model is  (n log n) Proof based on sorting: o Given an unsorted list of n numbers: (x 1,x 2,…, x n ) o Form an unsorted set of points: (x i, x i 2 ) for each x i o Convex hull of these points produces a sorted list! a parabola: so every point is on the convex hull o Finding the convex hull of n points is therefore at least as hard as sorting n points, so worst-case time is in  (n log n) 2.6. Lower Bound of O(n log n) Convex hull of red pts

ADA: 16. CG Topics47 There are a set of n points P = { p 1, …p n }. Find a pair of points p, q such that |p – q| is the minimum of all |p i – p j | Easy to do in O(n 2 ) time o for all pi ≠ pj, compute ║pi - pj║ on all the pairs and choose the minimum, which involves n(n-1)/2 comparisons We will aim for O(n log n) time 3. Finding the Closest Pair of Points

ADA: 16. CG Topics48 Divide : o Compute the median of the x-coordinates o Split the points into a left half PL and right half PR, each of size n/2 Conquer : compute the closest pairs for PL and PR Combine the results (the hard part) Divide and Conquer PLPR median line

ADA: 16. CG Topics49 dL = closestDist(PL) dR = closestDist(PR) d = min( d1, d2 ) Observe: o Need to check only pairs which cross the dividing line o Only interested in pairs within distance < d of each other It's enough to look at only the points in the 2d wide strip around the median lineCombine PLPR median line

ADA: 16. CG Topics50 Sort all points in the strip by their y-coords, forming q1…qk, k ≤ n. Let yi be the y-coord of qi dmin = d for i = 1 to k { j = i - 1 while (yi - yj < d){ if( ║ qi-qj ║ < d) dmin = ║ qi-qj ║ j = j-1 } Report dmin (and the corresponding pair) Scanning the Strip

ADA: 16. CG Topics51 Combine : O(n log n) because we sort the y-coords. But, we can: o Sort all points the y-coords at the beginning, outside of the main loop since the Divide stage preserves the y-order of points o Then this combine stage only takes O(n) We get T(n)=2T(n/2)+O(n), so T(n) is O(n log n) Running Time divide the data by half and calculate the closest pair on PL and PR combine

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

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).

Triangulation To make things easier, we decompose a polygon into pieces that are easy to guard. Draw diagonals between pairs of vertices. diagonals Triangulation: decomposition of a polygon into triangles by a maximal set of non-intersecting diagonals. Guard the art gallery by placing a camera in every triangle …

No. of Cameras Theorem: Every simple polygon has a triangulation. Any triangulation of a simple polygon with n vertices consists of n – 2 triangles.  n – 2 cameras can guard the simple polygon. Note: a camera sitting on a diagonal guards two triangles.  the no. of cameras can be reduced to roughly n/2 Note: a vertex is adjacent to many triangles so placing cameras at vertices can reduce the number even more…

3-Coloring of Vertices Idea: Select vertices, such that every triangle has at least one of those vertices. 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. Choose the smallest color set, and place cameras at all the vertices using that color   n/3  cameras.

The Dual Graph A dual graph G has a node inside every triangle and an edge between every pair of nodes whose corresponding triangles share a diagonal. The dual graph G is actually a tree (marked in red on this slide), and it is possible to build one using DFS.