AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf ·...

21
ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA SIAM J. COMPUT. c 2000 Society for Industrial and Applied Mathematics Vol. 29, No. 5, pp. 1401–1421 Abstract. In this paper, we reexamine in the framework of robust computation the Bentley– Ottmann algorithm for reporting intersecting pairs of segments in the plane. This algorithm has been reported as being very sensitive to numerical errors. Indeed, a simple analysis reveals that it involves predicates of degree 5, presumably never evaluated exactly in most implementations. Within the exact-computation paradigm we introduce two models of computation aimed at replacing the conventional model of real-number arithmetic. The first model (predicate arithmetic) assumes the exact evaluation of the signs of algebraic expressions of some degree, and the second model (exact arithmetic) assumes the exact computation of the value of such (bounded-degree) expressions. We identify the characteristic geometric property enabling the correct report of all intersections by plane sweeps. Verification of this property involves only predicates of (optimal) degree 2, but its straightforward implementation appears highly inefficient. We then present algorithmic variants that have low degree under these models and achieve the same performance as the original Bentley– Ottmann algorithm. The technique is applicable to a more general case of curved segments. Key words. computational geometry, segment intersection, plane sweep, robust algorithms AMS subject classifications. 68Q20, 68Q25, 68Q40, 68U05 PII. S0097539797329373 1. Introduction. As is well known, computational geometry has traditionally adopted the arithmetic model of exact computation over the real numbers. This model has been extremely productive in terms of algorithmic research, since it has permit- ted a vast community to focus on the elucidation of the combinatorial (topological) properties of geometric problems, thereby leading to sophisticated and efficient algo- rithms. Such an approach, however, has a substantial shortcoming, since all computer calculations have finite precision, a feature which affects not only the quality of the results but even the validity of specific algorithms. In other words, in this model, algorithm correctness does not automatically translate into program correctness. In fact, there are several reports of failures of implementations of theoretically correct algorithms (see, e.g., [For87, Hof89]). This state of affairs has engendered a vigorous debate within the research community, as is amply documented in the literature. Sev- eral proposals have been made to remedy this unsatisfactory situation. They can be split into two broad categories according to whether they perform exact computations (see, e.g., [BKM + 95, FV93, Yap97, She96]) or approximate computations (see, e.g., [Mil88, HHK89, Mil89]). This paper fine-tunes the exact-computation paradigm. The numerical compu- tations of a geometric algorithm are basically of two types: tests (predicates) and constructions, each with clearly distinct roles. Tests are associated with branching Received by the editors October 20, 1997; accepted for publication (in revised form) September 10, 1998; published electronically March 15, 2000. This work was partially supported by ESPRIT LTR 21957 (CGAL) and by the U.S. Army Research Office under grant DAAH04-96-1-0013. Part of the work was done while the first author was visiting the Center for Geometric Computing at Brown University. http://www.siam.org/journals/sicomp/29-5/32937.html INRIA, 2004 Route des Lucioles, BP 93, 06902 Sophia-Antipolis, France (Jean-Daniel.Boissonnat @sophia.inria.fr). Center for Geometric Computing, Computer Science Department, Brown University, 115 Water- man Street, Providence, RI 02912-1910, ([email protected]). 1401

Transcript of AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf ·...

Page 1: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS∗

JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

SIAM J. COMPUT. c© 2000 Society for Industrial and Applied MathematicsVol. 29, No. 5, pp. 1401–1421

Abstract. In this paper, we reexamine in the framework of robust computation the Bentley–Ottmann algorithm for reporting intersecting pairs of segments in the plane. This algorithm hasbeen reported as being very sensitive to numerical errors. Indeed, a simple analysis reveals that itinvolves predicates of degree 5, presumably never evaluated exactly in most implementations. Withinthe exact-computation paradigm we introduce two models of computation aimed at replacing theconventional model of real-number arithmetic. The first model (predicate arithmetic) assumes theexact evaluation of the signs of algebraic expressions of some degree, and the second model (exactarithmetic) assumes the exact computation of the value of such (bounded-degree) expressions. Weidentify the characteristic geometric property enabling the correct report of all intersections byplane sweeps. Verification of this property involves only predicates of (optimal) degree 2, but itsstraightforward implementation appears highly inefficient. We then present algorithmic variants thathave low degree under these models and achieve the same performance as the original Bentley–Ottmann algorithm. The technique is applicable to a more general case of curved segments.

Key words. computational geometry, segment intersection, plane sweep, robust algorithms

AMS subject classifications. 68Q20, 68Q25, 68Q40, 68U05

PII. S0097539797329373

1. Introduction. As is well known, computational geometry has traditionallyadopted the arithmetic model of exact computation over the real numbers. This modelhas been extremely productive in terms of algorithmic research, since it has permit-ted a vast community to focus on the elucidation of the combinatorial (topological)properties of geometric problems, thereby leading to sophisticated and efficient algo-rithms. Such an approach, however, has a substantial shortcoming, since all computercalculations have finite precision, a feature which affects not only the quality of theresults but even the validity of specific algorithms. In other words, in this model,algorithm correctness does not automatically translate into program correctness. Infact, there are several reports of failures of implementations of theoretically correctalgorithms (see, e.g., [For87, Hof89]). This state of affairs has engendered a vigorousdebate within the research community, as is amply documented in the literature. Sev-eral proposals have been made to remedy this unsatisfactory situation. They can besplit into two broad categories according to whether they perform exact computations(see, e.g., [BKM+95, FV93, Yap97, She96]) or approximate computations (see, e.g.,[Mil88, HHK89, Mil89]).

This paper fine-tunes the exact-computation paradigm. The numerical compu-tations of a geometric algorithm are basically of two types: tests (predicates) andconstructions, each with clearly distinct roles. Tests are associated with branching

∗Received by the editors October 20, 1997; accepted for publication (in revised form) September10, 1998; published electronically March 15, 2000. This work was partially supported by ESPRITLTR 21957 (CGAL) and by the U.S. Army Research Office under grant DAAH04-96-1-0013. Part ofthe work was done while the first author was visiting the Center for Geometric Computing at BrownUniversity.

http://www.siam.org/journals/sicomp/29-5/32937.html†INRIA, 2004 Route des Lucioles, BP 93, 06902 Sophia-Antipolis, France (Jean-Daniel.Boissonnat

@sophia.inria.fr).‡Center for Geometric Computing, Computer Science Department, Brown University, 115 Water-

man Street, Providence, RI 02912-1910, ([email protected]).

1401

Page 2: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1402 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

decisions in the algorithm that determine the flow of control, whereas constructionsare needed to produce the output data. While approximations in the execution ofconstructions are often acceptable, approximations in the execution of tests mayproduce incorrect branching, leading to the inconsistencies which are the object ofthe criticisms leveled against geometric algorithms. The exact-computation paradigmtherefore requires that tests be executed with total accuracy. This will guarantee thatthe result of a geometric algorithm will be topologically correct albeit geometricallyapproximate. This also means that robustness is in principle achievable if one is will-ing to employ the required precision. The reported failures of structurally correctalgorithms are entirely attributable to noncompliance with this criterion.

Therefore, geometric algorithms can also be characterized on the basis of thecomplexity of their predicates. The complexity of a predicate is expressed by thedegree of a homogeneous polynomial embodying its evaluation. The degree of analgorithm is the maximum degree of its predicates, and an algorithm is robust if theadopted precision matches the degree requirements.

The “degree criterion” is a design principle aimed at developing low-degree algo-rithms. This approach involves reexamining under the degree criterion the rich bodyof geometric algorithms known today, possibly without negatively affecting traditionalalgorithmic efficiency. A previous paper [LPT96] considered as an illustration of thisapproach the issue of proximity queries in two and three dimensions. As an addi-tional case of degree-driven algorithm design, in this paper we confront another classof important geometric problems, which have caused considerable difficulties in ac-tual implementations: plane sweep problems for sets of segments. As we shall see,plane sweep applications involve a number of predicates of different degree and algo-rithmic power. Their analysis not only will lead to new and robust implementations(an outcome of substantial practical interest) but will elucidate on a theoretical levelsome deeper issues pertaining to the structure of several related problems and themechanism of plane sweeps.

2. Three problems associated with intersecting segments. Given is afinite set S of line segments in the plane. Each segment is defined by the coordinatesof its two endpoints. We discuss the three following problems (see Figure 2.1):

Pb1: Report the pairs of segments of S that intersect.Pb2: Construct the arrangement A of S, i.e., the incidence structure of the graph

