Convex Hull obstacle start end Outline and Reading
Convex Hull obstacle start end
Outline and Reading Convex hull (§ 12. 5. 2) Orientation (§ 12. 5. 1 -2) Sorting by angle (§ 12. 5. 5) Graham scan (§ 12. 5. 5) Analysis (§ 12. 5. 5) 2
Convex Polygon A convex polygon is a nonintersecting polygon whose internal angles are all convex (i. e. , less than p) In a convex polygon, a segment joining two vertices of the polygon lies entirely inside the polygon convex nonconvex 3
Convex Hull The convex hull of a set of points is the smallest convex polygon containing the points Think of a rubber band snapping around the points 4
Special Cases The convex hull is a segment n n Two points All the points are collinear The convex hull is a point n n there is one point All the points are coincident 5
Applications Motion planning n Find an optimal route that avoids obstacles for a robot Geometric algorithms n Convex hull is like a two-dimensional sorting obstacle start end 6
Computing the Convex Hull The following method computes the convex hull of a set of points Phase 1: Find the lowest point (anchor point) Phase 2: Form a nonintersecting polygon by sorting the points counterclockwise around the anchor point Phase 3: While the polygon has a nonconvex vertex, remove it 7
Orientation The orientation of three points in the plane is clockwise, counterclockwise, or collinear orientation(a, b, c) n n n clockwise (CW, right turn) counterclockwise (CCW, left turn) collinear (COLL, no turn) The orientation of three points is characterized by the sign of the determinant D(a, b, c), whose absolute value is twice the area of the triangle with vertices a, b and c b c CW b CCW a c a b COLL 8
Sorting by Angle Computing angles from coordinates is complex and leads to numerical inaccuracy We can sort a set of points by angle with respect to the anchor point a using a comparator based on the orientation function n c b < c orientation(a, b, c) = CCW b = c orientation(a, b, c) = COLL b > c orientation(a, b, c) = CW CCW b a c COLL b a b CW c a 9
Removing Nonconvex Vertices Testing whether a vertex is convex can be done using the orientation function Let p, q and r be three consecutive vertices of a polygon, in counterclockwise order n n q convex orientation(p, q, r) = CCW q nonconvex orientation(p, q, r) = CW or COLL r r q q p p 10
Graham Scan The Graham scan is a systematic procedure for removing nonconvex vertices from a polygon The polygon is traversed counterclockwise and a sequence H of vertices is maintained r r p q H for each vertex r of the polygon Let q and p be the last and second last vertex of H while orientation(p, q, r) = CW or COLL remove q from H q p p vertex preceding p in H Add r to the end of H q p r q p H H 11
Analysis Computing the convex hull of a set of points takes O(n log n) time n n Finding the anchor point takes O(n) time Sorting the points counterclockwise around the anchor point takes O(n log n) time w Use the orientation comparator and any sorting algorithm that runs in O(n log n) time (e. g. , heap-sort or mergesort) n The Graham scan takes O(n) time w Each point is inserted once in sequence H w Each vertex is removed at most once from sequence H See pages 584 -585 for a Java implementation of this algorithm. 12
Incremental Convex Hull q z w e u t
Outline and Reading Point location n n Problem Data structure Incremental convex hull n n Problem Data structure Insertion algorithm Analysis 14
Point Location Given a convex polygon P, a point location query locate(q) determines whether a query point q is inside (IN), outside (OUT), or on the boundary (ON) of P An efficient data structure for point location stores the top and bottom chains of P in two binary search trees, TL and TH of logarithmic height n n An internal node stores a pair (x (v), v) where v is a vertex and x (v) is its x-coordinate An external node represents an edge or an empty halfplane TH P TL 15
Point Location (cont. ) TH To perform locate(q), we search for x(q) in TL and TH to find n n Edge e. L or vertex v. L on the lower chain of P whose horizontal span includes x(q) Edge e. H or vertex v. H on the upper chain of P whose horizontal span includes x(q) We consider four cases n n e. H P q If no such edges/vertices exist, we return OUT Else if q is on e. L (v. L) or on e. H (v. H), we return ON Else if q is above e. L (v. L) and below e. H (v. H), we return IN Else, we return OUT v. L TL 16
Incremental Convex Hull The incremental convex hull problem consists of performing a series of the following operations on a set S of points n n n locate(q): determines if query point q is inside, outside or on the convex hull of S insert(q): inserts a new point q into S hull(): returns the convex hull of S Incremental convex hull data structure n n We store the points of the convex hull and discard the other points We store the hull points in two redblack trees w TL for the lower hull w TH for the upper hull 17
Insertion of a Point In operation insert(q), we consider four cases that depend on the location of point q A IN or ON: no change B OUT and above: add q to the upper hull C OUT and below: add q to the lower hull D OUT and left or right: add q to the lower and upper hull A C D 18
Insertion of a Point (cont. ) q Algorithm to add a vertex q to the upper hull chain in Case B (boundary conditions omitted for simplicity) n n We find the edge e (vertex v) whose horizontal span includes q w left endpoint (neighbor) of e (v) z left neighbor of w While orientation(q, w, z) = CW or COLL z w We remove vertex w w w z left neighbor of w n n n e u t q u right endpoint (neighbor) of e (v) t right neighbor of u While orientation(t, u, q) = CW or COLL w We remove vertex u w u t w t right neighbor of u n w We add vertex q w z u t 19
Analysis Let n be the current size of the convex hull n n Operation locate takes O(log n) time Operation insert takes O((1 + k)log n) time, where k is the number of vertices removed Operation hull takes O(n) time The amortized running time of operation insert is O(log n) 20
current_best$ e ∞ 3 6 3 nextnode b f ∞ ∞ 9 ∞ ∞ ∞ wait candidate$ a f$ root e$ 4 d$ d ∞ 4 ∞ ∞ 3 ∞ yes b c$ IS b$ 7 a$ 7 ∞ ∞ 6 9 yes b node$ 2 mask$ a PEs parent$ Data Structure for MST Algorithm a ∞ 2 8 ∞ ∞ ∞ no b 2 ∞ 7 c 8 4 3 ∞ no 3 ∞ ∞ yes b 21
Quickhull Algorithm for ASC Reference: n [Maher, Baker, Akl, “An Associative Implementation of Classical Convex Hull Algorithms” ] h Review of Sequential Quickhull Algorithm n Suffices to find the upper convex hull of points that are on or above the line w Select point h so that the area of triangle weh is maximal. Proceed recursively with the sets of points on or above the lines and. e 22
Previous Illustration h e w 23
Example for Data Structure P 6, h p 5 p 7 p 4 p 1, w P 3, e p 2 24
Data Structure for Preceding Example right-pt$ area$ left-point$ y-coord$ name$ x-coord$ PE mask point$ hull$ job$ p 1 1 3 p 1 p 3 1 1 p 2 7 1 p 3 0 p 3 12 2 p 1 p 3 1 1 p 4 8 4 p 1 p 3 1 h p 5 11 7 p 1 p 3 1 ctr p 6 8 9 p 1 p 3 1 1 p 7 2 6 p 1 p 3 1 0 IS w e h 25
ASC Quickhull Algorithm (Upper Convex Hull) ASC-Quickhull( planar-point-set ) 1. Initialize: ctr = 1, area$ = 0, hull$ = 0 2. Find the PE with the minimal x-coord$ and let w be its point$ a) Set its hull$ value to 1 3. Find the PE with maximal x-coord$ and let e be its point$ a) Set its hull$ to 1 4. All PEs set their left-pt to w and right-pt to e. 5. If the point$ for a PE lies above the line a) b) Then set its job$ value to 1 Else set its job$ value to 0 26
ASC Quickhull Algorithm (cont) 6. Loop while parallel job$ contains a nonzero value a) b) c) The IS makes its active cell those with a maximal job$ value. Each (active) PE computes and stores the area of triangle (left-pt$, right-pt$, point$ ) in area$ Find the PE with the maximal area$ and let h be its point. w d) Set its hull$ value to 1 Each PE whose point$ is above sets its job$ value to ++ctr e) Each PE whose point$ is above sets its job$ to ++ctr f) Each PE with job$ < ctr -2 sets its job$ value to 0 27
Performance of ASC-Quickhull 5 3 1 4 2 6 0 28
Performance of ASC-Quickhull (cont) Average Case: Assume n n Roughly 1/3 of the points above each line being processed are eliminated. O(lg n) points are on the convex hull. w Shown to be true for randomly generated points Then the average running time is O(lg n) The average cost is O(n lg n) Worst Case: Running time is O(n). Cost is O(n 2) n Definition of cost is (running time) (nr. of processors) 29
MASC Quickhull Algorithm: Use IS 1 to execute the first loop of ASCQuickhull When an IS completes computing the loop in ASC-Quickhull, Idle ISs request problems from busy ISs who have inactive jobs on their job$ list. Control of the PEs for an inactive job is transferred to the idle IS. The control of these PEs is returned to original IS after the job is finished. 30
ASC Quickhull Algorithm (cont) 2 2 1 1 2 2 0 31
Analysis for MASC Quickhull Average Case: Assumptions: n n n roughly 1/3 of the points above each line being processed are eliminated. O(lg n) Instruction Streams are available. There are O(lg n) convex hull points The average running time is O(lg lg n) Essentially constant time for real world problems. Worst Case O(n) 32
MASC Quickhull for a Limited Number of ISs A manager IS is used to control the interactions of the ISs and the task workpool. The manager assigns IS 1 to execute the first loop of ASC-Quickhull When an IS completes the execution of a loop, n n n If two jobs are created, it gives one to the manager IS to place on the workpool and then executes the remaining IS If only one job is created, it executes this job next. If no new job is created, this IS requests a new job from the manager IS. 33
Additional Comments on MASC Quickhull For one million points this algorithm would require lg n = 20. n Note that increasing the ISs by only 5 (to 25) would allow 33. 5 million points to be processed. Even if (lg n) ISs are available for this algorithm, the actual number of ISs would likely to still be less than lg n. n It would be inefficient to assume that every time a new task is created, an idle IS would be available to execute it. However, this algorithm should also provide a speedup, even if only a small number k of ISs are available. n n The complexity of the running time will still be O(lg n). The actual running time could be up to k times faster than for one IS. w There will be some loss of efficiency due to IS interactions. n This is probably a more practical approach. 34
- Slides: 34