CS252  Computational Geometry

    Segment Intersection

Wei Qian

A. Introduction.

         In this project,  I try to solve the problem defined as: given a set S of n closed segments in the plane, report  all intersection points among the segment in S. This doesn't seem like a challenging problem: we can take each pair of segments, compute whether they intersect, if so, report their intersection point. This brute-force algorithm clear requires O(n2) time. This is not a practical algorithm in real life. Here I use plane sweep algorithm in stead, in which, there is an imagery line swept across the plane. The status of the sweep line is the set of segments intersecting it. The status changes while the sweep line moves to the right, but not continuously. Only at particular points is an update of the status required. These points are called event points of the plane sweep algorithm. In this algorithm, the event points are the endpoints of the segments and the intersection points.

B. Algorithm.

Here is the detail of the sweep line algorithm for segment intersection.

Input. A set of line segments in the plane.
Output. The set of intersection points among the segments in S.

  1. Initialize an empty event queue Q. Next, insert the segment endpoints into Q; each endpoint stores the segments begin from and/or end at itself.
  2. Initialize an empty status structure T.
  3. While Q is not empty
  4. do Determine the next event point p in Q and delete it.
  1. Let L(p) be the set of segments whose left endpoint is p, and R(p) the segments whose right endpoint is p. For vertical segment, the upper endpoint is defined as the left one.
  2. Search in T for the set C(p) of all segments that contain p in their interior.
  3. if L(p)UR(p)UC(p) contains more than one segments
  4.     then Report p an an intersection point.
  5. Delete the segments in R(p)UC(p) from T.
  6. Insert the segments in L(p)UC(p) into T. The order of the segments in  T should correspond the the order in which they are intersected by a sweep line just right to p. If there is a vertical segment, it comes last among all segments containing p.
  7. if L(p)UC(p) = 0
  8.      then Let su and sl be the upper and lower neighbors of p in T.
  9.               FINDNEWEVNET(su, sl , p).
  10.      else Let s' be the uppermost segment of L(p)UC(p) in T.
  11.               Let su be the upper neighbor of s' in T.
  12.               FINDNEWEVNET(sl, s', p).
  13.               Let s" be the lowest segment of L(p)UC(p) in T.
  14.               Let sl be the lower neighbor of s" in T.
  15.               FINDNEWEVNET(sl , s", p).
FINDNEWEVNET(su, sl , p)
  1. if su and s intersect to the right of the sweep line, or on it and below the current event point, and the intersection is not yet present as an event in Q
  2.      then Insert the intersection point as an event into Q.
The running time of Algorithm FINDINTERSECTIONS for a set of S of n line segments in the plane is O(nlogn + Ilogn), where I is the number of intersection points of segments in S.

C. Animation


    If your netscape/explorer has problems with Java JDK 1.1, go here

1. M. de Berg, M. van Kreveld, M. Overmars and O. Schwarzkopf, Computational Geometry Algorithms and Applications. Springer-Verlag,  March 1997.
2. Core JAVA, 1998 
Wei Qian

Last modified: Thu Sep 3 23:13:00 EDT 1998