obtained interpreting the union of the segments as a planar graph.Pb3: Construct the trapezoidal map T of S. T is obtained by drawing two vertical

line segments (walls), one above and one below each endpoint of the segmentsand each intersection point. The walls are extended either until they meetanother segment of S or to infinity.

Let S1, . . . , Sn be the segments of S, and let k be the number of intersecting pairs.We say that the segments are in general position if any two intersecting segmentsintersect in a single point, and all endpoints and intersection points are distinct.

The number of intersection points is no more than the number of intersecting pairsof segments, and both are equal if the segments are in general position. Therefore, thenumber of vertices of A is at most k, the number of edges of A is at most n+2k, andthe number of vertical walls in T is at most 2(n + k), the bounds being tight whenthe segments are in general position. Thus the sizes of both A and T are O(n + k).We didn’t consider here the two-dimensional faces of either A or T . Including themwould not change the problems we address.

Page 3: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1403

S

A

T

Fig. 2.1. A set of segments S, the corresponding arrangement A and its trapezoidal map T .

3. Algebraic degree and arithmetic models. It is well known that the ef-ficient algorithms that solve Pb1–Pb3 are very unstable when implemented usingnonexact arithmetic, and several frustrating experiences have been reported [For85].This motivates us to carefully analyze the predicates involved in those algorithms. Wefirst introduce here some terminology borrowed from [LPT96]. See also [Bur96, For93].We consider each input data (i.e., coordinates of an endpoint of some segment of S)as a variable.

An elementary predicate is the sign −, 0, or + of a homogeneous multivariatepolynomial whose arguments are a subset of the input variables. The degree of anelementary predicate is defined as the maximum degree of the irreducible factors(over the rationals) of the polynomials that occur in the predicate and that do nothave a constant sign. A predicate is more generally a Boolean function of elementarypredicates. Its degree is the maximum degree of its elementary predicates.

Page 4: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1404 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

The degree of an algorithm A is defined as the maximum degree of its predicates.The degree of a problem P is defined as the minimum degree of any algorithm

that solves P .In most problems in computational geometry, d = O(1). However, as d affects the

speed and/or robustness of an algorithm, it is important to measure d precisely.In the rest of this paper we consider the degree as an additional measure of

algorithmic complexity. Note that, qualitatively, degree and memory requirementsare similar, since the arithmetic capabilities demanded by a given degree must beavailable, albeit they may be never resorted to in an actual run of the algorithm(since the input may be such that predicates may be evaluated reliably with lowerprecision).

We will consider two arithmetic models. In the first one, called the predicate arith-metic of degree d, the only numerical operations that are allowed are the evaluations ofpredicates of degree at most d. Algorithms of degree d can therefore be implementedexactly in the predicate arithmetic model of degree d. This model is motivated byrecent results that show that evaluating the sign of a polynomial expression may befaster than computing its value (see [ABD+97, BY97, BEPP97, Cla92, She96]). Thismodel, however, is very conservative since the nonavailability of the arithmetics re-quired by a predicate is assimilated to an entirely random choice of the value of thepredicate.

The second model, called the exact arithmetic of degree d, is more demanding.It assumes that values (and not just signs) of polynomials of degree at most d berepresented and computed exactly (i.e., roughly as d-fold precision integers). However,higher-degree operations (e.g., a multiplication operation of whose factors is a d-foldprecision integer) are appropriately rounded. Typical rounding is rounding to thenearest representable number, but less accurate rounding can also be adequate as willbe demonstrated later.

Let P be a predicate (polynomial) of degree d. We ignore for simplicity the sizeof the coefficients of P , because they are typically small constants; if the input dataare all b-bit integers, the size of each monomial in predicate P is upper bounded by2bd. Moreover, let v be the number of variables that occur in a predicate; for mostgeometric problems and, in particular, for those considered in this paper, v is a smallnumber. Since the polynomial P is homogeneous, it may contain only highest-degreemonomials, whose number is bounded by vd. It follows that an algorithm of degree drequires precision p ≤ db+d log v = db+O(1) in the exact arithmetic model of degreed.

4. The predicates and the degree of problems Pb1–Pb3. In this section,we analyze the degree of problems Pb1–Pb3 (in subsections 4.1–4.3) and of the stan-dard algorithms for solving these problems (in subsection 4.4).

We use the following notations. The coordinates of point Ai are denoted xi andyi. Ai <x Aj means that the x-coordinate of point Ai is smaller than the x-coordinateof point Aj . The same is true for <y. [AiAj ] denotes the line segment whose left andright endpoints are, respectively, Ai and Aj , while (AiAj) denotes the line containing[AiAj ]. Ai <y (AjAk) means that point Ai lies below line (AjAk).

4.1. Predicates. Pb1 requires only that we check if two line segments intersect(Predicate 2′ below).

Pb2 requires in addition the ability to sort intersection points along a line segment(Predicate 4 below).

Pb3 requires the ability to execute all the predicates listed below.

Page 5: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1405

Predicate 1: A0 <x A1.Predicate 2: A0 <y (A1A2).Predicate 2′: [A0A1]

⋂[A2A3] = ∅.

Predicate 3: A0 <x [A1A2]⋂[A3A4].

Predicate 4: [A0A1]⋂[A2A3] <x [A0A1]

⋂[A4A5].

Predicate 5: [A0A1]⋂[A2A3] <x [A4A5]

⋂[A6A7].

Two other predicates appear in some algorithms that report segment intersections.Predicate 3′: (x = x0)

⋂[A1A2] <y (x = x0)

⋂[A3A4].

Predicate 4′: [A0A1]⋂[A2A3] <y (A4A5).

4.2. Algebraic degree of the predicates. We now analyze the algebraic de-gree of the predicates introduced above.

Proposition 4.1. The degree of Predicates i and i′ (i = 1, . . . , 5) is i.Proof. We first provide explicit formulae for the predicates.Evaluating Predicate 2 is equivalent to evaluating the sign of

orient(A0A1A2) =

∣∣∣∣∣∣

x0 x1 x2

y0 y1 y21 1 1

∣∣∣∣∣∣=

∣∣∣∣x1 − x0 x2 − x0

y1 − y0 y2 − y0

∣∣∣∣ .

Predicate 2′ can be implemented as follows for the case A0 <x A2 (otherwise weexchange the roles of [A0A1] and [A2A3]):

if A1 <x A2 then return falseif A3 <x A1

if orient(A0A1A2)× orient(A0A1A3) < 0 then return trueelse return false

elseif orient(A0A1A2)× orient(A2A3A1) > 0 then return trueelse return false

Therefore, in all cases, Predicate 2′ reduces to Predicate 2.The intersection point I = [AiAj ]

⋂[AkAl] is given by

I = Ai + (Aj −Ai)NI

DI(4.1)

with NI = orient(AiAkAl) and

DI =

∣∣∣∣xj − xi xk − xlyj − yi yk − yl

∣∣∣∣= orient(AiAjAk)− orient(AiAjAl)

def= Orient(AiAjAkAl).

Predicate 4′ reduces to evaluating orient(I, A0, A1), where I is the intersection of[A2A3] and [A4A5]. It follows from (4.1) that this is equivalent to evaluating the signof orient(A2A3A4A5) and of

orient(A0A1A2)×Orient(A2A3A4A5)− orient(A2A4A5)×Orient(A0A1A2A3).

Predicates 3–5: Explicit formulas for Predicates 3, 4, and 5 can be immediatelydeduced from the coordinates of the intersection points I = [A0A1]

⋂[A2A3] and

J = [A4A5]⋂[A6A7] which are given by (4.1). If A4A5 = A0A1, it is clear from (4.1)

that (x1 − x0) is a common factor of xI − x0 and xJ − x0.

Page 6: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1406 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

If [A1A2] and [A3A4] do not intersect, Predicate 3′ reduces to Predicate 2. Oth-erwise, it reduces to Predicate 3.

The above discussion shows that the degree of predicates i and i′ is at most i.To establish that it is exactly i, we have shown in the appendix that the polynomialsof Predicates 2, 3, 4′, and 5, as well as the factor other than (x1 − x0) involved inPredicate 4, are irreducible over the rationals.

It follows that the proposition is proved for all predicates.Recalling the requirements of the various problems in terms of predicates, we have

the following proposition.Proposition 4.2. The algebraic degrees of Pb1, Pb2, and Pb3 are, respectively,

2, 4, and 5.

4.3. Implementation of Predicate 3 with exact arithmetic of degree 2.As they will be useful in section 7, in this subsection we present two approximateimplementations of Predicate 3 (of degree 3) under the exact arithmetic of degree 2.

