Session topics • The plane sweep paradigm • Visibility of a point Computational Geometry � Problem description and motivation � Solution with a rotating sweepline • Maxima of a point set Exercise session #3 • Homework number 2 1 2 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 The plane sweep paradigm Example: line segment intersection • Events • Sweep the plane with a line , maintain the � Endpoints of segments or detected intersection points. status of the line, update it at scheduled event � DAST: a balanced binary search tree ordered according to points , and maintain the sweep invariant . y coordinate (x coordinate breaks ties) • Details are problem-dependent, but general • Status � Segments intersection by horizontal line at current y approach is similar to all sweep algorithms. coordinate. • Required data structures: � DAST: a balanced binary search tree according to segment order on horizontal line. � The event structure • Invariant � The status structure � All intersection points above line were reported. � The invariant structure (partial problem solution) � DAST: list of reported intersection points. 3 4 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Visibility of a point Uses of point visibility • Guarding: a guard can watch all visible visible vertices from this point. � How many guards needed for guarding all vertices? • Path planning: all visible vertices can be p reached by a straight line from the points, others need polyline paths. weakly visible not visible 5 6 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 1
Computing the visible vertices Rotational sweepline • Events: � Vertices of obstacles sorted CCW around point. � DAST: sorted list or array. • Status: � Edges of obstacles intersecting ρ . � DAST: balanced binary search tree ordered ρ according to intersection with ρ . • Invariant: � All vertices with angle between horizontal segment and ρ have been determined for visibility. � DAST: lists of visible and invisible vertices. 7 8 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Cases where ρ contains multiple vertices Algorithm outline • Input : a set S of polygonal obstacles and a point p that does not lie on the interior of any obstacle. p w i -1 p • Output : set of all vertices visible from p . w i -1 w i w i 1. Sort obstacle vertices in CCW according to angle with positive x direction. In case of ties, sort by increasing distance to p . Let w 1 ,…, w n be sorted list of events. Initialize ρ at positive x direction. 2. Find obstacle edges intersected by ρ and inset them in status tree T 3. ordered by intersection distance from p . 4. Initialize output W to {}. p p w i -1 w i -1 5. For i=1 to n do w i w i If Visible ( w i ) then add w i to W 1. 2. Insert into T obstacle edges incident to w i that are left of line from p to w i 3. Delete from T obstacle edges incident to w i that are right of line from p to w i 6. Return W 9 10 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Checking for visibility Complexity analysis Subroutine Visible ( w i ) • Data structures are linear in number of If [ pw i ] intersects the interior of the obstacle of which w i is a vertex, 1. obstacle vertices n . return false • Initial angular sorting takes O ( n log n ) time. 2. Else if i =1 or w i -1 is not on segment [ pw i ] � Search in T for edge e in leftmost leaf. • Number of events: n. � If e exists and [ pw i ] intersects e then return false � Else return true • Searching T for intersection: O (log n ) time. 3. Else if w i -1 is not visible return false • Status update operations take O (log n ) time 4. Else � each. Search in T for edge e that intersects [ w i -1 w i ] � If e exists then return false • Overall: O ( n ) space and O ( n log n ) time. � Else return true 11 12 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 2
Variations of visibility problems Maxima of a point set • Definition : point p dominates point q (denoted Visibility region in simple Edge visibility p >> q or q << p ) if for i =1,…, d we have p i ≥ q i polygon (the relation << is called dominance). • Definition : A point p is S is called a maximal element (or maximum ) if there does not exist q in S such that q >> p . • Problem : find all the maxima of a point set under the dominance condition. 13 14 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Relation to convex hulls Lower bound on complexity x 2 • Reduction from sorting to maxima finding. (-+) • Sorting input: x 1 ,…, x n (++) • Linear time reduction: S = { p i =( x i , y i )| x i + y i =const} • From construction: x i < x j <==> y i > y j x 1 • All the points are maxima! • To determine that p i is maximal, any algorithm must conclude that there is no j ≠ i s.t. x i < x j and y i < y j ==> • For all j ≠ i either x i > x j or y i > y j , that is x i > x j or x j > x i • For each pair { x i , x j } relative ordering of elements (--) (+-) known ==> solution to sorting problem. 15 16 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Computing maxima with sweepline Generalization to 3D (sweep plane) • All points below plane are dominated in the x 3 • Events: coordinate. � Intersection of horizontal line with input point. � DAST: queue of points, sorted by decreasing y. • Status structure: projection to the x 1 - x 2 plane of • Status: points which are maxima above current plane position. � Right-most point passed so far in sweep. � DAST: x coordinate of rightmost point. • The idea: project current event point p into x 1 - • Invariant: x 2 plane and check if dominated by points in � All maxima points above line discovered. status. � DAST: list of maxima points. � If dominated, then continue, else update status by removing points dominated by p , and adding p . • Complexity: dominated by sorting: O ( n log n ) 17 18 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 3
Query and update of status structure Complexity of space-sweep x 2 • Status maintained as a balanced search tree on successor x2 ( p ) the x 1 coordinate. p • Exactly n events to handle. • Each event has a O (log n ) query time, and possible update operations on structure. successor x1 ( p ) • A maximum of n deletions from structure, each costing O (log n ) time. • Overall complexity: O ( n ) space and O ( n log n ) x 1 time. 19 20 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 Remarks • The space sweep appraoch fails for dimensions higher than 3. • With a clever divide & conquer algorithm, the problem is solved for dimension d ≥ 2 in O ( n (log n ) d -2 + n log n ) time [Preparat & Shamos, page 155-159] 21 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 4
Recommend
More recommend