0% found this document useful (0 votes)
53 views4 pages

1 Line Segment Intersection: 1.1 Plane Sweep Method

This document describes algorithms for line segment intersection and convex polygon intersection problems using the plane sweep technique. For line segment intersection, it presents an O(n log n) algorithm that sweeps a vertical line left to right, maintaining active segments using a y-structure balanced search tree. Intersections are detected and added to an x-structure heap as the sweep progresses. For convex polygon intersection, it improves the line segment approach to O(n) by only maintaining constant-sized upper and lower hulls in the y-structure at each sweep event, and restricting the x-structure to a constant number of possible next events.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

1 Line Segment Intersection: 1.1 Plane Sweep Method

This document describes algorithms for line segment intersection and convex polygon intersection problems using the plane sweep technique. For line segment intersection, it presents an O(n log n) algorithm that sweeps a vertical line left to right, maintaining active segments using a y-structure balanced search tree. Intersections are detected and added to an x-structure heap as the sweep progresses. For convex polygon intersection, it improves the line segment approach to O(n) by only maintaining constant-sized upper and lower hulls in the y-structure at each sweep event, and restricting the x-structure to a constant number of possible next events.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1 Line Segment Intersection

(Line Segment Intersection algorithm is described in Chapter 8.4.1 in Kurt Mehlhorn’s Data Struc-
tures and Algorithms book.)
Let L1 L2 Ln be n line segments in the plane. We would like to determine all their pairwise
intersections.
(We make the simplifying assumptions that no segment is vertical, no two endpoints or intersection
points have the same x-coordinate.)
This problem has a simple O n2 algorithm - take each pair of segments and check if they intersect
and if they do, report their intersection point. But in practical situations, most segments do not inter-
sect each other and we would like faster algorithms in such situations. We would like an algorithm
whose running time depends not only on n but also on s - the number of intersection points.

1.1 Plane sweep method


We use the plane sweep technique to design an O n s log n algorithm for this problem. The
plane sweep method is a powerful technique used in many problems of computational geometry. We
imagine sweeping a vertical line from left to right across the plane.
We do not really need the sweep line to move in a continuous manner. We identify a finite number
of points called “event points” and imagine the sweep line to move from one event point to the next.
At any point of the sweep, we maintain the invariant that we have already solved the problem correctly
to the left of the sweep line. Let us describe this method concretely below.

Event points: The endpoints of the n line segments are event points for us. These are not the only
ones - the s intersection points are also event points. But these are event points which are not known
in advance - they are computed on the fly as the sweep line moves. So we have totally 2n s event
points (2n corresponding to the left and right end points of the n segments and s corresponding to the
intersection points). We use a data structure called the x-structure to store the event points.
We move the sweep line from one event point to the next event point in an order sorted according
to their x-coordinate. The segment endpoints can be presorted since we know them in advance. But
we need to detect the next intersection point in advance. To do this we will maintain a data structure
called the y-structure. At any point of the sweep we divide the set L1 Ln into three pairwise disjoint
groups: dead, active and dormant. A line segment is active if exactly one of its endpoints is to the left
of the sweep line. In the figure below, L1 L3 are dead, L2 L5 L7 are active and L4 L6 are dormant.

L2 L7

L1 L4 L6
L5

L3

sweep line

1
The y-structure stores the active line segments ordered according to the y-coordinate of their inter-
section with the sweep line. In the previous figure, the y-structure at the current position of the sweep
line would have L2 L7 and L5 in this order.
Whenever two line segments become adjacent along the sweep line, we will check if they have an
intersection occurring to the right of the sweep line. If so, we will add that intersection point to our
x-structure.
A natural question is whether this strategy is sufficient to detect all intersection points. And it is
indeed the case.

Lemma 1 Given two segments Li and L j , which intersect in a point p, there is an event point prior to
the event point p, where Li and L j are adjacent.

We can now give an overall description of our algorithm.