From (4.1) we know that Predicate 3 can be written as

x01D < x21N,(4.2)

where x01 = x0 − x1, x21 = x2 − x1, D = | Orient(A1A2A3A4)|, and N = sign(D)×orient(A1A3A4).

We stipulate to employ floating-point arithmetic conforming to the IEEE 754standard [Gol91]. In this standard, simple precision allows us to represent b-bit integerswith b = 24 and double precision allows us to represent b′-bit integers with b′ =2b+5 = 53. The coordinates of the endpoints of the segments are represented in simpleprecision, and the computations are carried out in double precision. We denote ⊕, ⊗,and the rounded arithmetic operations +,×, and /. In the IEEE 754 standard,all four arithmetic operations are exactly rounded; i.e., the computed result is thefloating-point number that best approximates the exact result.

Since Orient(A1A2A3A4) and orient(A1A3A4) are (2b + 3)-bit integers, the fourterms x01, x21, N , and D in inequality (4.2) can be computed exactly in doubleprecision, and the following monotonicity property is a direct consequence of exactrounding of arithmetic operations.

Monotonicity property 1: x01 ⊗D < x21 ⊗N =⇒ x01 ×D < x21 ×N.This implies that the comparison between the two computed expressions x01 ⊗D

and x21 ⊗N evaluates Predicate 3 except when these numbers are equal.Since in most algorithms, an intersection point is compared with many endpoints,

it is more efficient to compute and store the coordinates of each intersection point andto perform comparisons with the computed abscissae rather than to evaluate (4.2) re-peatedly. We now illustrate an effective rounding procedure of the x-coordinates ofintersection points which gives an alternative approximate implementation of Predi-cate 3.

Lemma 4.3. If the coordinates of the endpoints of the segments are simple pre-cision integers, then the abscissa xI of an intersection point can be rounded to oneof its two nearest simple precision integers using only double precision floating-pointarithmetic operations.

Proof. We assume that the coordinates of the endpoints of the segments arerepresented as b-bit integers stored as simple precision floating-point numbers. Thecomputations are carried out in double precision.

Page 7: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1407

The rounded value xI of xI is given by

xI = ((x21 ⊗N)D) ⊕ x1,

where X denotes the integer nearest to X (with any tie-breaking rule). If ε = 2−b′

is a strict bound to the modulus of the relative error of all arithmetic operations,X = (x21 ⊗N)D satisfies the following relations:

x21N

D(1− 2ε) ≈ x21N

D(1− ε)2 < X < x21N

D(1 + ε)2 ≈ x21N

D(1 + 2ε).

As x21ND = xI − x1 ≤ 2b+1, we obtain

|(x21 ⊗N)D − x21N/D)| <∼ 2b+122−b′ = 2−b−3 1.

We round X to the nearest integer X. Since X and x1 are (b+1)-bit integers,there is no error in the addition. Therefore, xI is a (b+2)-bit integer and the absoluteerror on xI is smaller than 1.

It follows that, under the hypothesis of the lemma, if E is an endpoint, I is an in-tersection point, and I is the corresponding rounded point, the following monotonicityproperty holds.

Monotonicity property 2: I <x E =⇒ I <x E,

E <x I =⇒ E <x I.

This implies that the comparison between the x-coordinates of I and E evaluatesPredicate 3, except when the abscissae of I and E coincide.

Notice that the monotonicity property does not necessarily hold for two intersec-tion points.

Remark 1. A result similar to Lemma 4.3 has been obtained by Priest [Pri92] forpoints with floating-point coordinates. More precisely, if the endpoints of the segmentsare represented as simple precision floating-point numbers, Priest [Pri92] has proposeda rather complicated algorithm that uses double precision floating-point arithmeticand rounds xI to the nearest simple precision floating-point number. Since it appliesto the integers as well, this stronger result also implies the monotonicity property.

4.4. Algebraic degree of the algorithms. The naive algorithm for detectingsegment intersections (Pb1) evaluates Θ(n2) Predicates 2′ and thus is of degree 2,which is degree-optimal by the proposition above. Although the time-complexity ofthe naive algorithm is worst-case optimal, since 0 ≤ k ≤ 1

2n(n−1), it is worth lookingfor an output sensitive algorithm whose complexity depends on both n and k. Chazelleand Edelsbrunner [CE92] have shown that Ω(n log n + k) is a lower bound for Pb1and therefore also for Pb2 and Pb3. A very recent algorithm of Balaban [Bal95] solvesPb1 optimally in O(n log n+ k) time using O(n) space. This algorithm does not solvePb2 nor Pb3 and, since it uses Predicate 3′, its degree is 3.

Pb2 can be solved by first solving Pb1 and subsequently sorting the reportedintersection points along each segment. This can easily be done in O((n+k) log n) timeby a simple algorithm of degree 4 using O(n) space. A direct (and asymptotically moreefficient) solution to Pb2 has been proposed by Chazelle and Edelsbrunner [CE92].Its time complexity is O(n log n + k), and it uses O(n + k) space. Their algorithm,which constructs the arrangement of the segments, is of degree 4.

A solution to Pb3 can be deduced from a solution to Pb2 in O(n+ k) time usinga very complicated algorithm of Chazelle [Cha91]. A deterministic and simple algo-rithm due to Bentley and Ottmann [BO79] solves Pb3 in O((n+k) log n) time, which

Page 8: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1408 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

is slightly suboptimal, using O(n) space. This classical algorithm uses the sweep-line paradigm and evaluates O((n+ k) log n) predicates of all types discussed above,and therefore has degree 5. Incremental randomized algorithms [CS89, BDS+92] con-struct the trapezoidal map of the segments and thus solve Pb3 and have degree 5.Their time complexity and space requirements are optimal (although only as expectedperformances).

In this paper, we revisit the Bentley–Ottmann algorithm and show that a variantof degree 3 (instead of 5) [Mye85, Sch91] can solve Pb1 with no sacrifice of performance(section 6.1). Although this algorithm is slightly suboptimal with respect to timecomplexity, it is much simpler than Balaban’s algorithm. We also present two variantsof the sweep-line algorithm. The first one (section 6.2) uses only predicates of degreeat most 2 and applies to the restricted but important special case where the segmentsbelong to two subsets of nonintersecting segments. The second one (section 7) usesthe exact arithmetic of degree 2. All these results are based on a (nonefficient) lazysweep-line algorithm (to be presented in section 5) that solves Pb1 by evaluatingpredicates of degree at most 2.

Remark 2. When the segments are not in general position, the number s of in-tersection points can be less than the number k of intersecting pairs. In the extreme,s = 1 and k = n(n − 1)/2. Some algorithms can be adapted so that their time com-plexities depend on s rather than k [BMS94]. However, a lower bound on the degreeof such algorithms is 4 since they must be able to detect if two intersection points areidentical, therefore to evaluate Predicate 4′.

5. A lazy sweep-line algorithm. Let S be a set of n segments whose endpointsare E1, . . . , E2n. For a succinct review, the standard algorithm first sorts E1, . . . , E2n

by increasing x-coordinates and stores the sorted points in a priority queue X, calledthe event schedule. Next, the algorithm begins sweeping the plane with a vertical lineL and maintains a data structure Y that represents a subset of the segments of S(those currently intersected by L, ordered according to the ordinates of their intersec-tions with L). Intersections are detected in correspondence of adjacencies created inY , either by insertion/deletion of segment endpoints or by order exchanges at inter-sections. An intersection, upon detection, is inserted into X according to its abscissa.Of course, a given intersection may be detected several times. Multiple detections canbe resolved by performing a preliminary membership test for an intersection in X andomitting insertion if the intersection has been previously recorded. An intersection isreported when the sweep-line reaches its abscissa. We stipulate to use another pol-icy to resolve multiple detections, namely to remove from X an intersection point Iwhose associated segments are no longer adjacent in Y . Event I will be reinserted inX when the segments become again adjacent in Y . This policy has also the advantageof reducing the storage requirement of Bentley–Ottmann’s algorithm to O(n) [Bro81].

5.1. Description of the lazy algorithm. We now describe a modification ofthe sweep-line algorithm that does not need to process the intersection points byincreasing x-coordinates.

First, the algorithm sorts the endpoints of the segments by increasing x-coordinatesinto an array X. Let E1, . . . , E2n be the sorted list of endpoints.

