Presentation is loading. Please wait.

Presentation is loading. Please wait.

Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,

Similar presentations


Presentation on theme: "Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,"— Presentation transcript:

1 Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness, and a good use for complicated data structures from CSE241). Some slides in this lecture come from Carola Wenk, Univ. Texas, San Antonio

2 Robert Pless, CS 546: Computational Geometry Lecture #3 Geometric Intersections Basic problem in Computational Geometry Solid modeling: Robotics: –Collision detection and avoidance Geographic information systems: –Overlay two subdivisions (e.g., road network and river network) Computer graphics: –Ray shooting/Photon Mapping to render scenes From UNC This environment consists of 25,000 tetrahedra (100,000 triangles) randomly placed within the scene. The flying object is a 747, which consists of nearly 15,000 triangles. (From Universitaat Salzburg). Photon mapped virtual environment: (w. chang, ucsd).

3 Robert Pless, CS 546: Computational Geometry Lecture #3 Line Segment Intersection Input: A set S={s 1, …, s n } of (closed) line segments in R 2 Output: All intersection points between segments in S

4 Robert Pless, CS 546: Computational Geometry Lecture #3 The basics. Two line segments ab and cd Write in terms of convex combinations: p(s) = (1-s) a + s b for 0  s  1 q(t) = (1-t) c + t d for 0  t  1 Intersection if p(s)=q(t)  Equation system (1-s) a x + s b x = (1-t) c x + t d x (1-s) a y + s b y = (1-t) c y + t d y Solve for s and t. –When is there no solution? –When do the segments intersect? a b

5 Robert Pless, CS 546: Computational Geometry Lecture #3 Bounds How many intersections can n line segments have? –0 < k < n 2 Really, from 0 to (n choose 2) Brute force algorithm? –Try out all pairs of line segments –Takes O(n 2 ) time, is optimal in worst case Challenge: Develop an output-sensitive algorithm –Runtime depends on size k of the output, 0  k  n 2 –What is best possible run time to expect? – O( n log n + k) (will talk about on next slide). –Our algorithm will have runtime: O( (n+k) log n) (with many intersections, this is worse than brute force).

6 Robert Pless, CS 546: Computational Geometry Lecture #3 Complexity Why is runtime O( n log n + k) optimal? –Element uniqueness: Given n real numbers, are all of them distinct? –The element uniqueness problem requires  (n log n) time ( in algebraic decision tree model of computation ) Reduction: element uniqueness to line segment intersection: –Take n numbers, convert into vertical line segments. There is an intersection iff there are duplicate numbers. –If we could solve line segment intersection in o(n log n) time, i.e., strictly faster than  (n log n), then element uniqueness could be solved faster. Contradiction.

7 Robert Pless, CS 546: Computational Geometry Lecture #3 Design of Plane Sweeps Plane sweep algorithms (also called sweep line algorithms) are a special kind of incremental algorithms Their correctness follows inductively by maintaining the cleanliness property –Algorithm is “clean” if the problem is “solved” to the left of the sweep line. Common runtimes in the plane are O(n log n): –n events are processed –Update of sweep line status takes O(log n) –Update of event queue: O(log n) per event

8 Robert Pless, CS 546: Computational Geometry Lecture #3 Event Q Sweep Line

9 Robert Pless, CS 546: Computational Geometry Lecture #3 Plane sweep algorithm Cleanliness property: –All intersections to the left of sweep line l have been reported Sweep line status: –Store segments that intersect the sweep line l, ordered by y-coordinate. Events: –When sweep line status changes combinatorially Left segment endpoints (known at beginning) Right segment endpoints (known at beginning) Intersection points (computed on the fly)

10 Robert Pless, CS 546: Computational Geometry Lecture #3 General position Assume that “nasty” special cases don’t happen: –No line segment is vertical –Two segments intersect in at most one point –No three segments intersect in a common point –(problems with this?)

11 Robert Pless, CS 546: Computational Geometry Lecture #3 Event Queue Need to keep events sorted: –Lexicographic order (first by x-coordinate, and if two events have same x-coordinate then by y-coordinate) Need to be able to remove next point, and insert new points in O(log n) time Use a priority queue (heap)

12 Robert Pless, CS 546: Computational Geometry Lecture #3 Sweep Line Status Store segments that intersect the sweep line l, ordered along the intersection with l. Need to insert, delete, and find adjacent neighbor in O(log n) time Use balanced binary search tree, storing the order in which segments intersect l in leaves b c d e cbedcbed

13 Robert Pless, CS 546: Computational Geometry Lecture #3 Event Handling Left segment endpoint –Add segment to sweep line status –Test adjacent segments on sweep line l for intersection with new segment (see Lemma) –Add new intersection points to event queue a b c d e cbdcbd cbedcbed

14 Robert Pless, CS 546: Computational Geometry Lecture #3 Event Handling 2. Intersection point –Report new intersection point –Two segments change order along l ? Test new adjacent segments for new intersection points (to insert into event queue) a b c d e cebdcebd cbedcbed Note: “new” intersection might have been detected before.

15 Robert Pless, CS 546: Computational Geometry Lecture #3 Event Handling 3. Right segment endpoint –Delete segment from sweep line status –Two segments become adjacent. Check for intersection points (to insert in event queue) a b c d e ecbdecbd ecdecd

16 Robert Pless, CS 546: Computational Geometry Lecture #3 Correctness proof. We only report intersections that actually occur. Do we report all intersections? We only check for intersections between segments that are neighbors in the sweep line data structure. Is that enough? Intersection Lemma Lemma: Let s, s’ be two non-vertical segments whose interiors intersect in a single point p. Assume there is no third segment passing through p. Then there is an event point to the left of p where s and s’ become adjacent (and hence are tested for intersection). Proof: Consider placement of sweep line infinitesimally left of p. s and s’ are adjacent along sweep line. Hence there must have been a previous event point where s and s’ become adjacent. p s s’

17 Robert Pless, CS 546: Computational Geometry Lecture #3 Runtime Sweep line status updates: O(log n) Event queue operations: O(log n), as the total number of stored events is  2n + k, and each operation takes time O(log(2n+k)) = O(log n 2 ) = O(log n) There are O(n+k) events. Hence the total runtime is O((n+k) log n) k = O(n 2 )

18 Robert Pless, CS 546: Computational Geometry Lecture #3 Backing out of general position. Suppose a segment is vertical. How can you fix the algorithm? –Function specialVerticalEvent: Suppose 3 segments intersect in a point Two segments overlap (intersect in more than one point?) sisi sjsj

19 Robert Pless, CS 546: Computational Geometry Lecture #3 Table of good stuff Running time definitions: O(n log n) –At most n log n. –It is correct to say that binary search is O(n log n). (it is also correct to say that it is O(log n). o(n log n) –Stricty better than n log n.  (n log n) –Exactly n log n (up to constant factors). Lower Bounds: Sorting: O(n log n) Element Uniqueness O(n log n). Data Structures Heap: Extract min: O(1) Insert-element O(log n) Delete element O(log n) Balanced Binary Tree: Insert: O(log n) Delete: O(log n) Find neighbors: O(log n) Lexicographic order (like alphabetical order, sort by first element, then by second element, etc.).

20 Robert Pless, CS 546: Computational Geometry Lecture #3 Example problem for sweep line? Problem: Given P  R 2, |P|=n, find the distance of the closest pair in P


Download ppt "Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,"

Similar presentations


Ads by Google