x-structure the 2n endpoints of L1 Ln sorted by x-coordinate;
y-structure 0. /
while x-structure 0/ do
p a point with minimum x-coordinate in the x-structure;
delete p from the x-structure;
if p is a left endpoint then
Call Handle left endpoint(p)
end if
if p is a right endpoint then
Call Handle right endpoint(p)
end if
if p is an intersection point then
Call Handle intersection point(p)
end if
end while

Handle left endpoint(p): Handle left endpoint(p) means that we see the left endpoint of a line
segment L. So we have a new active segment now and we should add L to the y-structure. Since the
y-structure has segments sorted according to their intersection with the sweep line, we should add L
in its correct position (according to the position of p in the intervals formed on the sweep line by the
active line segments). In the figure below, we find that p is located in the interval between L5 and L1 .

L4

L5

p L6
L
3
L2
L1

sweep line

2
So, if Li and L j are the neighbors of L in the y-structure, then we check if Li and L intersect and if
so, we add that intersection point to the x-structure and similarly we check if Lj and L intersect and if
so, we add that intersection point to the x-structure.

Handle right end point(p): Handle right endpoint(p) means that we have come to the end of a line
segment L. We need to delete L from the y-structure. But before that we check if the neighbors of L
intersect to the right of the sweep line and if so, we add that point to the x-structure.

Handle intersection point(p): We report that p is an intersection point. We also have to update
our x and y structures. Let p be an intersection point of Li and L j . It means that in the y-structure
Li and L j are necessarily adjacent and now the positions of Li and L j should get interchanged. In the
figure below, after L5 and L2 intersect, L2 occurs before L5 in the sorted order on the sweep line.

L4

L5

L6
L
3
L2
L1

sweep line
So we interchange Li and L j in the y-structure. Let Lh and Lk be the two neighbors of Li and L j
in the y-structure (before the interchange). We check if Lh and L j intersect, similarly if Lk and Li
intersect to the right of the sweep line and we add the intersection points to the x-structure.

The x and y structures: What data structures should we use to implement the x and y structures?
We will implement the x-structure as a heap since we perform insertion and delete-min operations on
it. The y-structure needs to support the following operations:

find(p): given a point p on the sweep line, find the interval that contains p;

insert(L)

delete(L)

predecessor(L), successor(L): the neighbors of L in the y-structure

interchange(Li L j ): interchange adjacent segments Li and L j in the y-structure.

We will implement the y-structure as a balanced search tree. Then the above operations can be per-
formed in logarithmic time.

Theorem 1 The set of all s intersections of L1 Ln can be computed in O n s log n time.

3
2 Convex Polygon Intersection
(from the Computational Geometry Lecture Notes of David M. Mount)
We are given 2 convex polygons P1 and P2 with n vertices each and we would like to compute
P1 P2 . Note that P1 P2 is again a convex polygon. Also, observe that each edge of P1 and P2 can
contribute at most one edge to P1 P2 . So P1 P2 is a convex polygon with at most 2n edges.
Since the total number of points of intersection between the edges of P1 and P2 is 2n, using
the line segment intersection algorithm we get an O n log n algorithm for computing the vertices of
P1 P2 . But we can do better. Using the plane sweep method we can get an O n algorithm for this
problem.
We perform a left to right plane sweep, as before, to compute the intersection. We begin by
breaking the boundary of P1 into its upper hull and lower hull. Similarly we break the boundary of P2
into its upper and lower hulls.
As before, the y-structure stores the edges of P1 and P2 that currently intersect the sweep line. Note
that at any point there are at most 4 points in the y-structure. This is because at any given moment, the
sweep line can intersect the upper hull of P1 (similarly, P2 ) in at most 1 point and the lower hull of P1
( similarly, P2 ) in at most 1 point. See the figure below.

e1 P1
e3

e2 P2
e4

sweep line
We do not store all the endpoints of the edges of P1 and P2 in our x-structure. At any point there
are at most 8 possible candidates for the next event point. They correspond to the right end points
of the 4 edges currently stabbed by the sweep line (let us call these edges e1 e2 e3 e4 ) and up to 4
intersection points corresponding to e1 e3 e1 e4 e2 e3 e2 e4 .
Since there are only a constant number of items being stored in the x and y structures, our opera-
tions can be handled in O 1 time.

You might also like