Then the algorithm starts processing events and maintains a dictionary Y thatstores an ordered subset of the line segments. The events consist of the endpoints andof a subset of the pairs of segments that intersect and are adjacent in Y . Such pairsare called processable and will be precisely defined below. The algorithm processes theendpoints by increasing order of their x-coordinates, but, contrary to the standard

Page 9: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1409

algorithm, the processable pairs are processed in any order. As a consequence, twointersection points or even an intersection point and an endpoint won’t necessarilybe processed in the order of their x-coordinates, and Y won’t necessarily representthe ordered set of segments intersecting some vertical line L (as in the standardalgorithm).

The events are processed in the same way as in the standard algorithm, i.e.,processing an endpoint means either the insertion of the corresponding segment intoY or its deletion from it (as appropriate), and processing an intersection means itsreport and the exchange of the two segments involved. The only difference is thatwe maintain a set P of processable pairs: each time a pair of intersecting segmentsbecome adjacent in Y , we check whether the pair is processable and, in the affirmative,add it to P .

While there are processable pairs, the algorithm extracts any of them from P andprocesses it. When there are no more processable pairs, the algorithm proceeds to thenext endpoint. When there are no more processable pairs and no more endpoints tobe processed, the algorithm stops.

To complete the description of the algorithm, we need to define the processablepairs. The definition rests on the notions of active and prime pairs to be given below.We need the following notations. We denote by L(Ei) the vertical line passing throughEi. Slab (Ei, Ei+1) denotes the open vertical slab bounded by L(Ei) and L(Ei+1), and(Ei, Ei+1] denotes the semiclosed slab obtained by adjoining line L(Ei+1) to the openslab (Ei, Ei+1). For two segments Sk and Sl, we denote by Akl their rightmost leftendpoint, by Bkl their leftmost right endpoint, and by Ikl their intersection point whenthey intersect (see Figure 5.1). In addition, Wkl denotes the set of segment endpointsthat belong to the (closed) region bounded by the vertical lines L(Akl) and L(Bkl)and by the two segments (a trapezoid if the two segments do not intersect, a double-wedge otherwise). We denote by Ekl the most recently processed element of Wkl andby Fkl the element of Wkl to be processed next. (Note that Ekl and Fkl are alwaysdefined, since they may respectively coincide with Akl and Bkl.) Last, we define setsW+

kl(Ekl) and W−kl (Ekl) as follows. If Sk and Sl do not intersect, W+

kl(Ekl) = ∅ andW−

kl (Ekl) consists of all points E ∈ Wkl, Ekl ≤x E. Otherwise, an endpoint E ∈ Wkl

belongs to W+kl(Ekl) (respectively, to W

−kl (Ekl)) if Ekl ≤x E and if the slab (Ekl, E]

does (respectively, does not) contain Ikl.1

Definition 5.1. Let (Sk, Sl) be a pair of segments, and assume without lossof generality that Sk

⋂L(Ekl) <y Sl

⋂L(Ekl). The pair is said to be active if the

following conditions are satisfied:(1) Sk and Sl are adjacent in Y,(2) Sk < Sl in Y,(3) Fkl ∈W+

kl(Ekl) (emptiness condition).Observe that the emptiness condition implies that the segments intersect (since

W+kl(Ekl) = ∅ if they do not). We now identify a subset of the active pairs, whose

processing, as we shall see, has priority.Definition 5.2. An active pair of segments (Sk, Sl) is said to be prime if the

next endpoint to be processed belongs to Wkl (i.e., it coincides with Fkl ∈W+kl(Ekl)).

It should be noted that deciding if a pair of intersecting segments is active or primereduces to the evaluation of Predicates 2 only and the condition Fkl ∈W+

kl(Ekl) should

1For line segments or even pseudosegments, W−kl(Ekl) and W+

kl(Ekl) do not depend on Ekl.

However, we keep Ekl as a parameter in preparation for the more general case of monotone arcs. SeeRemark 4 at the end of this section.

Page 10: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1410 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

Sk

Sl

Ikl

L(Akl) L(Bkl)

Akl

Bkl

Ekl

Fkl

W+kl(Ekl)

W−kl (Ekl)

Fig. 5.1. For the definitions of W−kl(Ekl) and W+

kl(Ekl).

not be construed as implying the comparison of the abscissae of Ikl and Fkl (Predicate3). Indeed, if Sk

⋂L(Akl) <y Sl

⋂L(Akl) (which can be decided by Predicate 2), then

the emptiness condition corresponds to Fkl <y Sk and Sl <y Fkl.For reasons that will be clear below, the set of processable pairs is not specified

in the finest detail in this section, since several different implementations are possible.We require only that, at any time, the two following assertions remain true.

(1) All prime pairs are processable.(2) All processable pairs are active.

In other words, the next endpoint may be processed once there are no more primepairs, without placing any deadline on the processing of the current active pairs aslong as they are not prime.

In the rest of this section, we will simply assume that we have an oracle at ourdisposal that can decide if a given pair is processable. Clearly, for some instancesof the lazy algorithm (e.g., when considering all active pairs as processable), theoracle can be implemented with Predicates 2 only. In such a case, the lazy algorithminvolves only Predicates 1 and 2 and is of degree 2 by Proposition 4.1. We will proveits correctness in the next subsection.

The important issue of efficiently detecting the processable pairs will be consideredin sections 6 and 7 where several oracles will be introduced. These instances of thelazy algorithm will still be correct but, in some cases, will have a degree higher than2.

Page 11: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1411

5.2. Correctness of the lazy algorithm. Let Y −(Ei) and Y +(Ei) be, re-spectively, snapshots of the data structure Y immediately before and after processingevent Ei, i = 1, . . . , 2n. Observe that Y −(Ei) and Y

+(Ei) differ only by the segmentS that has Ei as one of its endpoints. Let Y (Ei) = Y −(Ei)

⋃Y +(Ei). The order

relation in Y is denoted by <.Theorem 5.3. If Predicates 1 and 2 are evaluated exactly, the described lazy

sweep-line algorithm will detect all pairs of segments that intersect.Proof. The algorithm (correctly) sorts the endpoints E1, . . . , E2n of the segments

by increasing x-coordinates into X. Consequently, the set of segments that intersectL(E) and the set of segments in Y (E) coincide for any endpoint E. The proof of thetheorem is articulated now as two lemmas and their implications.

Lemma 5.4. Two segments have exchanged their positions in Y if and only ifthey intersect and if the pair has been processed.

Proof. Let us consider two segments, say Sk and Sl, that do not intersect. Withoutloss of generality, let Sk < Sl in Y (Akl). Assume for a contradiction that Sl < Sk inY −(Bkl). Sk and Sl cannot exchange their positions because they will never form anactive pair. Therefore, Sl < Sk in Y −(Bkl) can happen only if there exists a segmentSm, m = k, l, that at some stage in the execution of the algorithm was present in Ytogether with Sk and Sl and caused one of the following two events to occur.

(1) Sm > Sl and the positions of Sm and Sk are exchanged in Y .(2) Sm < Sk and the positions of Sm and Sl are exchanged in Y .

In both cases, the segments that exchange their positions are not consecutive in Y ,violating condition 1 of Definition 5.1.

Therefore, two segments can exchange their positions in Y only if they intersectand this can happen only when their intersection is processed. Moreover, when the in-tersection has been processed, the segments are no longer active and cannot exchangetheir positions a second time.

We say that an endpoint E of S is correctly placed if and only if the subset of thesegments that are below E (in the plane) coincides with the subset of the segments< S in Y (E), i.e.,

∀S′ ∈ Y (E), S′ < S ⇐⇒ S′ ⋂L(E) <y S⋂L(E).

Otherwise, E is said to be misplaced. (Note that S⋂L(E) coincides with E.)

Lemma 5.5. If Predicates 1 and 2 are evaluated exactly, both endpoints of everysegment are correctly placed.

Proof. Assume, for a contradiction, that E of S is the first endpoint to be mis-placed by the algorithm.

Claim 1. E can be misplaced only if there exist at least two intersecting segmentsSk and Sl in Y

−(E) such that E belongs to Wkl.Proof. First recall that Predicate 2 is the only predicate involved in placing S in

Y .Consider first the case where E is the left endpoint of S. Let (Sk, Sl) be any pair

of segments in Y −(E). If E ∈Wkl, then both Sl and Sk are either above or below E,and their relative order does not affect the placement of E. This establishes that Ewill be correctly placed in Y +(E) (i.e., the contrapositive of the necessary conditionexpressed by the claim).

