1 / 11

n Line Segments

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 the intersections. 2. Running time  ( n ). A Brute-Force Algorithm.

krossman
Télécharger la présentation

n Line Segments

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. n Line Segments ProblemGiven a set of nline segments in the plane,determine whether or not any intersection exists. It is not required to output all the intersections.

  2. 2 Running time (n ). A Brute-Force Algorithm Simply take each pair of segments, and check if they intersect. If so, output yes to the original problem; otherwise, output no. Nevertheless, sparsedistribution in practice: Most segments do not intersect, or if they do, only with a few other segments. Need an faster algorithm for testing in such situations!

  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

  4. Assumptions on Non-degeneracy 1. No segment is vertical. // the sweep line always hits a segment at // a point. If ≥ 1 vertical segment, rotate all segments by a small angle and then test for intersection. 2. No three segments are concurrent. Exercise 33.2-8 on how to deal with the violating case. Dealing with degeneracies are often the most laborious part of implementing geometric algorithms and proving their correctness.

  5. Ordering Segments Atotal orderover the segments that intersect the current position of the sweep line: b b > c > d (a and e are out of the ordering) a e c d Such a total order T is called thesweep-line status.

  6. Sweep-line Status Describes the relationships among the segments intersected by the sweep line. Supports the following operations on a segment s. Insert(T, s) Delete(T, s) Above(T, s)// segment immediately above s Below(T, s)// segment immediately below s Red-black tree implementation (key comparisons replaced by cross-product comparisons). O(lg n)for each operation.

  7. Sweeping around an Intersection The order of the two intersecting segments gets reversed. b a e c f d beforeafter d < f < c < b d < c < f < b

  8. Event-point Schedule Where will the sweep line make intermediate stops? A sequence of x-coordinates, in increasing order. The sweeping algorithm does something only when it reaches an endpoint. Sort the segment endpoints by increasing x-coordinate and proceed from left to right.

  9. An Example e d a c f b d a c b e d c b a a b a c b d c b e d b Sweep-line status: Intersect!

  10. Above(T, s) p s Below(T, s) Above(T, s) s p Below(T, s) The Sweeping Algorithm Any-Segments-Intersect(S) // a set S of line segments T = { } // total order of segments intersecting the sweep line sort the endpoints of the segments from left to right for each point p in the sorted list do ifp is the left endpoint of a segment s then Insert(T, s) if (Above(T, s) exists and intersectss) or (Below(T, s) exists and intersects s) then returntrue ifp is the right endpoint of a segment s then if both Above(T, s) and Below(T, s) exist and they intersect then returntrue Delete (T, s) return false

  11. Sorting of line segments takesO(n lg n) time. There are 2n event points, each costs O(lg n) on updating the sweep-line status. Running Time Total timeO(n lg n).

More Related