1 / 20

Last Time: Convex Hulls

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. From UNC.

dafydd
Download Presentation

Last Time: Convex Hulls

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  3. Line Segment Intersection • Input: A set S={s1, …, sn} of (closed) line segments in R2 • Output: All intersection points between segments in S

  4. The basics. a • Two line segments ab and cd • Write in terms of convex combinations: p(s) = (1-s) a + sb for0£ s £ 1 q(t) = (1-t) c + td for0£ t £ 1 Intersection if p(s)=q(t) • Equation system (1-s) ax + sbx = (1-t) cx + tdx (1-s) ay + sby = (1-t) cy + tdy • Solve for s and t. • When is there no solution? • When do the segments intersect? b

  5. Bounds • How many intersections can n line segments have? • 0 < k < n2 Really, from 0 to (n choose 2) • Brute force algorithm? • Try out all pairs of line segments • Takes O(n2) time, is optimal in worst case • Challenge: Develop an output-sensitive algorithm • Runtime depends on size k of the output, 0 £k£n2 • 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. 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 W(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 q(n log n), then element uniqueness could be solved faster. Contradiction.

  7. 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. Sweep Line Event Q

  9. 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. 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. 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. 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 e d cbed

  13. 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 b c a e d cbd cbed

  14. 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) b c a e d Note: “new” intersection might have been detected before. cbed cebd

  15. 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) b c a e d ecbd ecd

  16. 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. s’ p s

  17. k = O(n2) 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 n2) = O(log n) • There are O(n+k) events. Hence the total runtime is O((n+k) log n)

  18. si sj 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?)

  19. Table of good stuff Lower Bounds: • Sorting: O(n log n) • Element Uniqueness O(n log n). • 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. • q(n log n) • Exactly n log n (up to constant factors). 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. Example problem for sweep line? • Problem: Given PÍR2, |P|=n, find the distance of the closest pair in P

More Related