Suppose now that E is a right endpoint. In this case we shall establish the lemmain its direct form. The left endpoint of S has been correctly placed since it wasprocessed earlier and E is the first one to be misplaced. If E has been misplaced,

Page 12: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1412 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

then, by Lemma 5.4, there exists a segment S′ ∈ Y −(E) intersecting S to the left ofE such that the relative positions of S and S′ in Y +(A) and Y −(E) are the same (Ais the rightmost left endpoint of S and S′), i.e., their order in Y has not been reversedby the algorithm. In this case, E = Bkl ∈ Wkl for Sk = S and Sl = S

′, thus provingthat there exists a pair Sl and Sk such that Sl and Sk intersect and E ∈Wkl.

Let Sk and Sl be two segments of Y−(E) such that E ∈Wkl. Assume without loss

of generality that Sk < Sl in Y (Ekl). Since E is the first endpoint to be misplaced,we have Sk

⋂L(Ekl) <y Sl

⋂L(Ekl). For convenience, we will say that two segments

Sp and Sq have been exchanged between E′ and E′′ for two endpoints E′ <x E′′ if

Sp < Sq in Y+(E′) and Sq < Sp in Y −(E′′).

The case where E ∈W−kl (Ekl) cannot cause any difficulty since Sk and Sl cannot

be active between Ekl and E, and therefore, Sk and Sl cannot be exchanged betweenEkl and E, which implies that E is correctly placed with respect to Sk and Sl.

The case where E ∈ W+kl(Ekl) is more difficult. E is not correctly placed only

if Sk and Sl are not exchanged between Ekl and E, i.e., Sk < Sl in both Y +(Ekl)and Y −(E). We shall prove that this is not possible and therefore conclude that S iscorrectly placed into Y in this case as well.

Assume, for a contradiction, that Sk and Sl have not been exchanged betweenEkl and E. As E belongs to W+

kl(Ekl), Sk and Sl cannot be adjacent in Y−(E) since

otherwise they would constitute a prime pair and they would have been exchanged. Let(Sk = Sk0 , Sk1 , . . . , Skr , Skr+1 = Sl) (r ≥ 1) be the subsequence of segments of Y −(E)occurring between Sk and Sl with the further (legitimate) assumption that (Sk, Sl) isa pair of intersecting segments such that E ∈W+

kl(Ekl), for which r isminimal (i.e., forwhich the above subsequence is shortest). For an arbitrary 1 ≤ i ≤ r, consider segmentSki and assume, without loss of generality, that E <y Ski

. As a direct consequenceof the fact that (Sk, Sk1 , . . . , Skr , Sl) is shortest, we observe that E cannot belong toW+

kki(Ekki) nor to W

+kil(Ekil). We distinguish two cases.

(i) E <y Ski (see Figure 5.2). Clearly, E ∈ Wkil, and, by the above observation,we must have E ∈W−

kil(Ekil). It follows that the relative y-orders of Ski and Sl along

L(Ekil) and L(E) are the same, hence Sl⋂L(Ekil) <y Ski

⋂L(Ekil). As E is the first

endpoint to be misplaced, the order in Y +(Ekil) agrees with the geometry; i.e., wehave Sl < Ski in Y

+(Ekil). Moreover, since the pair (Ski , Sl) is not active (betweenEkil and E, because E ∈ W−

kil(Ekil)) and therefore cannot be exchanged, the same

inequality holds in Y −(E), which contradicts the definition of Ski .

(ii) Ski<y E. This case is entirely symmetric to the previous one. It suffices to

exchange the roles of Sk and Sl and to reverse the relations < and <y.

Since a contradiction has been reached in both cases, the lemma is proved.

We now complete the proof of the theorem. The previous lemma implies thatthe endpoints are correctly processed. Indeed let Ei be an endpoint. If Ei is a rightendpoint, we simply remove the corresponding segment from Y and update the set ofactive segments. This can be done exactly since predicates of degree ≤ 2 are evaluatedcorrectly. If Ei is a left endpoint, it is correctly placed in Y on the basis of the previouslemma.

The lemma also implies that all pairs that intersect have been processed. Indeedif Sp and Sq are two intersecting segments such that Sp

⋂L(Apq) <y Sq

⋂L(Apq) and

Sq⋂L(Bpq) <y Sp

⋂L(Bpq), the lemma shows that Sp < Sq in Y

+(Apq) and Sp > Sqin Y −(Bpq), which implies that the pair (Sp, Sq) has been processed (Lemma 5.4).

This concludes the proof of the theorem.

Remark 3. Handling the degenerate cases does not cause any difficulty, and the

Page 13: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1413

Sk

Sl

E

Ski

L(Ekl) L(E)

Fig. 5.2. For the proof of correctness of the lazy algorithm.

previous algorithm will work with only minor changes. For the initial sorting ofthe endpoints, we can take any order relation compatible with the order of theirx-coordinates, e.g., the lexicographic order.

Remark 4. Theorem 5.3 applies directly to pseudosegments, i.e., curved segmentsthat intersect in at most one point. Lemmas 5.4 and 5.5 also extend to the case ofmonotone arcs that may intersect at more than one point. To be more precise, inLemma 5.4, we have to replace “intersect” with “intersect an odd number of times”;Lemma 5.5 and its proof are unchanged provided that we define W+

kl(Ekl) (respec-tively, W−

kl (Ekl)) as the subset of Wkl consisting of the endpoints E, Ekl ≤x E, suchthat the slab (Ekl, E] contains an odd number (respectively, none or an even number)of intersection points. As a consequence, the lazy algorithm (which still uses onlyPredicates 1, 2, and 2′) will detect all pairs of arcs that intersect an odd number oftimes.

Remark 5. For line segments, observe that checking whether a pair of segmentsis active does not require knowing (and therefore maintaining) Ekl. In fact, we canreplace condition 3 in the definition of an active pair by the following condition:Sl <y Fkl <y Sk and Ikl <x Fkl. If Ekl <x Ikl, the two definitions are identical and ifIkl <x Ekl, the pair is not active since, by Lemma 5.5, condition 2 of the definitionwon’t be satisfied.

6. Efficient implementations of the lazy algorithm in the predicatearithmetic model. The difficulty of efficiently implementing the lazy sweep-linealgorithm using only predicates of degree at most 2 (i.e., in the predicate arithmeticmodel of degree 2) is due to verification of the emptiness condition in Definition 5.1and of the prime-pair condition expressed by Definition 5.2: both conditions requireexamination of all endpoints that have not been processed yet. One can easily checkthat various known implementations of the sweep achieve straightforward verification

Page 14: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1414 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

of the emptiness condition by introducing algorithmic complications. The followingsubsection describes an efficient implementation of the lazy algorithm in the predi-cate arithmetic model of degree 3. The second subsection improves on this result in aspecial but important instance of Pb1, namely the case of two sets of nonintersectingsegments. The algorithm presented there uses only predicates of degree at most 2.

6.1. Robustness of the standard sweep-line algorithm. We shall run ourlazy algorithm under the predicate arithmetic model of degree 3. We then have thecapability to correctly compare the abscissae of an intersection and of an endpoint. Werefine the lazy algorithm in the following way. Let Ei be the last processed endpointand let Ei+1 be the endpoint to be processed next. An active pair (Sk, Sl) that occursin Y between Y (Ei) and Y

−(Ei+1) will be processed if and only if its intersection pointIkl lies to the right of Ei and not to the right of Ei+1. As the slab is free of endpointsin its interior, any pair of adjacent segments encountered in Y (between Y (Ei) andY −(Ei+1)) and that intersect within the slab is active. Moreover the intersectionpoints of all prime pairs belong to the slab. It follows that this instance of the lazyalgorithm need not explicitly check whether a pair is active or not and therefore ismuch more efficient than the lazy algorithm of section 5. This algorithm is basicallywhat the original algorithm of Bentley–Ottmann2 becomes when predicates of degreeat most 3 are evaluated. (Recall that the standard algorithm requires the capabilityto correctly execute predicates of degree up to 5.)

We therefore conclude with the following theorem.

Theorem 6.1. If Predicates 1, 2, and 3 are evaluated exactly, the standard sweep-line algorithm will solve Pb1 in O((n+ k) log n) time.

It is now appropriate to briefly comment on the implementation details of thejust described modified algorithm. Data structure Y is implemented as usual as a dic-tionary. Data structure X, however, is even simpler than in the standard algorithm(which uses a priority queue with dictionary access). Here X has a primary compo-nent realized as a static search tree on the abscissae of the endpoints E1, . . . , E2n.Leaf Ej points to a secondary data structure L(Ej) realized as a conventional linkedlist, containing (in an arbitrary order) adjacent intersecting pairs in slab (Ej , Ej+1].Remember that, when Ej has been processed, all intersecting pairs of L(Ej) are ac-tive. Insertion into L(Ej) is performed at one of its ends, and so is access for reporting(when the plane sweep reaches slab (Ej , Ej+1]). Since access to events occurs in datastructure X, each pair in X must have pointers to the two corresponding segmentsin Y , in order to enable the necessary updates. In addition, to effect constant-timeremoval of a pair (Sh, Sk) due to loss of adjacency, all that is needed is to makebidirectional the mentioned pointers. Notice that the elements of X correspond topairs of adjacent segments in Y , so that at most two records in X are pointed to byany member of Y . We finally observe that a segment adjacency arising in Y duringthe execution of the algorithm must be tested for intersection; however, an intersect-ing pair of adjacent segments is eligible for insertion into X only as long as the planesweep has not gone beyond the slab containing the intersection in question. As regardsthe running time, beside the initial sorting of the endpoints and the creation of thecorresponding primary tree in time O(n log n), it is easily seen that each intersectionuses O(log n) time (amortized), thereby achieving the performance of the standardalgorithm.

2With the policy concerning multiple detections of intersections that is stipulated at the beginningof section 5.

Page 15: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1415

S1

S3

S4

S2

I12

I23

I34

Fig. 6.1. Assume that the computed x-coordinate of the intersection I12 of S1 and S2 is (erro-neously) found to be smaller than the x-coordinate of the left endpoint of S3. Y is implemented as abalanced binary search tree. The key associated to a node is the n

2th element of the corresponding

subtree. If all predicates of degree at most 2 are evaluated exactly, S3 is correctly inserted below S2,and S4 is correctly inserted above S1 and S2. The different states of Y are (S1), (S1, S2), (S2, S1),(S3, S2, S1), and (S3, S2, S1, S4). Since segments S3 and S4 are never adjacent, their intersectionI34 will not be detected. Observe that the missed intersection point can be arbitrarily far from theintersection point involved in the wrong decision.

Finally, we note that if only predicates of degree ≤ 2 are evaluated correctly,the algorithm of Bentley–Ottmann may fail to report the set of intersecting pairs ofsegments. See Figure 6.1 for an example.

Remark 6. The fact that the sweep-line algorithm does not need to sort intersectionpoints had already been observed by several authors including Myers [Mye85], Schorn[Sch91], and Hobby [Hob93]. Myers does not use it for solving robustness problemsbut for developing an algorithm with an expected running time of O(n log n + k).Schorn uses this fact to decrease the precision required by the sweep-line algorithmfrom fivefold to threefold; i.e., Schorn’s algorithm uses exact arithmetic of degree 3.Using Theorem 5.3, we will show in section 7 that double precision suffices.

6.2. Reporting intersections between two sets of nonintersecting linesegments. In this subsection, we consider two sets of line segments in the plane,Sb (the blue set) and Sr (the red set), where no two segments in Sb (similarly, inSr) intersect. Such a problem arises in many applications, including the union of twopolygons and the merge of two planar maps. We denote by nb and nr the cardinalitiesof Sb and Sr, respectively, and let n = nb + nr.

Mairson and Stolfi [MS88] have proposed an algorithm that works for arcs of curveas well as for line segments. Its time complexity is O(n log n+k), which is optimal, andrequires O(n+ k) space (O(n) in case of line segments). The same asymptotic time-bound has been obtained by Chazelle et al. [CEGS94] and by Chazelle and Edelsbrun-ner [CE92]. The latter algorithm is not restricted to two sets of nonintersecting linesegments. Other algorithms have been proposed by Nievergelt and Preparata [NP82]and by Guibas and Seidel [GS87] in the case where the segments of Sb (and Sr) are

Page 16: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1416 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

Sb

Sr

Tbr

L−b

L+b

Ibr

Fig. 6.2. Notations for the case of two sets of nonintersecting line segments.

the edges of a subdivision with convex faces. With the exception of the algorithm ofChazelle et al. [CEGS94], all these algorithms construct the resulting arrangementand therefore have degree 4. The algorithm of Chazelle et al. requires comparing theordinates of the intersections of two segments with a vertical line passing through anendpoint. Therefore it is of degree 3.

We propose here an algorithm that computes all the intersections but not the ar-rangement. This algorithm uses only predicates of degree ≤ 2 and has time complexityO((n+ k) log n).

Segments are assumed to be nonvertical since intersections with vertical segmentscan be easily handled with predicates of degree ≤ 2. We say that a point Ei is verticallyvisible from a segment Sb ∈ Sb if the vertical line segment joining Ei with Sb doesnot intersect any other segment in Sb (the same notion is applicable to Sr). For twointersecting segments Sb ∈ Sb and Sr ∈ Sr, let L be a vertical line to the right ofAbr such that no other segment intersects L between Sb and Sr (i.e., Sb and Sr areadjacent). We let Tbr denote the wedge defined by Sb and Sr in the slab between Land L(Ibr) (see Figure 6.2). For a point set F , we let CH+(F) and CH−(F) denoteits upper and lower convex hulls, respectively.

Our algorithm is based on the following observation.

Lemma 6.2. Tbr contains blue endpoints if and only if it contains a blue endpointthat is vertically visible from Sb. Similarly, Tbr contains red endpoints if and only ifit contains a red endpoint vertically visible from Sr.

Proof. The sufficient condition is trivial, so we prove only necessity. Assumewithout loss of generality that Sr

⋂L(Abr) <y Sb

⋂L(Abr). Let E be the subset of

the blue endpoints that belong to Tbr. Clearly, all vertices of CH+(E) are vertically

visible from Sb.

Our algorithm has two phases. The second one is the lazy algorithm of section

Page 17: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1417

5. The first one can be considered as a preprocessing step that will help to efficientlyfind active pairs of segments.

More specifically, our objective is to develop a quick test of the emptiness con-dition based on the previous lemma. The preprocessing phase is aimed at identifyingthe candidate endpoints for their potential belonging to wedges formed by intersectingadjacent pairs. Referring to Sb (and analogously for Sr), we first sweep the segmentsof Sb and construct for each blue segment Sb the lists L−

b and L+b of blue endpoints

that are vertically visible from Sb and lie respectively below and above Sb. The sweeptakes time O(n log n) and the constructed lists are sorted by increasing abscissa. Sincethere is no intersection point, only predicates of degree ≤ 2 are used. The total sizeof the lists L−

b , L+b , L−

r , and L+r is O(n).

As mentioned above, the crucial point is to decide whether or not the wedge Tbrof a pair of intersecting segments Sb and Sr, adjacent in Y , contains endpoints ofother segments. Again, we assume that Sr < Sb in Y . If such endpoints exist, thenTbr contains either a blue vertex of CH

+(L−b ∩L+) or a red vertex of CH−(L+

b ∩L+).(L+ is the half-plane to the right of line L.)

We will show below that, using predicates of degree ≤ 2, the lists can be prepro-cessed in time O(n log n) and that deciding whether or not Tbr contains endpoints canbe done in time O(log n), using only predicates of degree at most 2.

Assuming for the moment that this primitive is available, we can execute the planesweep algorithm described earlier. Specifically, we sweep Sb and Sr simultaneously,using the lazy sweep-line algorithm of section 5.3 Each time we detect a pair of(adjacent) intersecting segments Sb and Sr, we can decide in time O(log n) whetherthey are “active” or “not active,” using only predicates of degree ≤ 2.

We sum up the results of this section in the following theorem.Theorem 6.3. Given n line segments in the plane belonging to two sets Sb and Sr,

where no two segments in Sb (analogously, in Sr) intersect, there exists an algorithmof optimal degree 2 that reports all intersecting pairs in O((n + k) log n) time usingO(n) storage.

We now return to the implementation of the primitive described above. Supposethat, for some segment Si (i = b or r) we have constructed the upper hull CH+(L−

i ∩L+). Then we can detect in O(log n) time if an element of a list, say L−

b , lies abovesome segment Sr. More specifically, we first identify among the edges of CH+(L−

b ∩L+)the two consecutive edges whose slopes are, respectively, smaller and greater than theslope of Sr. This requires only the evaluation of O(log |L−

b |) predicates of degree 2.It then remains to decide whether the common endpoint E of the two reported edgeslies above or below the line containing Sr. This can be answered by evaluating theorientation predicate orient(E,Ar, Br).

The crucial requirement of the adopted data structure is the ability to efficientlymaintain CH+(L−

i ∩ L+). To this purpose, we propose the following solution.The data structure associated with a list L−

i (i = b or r) represents the upperconvex hull CH+(L−

i ) of L−i . (Similarly, the data structure associated with a list L+

i

represents the lower convex hull CH−(L+i ) of L+

i .) This implies that a binary searchon the convex hull slopes uniquely identifies the test vertex. Since the elements ofeach list are already sorted by increasing x-coordinates, the data structures can beconstructed in time proportional to their sizes and therefore in O(n) time in total.It can be easily checked that only orientation predicates (of degree 2) are involvedin this process. To guarantee the availability of CH+(L−

i ∩ L+), we have to ensure

3We can adopt the policy of processing all active pairs before the next endpoint.

Page 18: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1418 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

that our data structure can efficiently handle the deletion of elements. As elementsare deleted in order of increasing abscissa, this can be done in amortized O(log |S|)time per deletion [HS90, HS96]. It follows that preprocessing all lists takes O(n) time,uses O(n) space, and requires only the evaluation of predicates of degree ≤ 2.

7. An efficient implementation of the lazy algorithm under the exactarithmetic model of degree 2. We shall run the lazy algorithm of section 6.1under the exact arithmetic model of degree 2, i.e., Predicates 1 and 2 are evaluatedexactly but Predicate 3 is implemented with exact arithmetic of degree 2 as explainedin section 4.3. Several intersection points may now be found to have the same abscissaas an endpoint. We refine the lazy algorithm in the following way. Let Ei be the lastprocessed endpoint and let Ei+1 be the endpoint with an abscissa strictly greater thanthe abscissa of Ei to be processed next. An active pair (Sk, Sl) will be processed ifand only if its intersection point is found to lie to the right of Ei and not to the rightof Ei+1.

We claim that this policy leads to efficient verification of the emptiness condition.Indeed, the intersections of all prime pairs belong to (Ei, Ei+1], because Ei+1 ∈W+

kl(Ekl) =⇒ Ikl ≤x Ei+1, and, by the monotonicity property, both implementationsof Predicate 3 of section 4.3 will report that Ikl ≤x Ei+1.

The crucial observation that drastically reduces the time complexity is the fol-lowing. A pair of adjacent segments (Sk, Sl) encountered in Y between Y (Ei) andY (E−

i+1) whose intersection point is reported to lie in slab (Ei, Ei+1] is active if and

only if Ei+1 ∈ W−kl (Ekl). Indeed, since Ikl is found to be <x Ei+2, the monotonicity

property implies that Ikl <x Ei+2. Therefore, when checking if a pair is active, it issufficient to consider just the next endpoint, not all of them.

Theorem 5.3 therefore applies. If no two endpoints have the same x-coordinate, thealgorithm is the same as the algorithm in section 6.1 apart from the implementationof Predicate 3. Otherwise, we construct X on the distinct abscissae of the endpointsand store all endpoints with identical x-coordinates in a secondary search structurewith endpoints sorted by y-coordinates. This secondary structure will allow us todetermine if a pair is active in logarithmic time by binary search. We conclude withthe following theorem.

Theorem 7.1. Under the exact arithmetic model of degree 2, the instance of thelazy algorithm described above solves Pb1 in O((n+ k) log n) time.

8. Conclusion. Further pursuing our investigations in the context of the exact-computation paradigm, in this paper we have illustrated that important problems onsegment sets (such as intersection report, arrangement, and trapezoidal map), whichare viewed as equivalent under the Real-RAM model of computation, are distinct iftheir algebraic degree is taken into account. This sheds new light on robustness issueswhich are intimately connected with the notion of algebraic degree and illustrates therichness of this new direction of research.

For example, we have shown that the well-known plane sweep algorithm of Bentley–Ottmann uses more machinery than strictly necessary and can be appropriately mod-ified to report segment intersections with arithmetic capabilities very close to optimaland no sacrifice in performance.

Another result of our work is that exact solutions of some problems can be ob-tained even if approximate (or even random) evaluations of some predicates are per-formed. More specifically, using less powerful arithmetic than demanded by the appli-cation, we have been able to compute the vertices of an arrangement of line segments

Page 19: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1419

by constructing an arrangement which may be different from the actual one (and maynot even correspond to any set of straight line segments) but still has the same vertexset.

Our work shows that the sweep-line algorithm is more robust than usually be-lieved, proposes practical improvements leading to robust implementations, and pro-vides a better understanding of the sweeping line paradigm. The key to our techniqueis to relax the horizontal ordering of the sweep. This is one step further after similarattempts, aimed though at different purposes [Mye85, MS88, EG89].

A host of interesting open questions remain. One such question is to devise anoutput-sensitive algorithm for reporting segment intersections with optimal time com-plexity and with optimal algebraic degree (that is, 2). It would also be interesting toexamine the plane sweep paradigm in general. For example, with regard to the con-struction of Voronoi diagrams in the plane, one should elucidate the reasons for theapparent gap between the algebraic degrees of Fortune’s plane sweep solution and ofthe (optimal) divide-and-conquer and incremental algorithms.

Appendix. In connection with reducibility of polynomials over a domain of ra-tionality, we choose the rationals as the latter. “Reducible” means “reducible overthe rationals.”

We first recall that a general determinant is irreducible if its entries are regardedas independent variables [Boc07]. This suffices to prove directly that the degree ofPredicate 2 is 2 and will be crucial for completing the proof of irreducibility of thepolynomials pertaining to the other predicates. Use will be made of the followingtheorem.

Let p(x1, . . . , xn) be a multivariate homogeneous polynomial, and let I be a subsetof 1, . . . , n, such that for any j ∈ I, xj is a variable of degree 1 in p. For i ∈ 1, . . . , np can be expressed as

p = pixi + pi0,

where pi and pi0 are polynomials in all variables except xi. Two polynomials arenot considered distinct if they differ just by a multiplicative constant. We have thefollowing.

Theorem 8.1. Let p(x1, . . . , xn) be a multivariate homogeneous polynomial withdegree at least 3 and |I| ≥ 2. If for some i, j ∈ I, coefficients pi and pj are distinctand irreducible, then p is irreducible.

Proof. Assume, for a contradiction, that p is reducible. This means that p can beexpressed as p = φψ, where φ and ψ are multivariate homogeneous polynomials overthe same variables satisfying 1 ≤ degree(φ), degree(ψ) < degree(p). Each degree-1variable obviously appears in exactly one of the factors. With complete generality,assume that xi appears in φ. We distinguish two cases.

(1) degree(φ) > 1. Expanding φ around xi we obtain φ = φixi + φi0, so that

p = φψ = (φixi + φi0)ψ = φiψxi + φi0ψ.

This means that pi = φiψ, with degree(φi), degree(ψ) ≥ 1, i.e., pi is reducible,a contradiction.

(2) degree(φ) = 1. Variable xj appears either in φ or in ψ. In the first case, pi andpj are both proportional to ψ, i.e., they may differ only by a multiplicativeconstant and are not distinct, a contradiction.In the second case, by an argument analogous to that of Case 1, we reach theconclusion that pj = φψj and that degree(ψj) = degree(p)−degree(φ)−1 ≥

Page 20: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

1420 JEAN-DANIEL BOISSONNAT AND FRANCO P. PREPARATA

3− 1− 1 = 1. Since pj = φψj and degree(φ), degree(ψj) ≥ 1, pj is reducible,another contradiction.

This completes the proof of the theorem.The calculation of coefficients pi, pj corresponds to taking formal derivatives of p

with respect to xi,xj . Notice that a derivation reduces the degree by 1. The reader mayverify, by explicit and not very enlightening calculations, that the following schedulesof derivations lead to irreducible 2 × 2 determinants. The indices conform with thenotation of section 4.1.

Predicate 3: Apply Theorem 8.1 to the pair (x1, x2).Predicate 4: Apply Theorem 8.1 first to (x2, x3) and then to (y6, y7).Predicate 4′: Apply Theorem 8.1 first to (x0, x1) and then to (x2, x3)Predicate 5: Apply Theorem 8.1 first to (x1, x2), next to (x7, x8), and finally to

(y5, y6).Acknowledgments. We are indebted to H. Bronnimann for having pointed out

an error in a previous version of this paper and to O. Devillers for discussions that leadto Lemma 4.3. S. Pion, M. Teillaud, and M. Yvinec are also gratefully acknowledgedfor their comments on this work. Special thanks are due to two anonymous referees,whose insightful comments have significantly contributed to the quality of the paper.

REFERENCES

[ABD+97] F. Avnaim, J.-D. Boissonnat, O. Devillers, F. Preparata, and M. Yvinec, Eval-uating signs of determinants using single-precision arithmetic, Algorithmica, 17(1997), pp. 111–132.

[Bal95] I. J. Balaban, An optimal algorithm for finding segment intersections, in Proceedingsof the 11th Annual ACM Symposium on Computational Geometry, Vancouver,Canada, 1995, pp. 211–219.

[BO79] J. L. Bentley and T. A. Ottmann, Algorithms for reporting and counting geometricintersections, IEEE Trans. Comput., C-28 (1979), pp. 643–647.

[Boc07] M. Bocher, Introduction to Higher Algebra, Macmillan, New York, 1907.[BDS+92] J.-D. Boissonnat, O. Devillers, R. Schott, M. Teillaud, and M. Yvinec, Ap-

plications of random sampling to on-line algorithms in computational geometry,Discrete Comput. Geom., 8 (1992), pp. 51–71.

[BEPP97] H. Bronnimann, I. Emiris, V. Pan, and S. Pion, Computing exact geometric pred-icates using modular arithmetic with single precision, in Proceedings of the 13thAnnual ACM Symposium on Computational Geometry, Nice, France, 1997, pp.174–182.

[BY97] H. Bronnimann and M. Yvinec, Efficient exact evaluation of signs of determinants,in Proceedings of the 13th Annual ACM Symposium on Computational Geometry,Nice, France, 1997, pp. 166–173.

[Bro81] K. Q. Brown, Comments on “Algorithms for reporting and counting geometric inter-sections,” IEEE Trans. Comput., C-30 (1981), pp. 147–148.

[Bur96] C. Burnikel, Exact Computation of Voronoi Diagrams and Line Segment Intersec-tions, Ph.D. thesis, Universitat des Saarlandes, Saarbrucken, Germany, 1996.

[BKM+95] C. Burnikel, J. Konnemann, K. Mehlhorn, S. Naher, S. Schirra, and C. Uhrig,Exact geometric computation in LEDA, in Proceedings of the 11th Annual ACMSymposium on Computational Geometry, Vancouver, Canada, 1995, pp. C18–C19.

[BMS94] C. Burnikel, K. Mehlhorn, and S. Schirra, On degeneracy in geometric computa-tions, in Proceedings of the 5th ACM-SIAM Symposium on Discrete Algorithms,Arlington, VA, 1994, pp. 16–23.

[Cha91] B. Chazelle, Triangulating a simple polygon in linear time, Discrete Comput. Geom.,6 (1991), pp. 485–524.

[CE92] B. Chazelle and H. Edelsbrunner, An optimal algorithm for intersecting line seg-ments in the plane, J. ACM, 39 (1992), pp. 1–54.

[CEGS94] B. Chazelle, H. Edelsbrunner, L. J. Guibas, and M. Sharir, Algorithms for bichro-matic line segment problems and polyhedral terrains, Algorithmica, 11 (1994), pp.116–132.

Page 21: AND - Brown Universitycs.brown.edu/research/pubs/pdfs/2000/Boissonnat-2000-RPS.pdf · ROBUSTPLANESWEEPFORINTERSECTINGSEGMENTS∗ JEAN-DANIEL BOISSONNAT† AND FRANCO P. PREPARATA‡

ROBUST PLANE SWEEP FOR INTERSECTING SEGMENTS 1421

[Cla92] K. L. Clarkson, Safe and effective determinant evaluation, in Proceedings of the 33rdAnnual IEEE Symposium on Foundations of Computer Science, IEEE ComputerSociety, Los Alamitos, CA, 1992, pp. 387–395.

[CS89] K. L. Clarkson and P. W. Shor, Applications of random sampling in computationalgeometry, II. Discrete Comput. Geom., 4 (1989), pp. 387–421.

[EG89] H. Edelsbrunner and L. J. Guibas, Topologically sweeping an arrangement, J.Comput. System Sci., 38 (1989), pp. 165–194. Corrigendum in 42 (1991), pp.249–251.

[For85] A. R. Forrest, Computational geometry in practice, in Fundamental Algorithms forComputer Graphics, NATO Adv. Sci. Inst. Ser. F Comput. Systems Sci. 17, R. A.Earnshaw, ed., Springer-Verlag, Berlin, 1985, pp. 707–724.

[For87] A. R. Forrest, Computational geometry and software engineering: Towards a ge-ometric computing environment, in Techniques for Computer Graphics, D. F.Rogers and R. A. Earnshaw, eds., Springer-Verlag, Berlin, 1987, pp. 23–37.

[For93] S. Fortune, Progress in computational geometry, in Directions in ComputationalGeometry, R. Martin, ed., Information Geometers, Winchester, UK, 1993, pp.81–128.

[FV93] S. Fortune and C. J. Van Wyk, Efficient exact arithmetic for computational ge-ometry, in Proceedings of the 9th Annual ACM Symposium on ComputationalGeometry, San Diego, CA, 1993, pp. 163–172.

[Gol91] D. Goldberg, What every computer scientist should know about floating-point arith-metic, ACM Comput. Surv., 23 (1991), pp. 5–48.

[GS87] L. J. Guibas and R. Seidel, Computing convolutions by reciprocal search, DiscreteComput. Geom., 2 (1987), pp. 175–193.

[HS90] J. Hershberger and S. Suri, Applications of a semi-dynamic convex hull algorithm,In Proceedings of the 2nd Scandinavian Workshop on Algorithm Theory (Bergen,1990), Lecture Notes Comput. Sci. 447, Springer-Verlag, Berlin, 1990, pp. 380–392.

[HS96] J. Hershberger and S. Suri, Off-line maintenance of planar configurations, J.Algorithms, 21 (1996), pp. 453–475.

[Hob93] J. Hobby, Practical Segment Intersection with Finite Precision Output, TechnicalReport 93/2-27, Bell Laboratories, Murray Hill, NJ, 1993.

[Hof89] C. M. Hoffmann, The problems of accuracy and robustness in geometric computation,IEEE Computer, 22 (1989), pp. 31–41.

[HHK89] C. M. Hoffmann, J. E. Hopcroft, and M. T. Karasick, Robust set operations onpolyhedral solids, IEEE Comput. Graph. Appl., 9 (1989), pp. 50–59.

[LPT96] G. Liotta, F. P. Preparata, and R. Tamassia, Robust proximity queries: An il-lustration of degree-driven algorithm design, SIAM J. Comput., 28 (1999), pp.864–889.

[MS88] H. G. Mairson and J. Stolfi, Reporting and counting intersections between two setsof line segments, in Theoretical Foundations of Computer Graphics and CAD,NATO Adv. Sci. Inst. Ser. F. Comput. Systems Sci. 40, R. A. Earnshaw, ed.,Springer-Verlag, Berlin, 1988, pp. 307–325.

[Mil88] V. J. Milenkovic, Verifiable implementations of geometric algorithms using finiteprecision arithmetic, Artificial Intelligence, 37 (1988), pp. 377–401.

[Mil89] V. Milenkovic, Double precision geometry: A general technique for calculating lineand segment intersections using rounded arithmetic, in Proceedings of the 30thAnnual IEEE Symposium on Foundations Computer Science, IEEE ComputerSociety, Los Alamitos, CA, 1989, pp. 500–505.

[Mye85] E. W. Myers, An O(E logE + I) expected time algorithm for the planar segmentintersection problem, SIAM J. Comput., 14 (1985), pp. 625–637.

[NP82] J. Nievergelt and F. P. Preparata, Plane-sweep algorithms for intersecting geo-metric figures, Commun. ACM, 25 (1982), pp. 739–747.

[Pri92] D. Priest, On Properties of Floating Point Arithmetics: Numerical Stability and theCost of Accurate Computations, Ph.D. thesis, Dept. of Mathematics, Univ. ofCalifornia at Berkeley, 1992.

[Sch91] P. Schorn, Robust Algorithms in a Program Library for Geometric Computation, vol-ume 32 of Informatik-Dissertationen ETH Zurich, Verlag der Fachvereine, Zurich,Switzerland, 1991.

[She96] J. R. Shewchuk, Robust adaptive floating-point geometric predicates, in Proceedingsof the 12th Annual ACM Symposium on Computational Geometry, Philadelphia,PA, 1996, pp. 141–150.

[Yap97] C. Yap, Towards exact geometric computation, Comput. Geom., 7 (1997), pp. 3–23.