On Ray Shooting for Triangles in 3-Space and Related Problems
OOn Ray Shooting for Triangles in 3-Space and RelatedProblems ∗ Esther Ezra † Micha Sharir ‡ February 16, 2021
Abstract
We consider several problems that involve lines in three dimensions, and presentimproved algorithms for solving them. The problems include (i) ray shooting amidtriangles in R , (ii) reporting intersections between query lines (segments, or rays) andinput triangles, as well as approximately counting the number of such intersections,(iii) computing the intersection of two nonconvex polyhedra, (iv) detecting, counting,or reporting intersections in a set of lines in R , and (v) output-sensitive constructionof an arrangement of triangles in three dimensions.Our approach is based on the polynomial partitioning technique.For example, our ray-shooting algorithm processes a set of n triangles in R into adata structure for answering ray shooting queries amid the given triangles, which uses O ( n / ε ) storage and preprocessing, and answers a query in O ( n / ε ) time, for any ε >
0. This is a significant improvement over known results, obtained more than 25years ago, in which, with this amount of storage, the query time bound is roughly n / .The algorithms for the other problems have similar performance bounds, with similarimprovements over previous results.We also derive a nontrivial improved tradeoff between storage and query time. Usingit, we obtain algorithms that answer m queries on n objects inmax (cid:110) O ( m / n / ε + n ε ) , O ( m / ε n / + m ε ) (cid:111) time, for any ε >
0, again an improvement over the earlier bounds.
Keywords:
Ray shooting, Three dimensions, Polynomial partitioning, Tradeoff ∗ Work by Esther Ezra has been partially supported by NSF CAREER under grant CCF:AF-1553354 andby Grant 824/17 from the Israel Science Foundation. Work by Micha Sharir has been partially supported byISF Grant 260/18, by grant 1367/2016 from the German-Israeli Science Foundation (GIF), and by BlavatnikResearch Fund in Computer Science at Tel Aviv University. A preliminary version of this work appears inthe proceedings of the 37th Symposium on Computational Geometry. † School of Computer Science, Bar Ilan University, Ramat Gan, Israel; [email protected],https://orcid.org/0000-0001-8133-1335 ‡ School of Computer Science, Tel Aviv University, Tel Aviv Israel; [email protected],http://orcid.org/0000-0002-2541-3763 a r X i v : . [ c s . C G ] F e b Introduction
In this paper we consider several algorithmic problems that involve, explicitly or implicitly,a finite set of lines in three dimensions. The main problems that we consider are: (i)
Ray shooting amid triangles in three dimensions.
We have a set T of n triangles in R , and our goal is to preprocess T into a data structure that supports efficient ray-shooting queries, each of which specifies a ray ρ and asks for the first triangle of T that is hit by ρ , if such a triangle exists. (ii) Intersection reporting, emptiness, and approximate counting queries amid triangles inthree dimensions.
For a set T of n triangles in R , we want to preprocess T into adata structure that supports efficient intersection reporting (resp., emptiness) queries,each of which specifies a line, ray, or segment ρ and asks for reporting the triangles of T that ρ intersects (resp., determining whether such a triangle exists). We want thequeries to be output-sensitive, so that their cost is a small (sublinear) overhead plus aterm that is nearly linear in the output size k . In the related problem of approximatecounting queries, we want to preprocess T into a data structure, such that given aquery ρ as above, it efficiently computes the number of triangles of T that ρ intersects,up to some prescribed small relative error. (iii) Compute the intersection of two nonconvex polyhedra. The complexity of the inter-section can be quadratic in the complexities of the input polyhedra, and we thereforeseek an output-sensitive solution, where the running time is a small (subquadratic)overhead plus a term that is nearly linear in k , where k is the complexity of theintersection. (iv) Detect, count, or report intersections in a set of lines in 3-space. Again, in the reportingversion we seek an output-sensitive solution, as above. (v)
Output-sensitive construction of an arrangement of triangles in three dimensions.All these problems, or variants thereof, have been considered in several works duringthe 1990s; see [5, 7, 11, 12, 16, 29, 32] for a sample of these works. See also Pellegrini [33]for a recent comprehensive survey of the state of the art in this area.Pellegrini [32] presents solutions to some of these problems, including efficient datastructures (albeit less efficient than ours) for the ray-shooting problem, and also (a) anoutput-sensitive algorithm for computing the intersection of two nonconvex polyhedra intime O ( n / ε + k log k ), for any ε >
0, where n is the number of vertices, edges, and facetsof the two polyhedra and k is the (similarly defined) complexity of their intersection; (b)an output-sensitive algorithm for constructing an arrangement of n triangles in 3-space in O ( n / ε + k log k ) time, where k is the output size; and (c) an algorithm that, in O ( n / ε )expected time, counts all pairs of intersecting lines, in a set of n lines in 3-space. Background.
Algorithmic problems that involve lines in three dimensions have beenstudied for more than 30 years, covering the problems mentioned above and several oth-ers. An early study by McKenna and O’Rourke [30] has developed some of the tools andtechniques for tackling these problems. Various techniques for ray shooting, and for the2elated problems of computing and verifying depth orders and hidden surface removal havebeen studied in de Berg’s dissertation [11], and later by de Berg et al. [12]. Another workthat developed some of the infrastructure for these problems is by Chazelle et al. [16], whopresented several combinatorial and algorithmic results for problems involving lines in 3-space. Agarwal and Matouˇsek [5] reduced ray shooting problems, via parametric search,to segment emptiness problems (where the query is a segment and we want to determinewhether it intersects any input object), and obtained efficient solutions via this reduction.See also [29] and [7] for studies of some additional and special cases of the ray shootingproblem.Most of the works cited above suffer from the ‘curse’ of the four-dimensionality of (theparametric representation of) lines in space, which leads to algorithms whose complexity isinferior to those obtained in our work. Nevertheless, there are a few instances where bettersolutions can be obtained, such as in [15, 16] and some other works.
Our results.
Using the polynomial partitioning technique of [21, 22], we derive moreefficient algorithms for the problems listed above. In our first main result, presented inSection 2, we tackle the ray-shooting problem, and construct a data structure on an inputset of n triangles, which requires O ( n / ε ) storage and preprocessing, so that a ray shootingquery can be answered in O ( n / ε ) time, for any ε >
0. We then extend the technique, inSection 3, to obtain an equally-efficient data structure for the segment-triangle intersectionreporting, emptiness, and approximate counting problems, where in the case of approximatecounting the query time bound has an additional term that is nearly linear in the outputsize.These are significant improvements over previous results, which, as already noted, havetreated the lines supporting the edges of the input triangles and the line supporting the queryray (or segment) as points or surfaces in a suitable four-dimensional parametric space (inmany of the earlier works, lines were actually represented as points on the
Klein quadric infive-dimensional projective space; see [13, 26, 33, 36]). As a result, the algorithms obtainedby these techniques were less efficient.A weakness, or rather an intriguing peculiarity, of our analysis is that it does not providea desirably sharp tradeoff between storage and query time. To make this statement moreprecise, the tradeoff that the earlier solutions provide, say for the ray shooting problem forspecificity, is that, for n input triangles and with s storage, for s varying between n and n ,a ray-shooting query takes O ( n ε /s / ) time; see, e.g., [33] (the ‘4’ in the exponent comesfrom the fact that lines in 3-space are represented as objects in four-dimensional parametricspace). Thus, with storage O ( n / ε ), which is what our solution uses, the query timebecomes about O ( n / ), considerably weaker than our bound.An ambitious, and maybe unrealistic goal would be to improve the tradeoff so that thequery time is only O ( n ε /s / ). (This does indeed coincide with the bound that our mainresult gives, as the storage that it uses is O ( n / ε ), but this coincidence only holds for thisamount of storage.) Although not achieving this goal, still, combining our technique withthe known, aforementioned ‘4-dimensional’ tradeoff, we are able to obtain an ‘in between’tradeoff, which we present in Section 4. Concretely, the tradeoff is that, with s storage, the3ost of a query is Q ( n, s ) = O (cid:16) n / ε s / (cid:17) , s = O ( n / ε ) ,O (cid:16) n / ε s / (cid:17) , s = Ω( n / ε ) . (1)Note that this tradeoff contains our bounds ( s, Q ) = (cid:0) O ( n / ε ) , O ( n / ε ) (cid:1) , as a specialcase, that at the extreme ends s = Θ( n ), s = Θ( n ), of the range of s we get Q = O ( n / ε ), Q = O ( n ε ), respectively, as in the older tradeoff, and that the new tradeoff is better for anyin-between value of s . A comparison between the two tradeoffs is illustrated in Figure 1.Our improved tradeoff applies to all the problems studied in this paper. In particular, itimplies that, in all these problems, the overall cost of processing m queries with n inputobjects, including preprocessing cost, ismax (cid:110) O ( m / n / ε + n ε ) , O ( n / m / ε + m ε ) (cid:111) , (2)for any ε >
0; for the output-sensitive problems, this bounds the total overhead cost. Thefirst (resp., second) bound dominates when n ≥ m (resp., n ≤ m ). / / / Figure 1:
The old tradeoff (green) and the new tradeoff (red). The x -axis is the storage as afunction of n , and the y -axis is the query cost. Both axes are drawn in a logarithmic scale. We then present, in Section 5, extensions of our technique for solving the other problems(iii), (iv) and (v) listed above. In all these applications, our algorithms are output-sensitivefor the reporting versions, so that the query time bound, or the full processing cost bound,contains an additional term that is nearly linear in the output size. See Section 5 for theconcrete bounds that we obtain.
Let T be a collection of n triangles in R . We fix some sufficiently large constant parameter D , and construct a partitioning polynomial f of degree O ( D ) for T , so that each of the O ( D ) connected components τ of R \ Z ( f ) (the cells of the partition) is crossed by atmost n/D triangle edges. We refer to triangles whose edge crosses τ as narrow triangles (with respect to τ ), and refer to the remaining triangles that cross τ (but none of theiredges do) as wide triangles . We denote the set of narrow (resp., wide) triangles in τ by N τ The actual query time in the older tradeoff, with maximum storage, is Q = O (log n ). W τ ). The existence of such a partitioning polynomial is implied, as a special case,by the general machinery developed in Guth [21]. An algorithm for constructing f is givenin a recent work of Agarwal et al. [2]. It runs in O ( n ) time, for any constant value of D ,where the constant of proportionality depends (polynomially) on D .For technical reasons, we want to turn any query ray into a bounded segment, and wedo it by enclosing all the triangles of T by a sufficiently large bounding box B , and byclipping any query ray to its portion within B .For each (bounded) cell τ ⊆ B of the partition, we take the set W τ of wide triangles in τ , and prepare a data structure for efficient segment-shooting queries into the triangles of W τ , by segments that are fully contained in τ . The nontrivial details of this procedure aregiven in Section 2.1. As we show there, we can construct such a structure with storage andpreprocessing O ( |W τ | / ε ) = O ( n / ε ), for any ε > D depends on ε ), and each segment-shooting query takes O ( |W τ | / ε ) = O ( n / ε ) time.The preprocessing then recurses within each such cell τ of the partition, with the set N τ of the narrow triangles in τ . The recursion terminates when the number of input trianglesbecomes smaller than the constant threshold n := O ( D ), in which case we simply outputthe list of triangles in the subproblem.A query, with a ray (now turned into a segment) ρ , emanating from a point q , is answeredas follows. We first consider the case where ρ (that is, the line containing ρ ) is not fullycontained in Z ( f ), and discuss the (simpler, albeit still involved) case where ρ ⊂ Z ( f ),later. The case where ρ (cid:54)⊂ Z ( f ) . We assume a standard model of algebraic computation, inwhich a variety of computations involving polynomials of constant degree, such as computing(some discrete representation of) the roots of such polynomials, performing comparisons andalgebraic computations (of constant degree) with these roots, and so on, can be done exactlyin time C ( δ ), where δ is the degree of the polynomial, and C ( δ ) is a constant that dependson δ ; see, e.g., [9, 10].Using this model, we first locate the cell of the partition that contains the startingendpoint q of the segment ρ , in constant time (recalling that D is a constant). One wayof doing this is to construct the cylindrical algebraic decomposition (CAD) of Z ( f ) (see[18, 34]), associate with each cell σ of the CAD the cell of R \ Z ( f ) that contains it (oran indication that σ is contained in Z ( f )), and then search with q in the CAD, coordinateby coordinate (see, e.g., [2] for more details concerning such an operation). We then find,in constant time, the t = O ( D ) points of intersection of ρ with Z ( f ), and sort them intoa sequence P := ( p , . . . , p t ) in their order along ρ ; we assume that p t ∈ ∂B , and ignorethe suffix of ρ from p t onwards. The points in P partition ρ into a sequence of segments,each of which is a connected component of the intersection of ρ with some cell. The firstsegment is e = qp , the subsequent segments are e = p p , e = p p , . . . , e t = p t − p t . Wedenote by τ i the cell containing the i -th segment, for i = 1 , . . . , t (a cell can appear severaltimes in this sequence). See Figure 2.We now process the segments e i in order. For each segment e i , let τ i denote the partitioncell that contains e i . We first perform a ray-shooting (or rather a segment-shooting) queryin the structure for W τ i with the segment e i . As already mentioned (and will be describedin Section 2.1), this step can be performed in O ( n / ε ) time, with O ( n / ε ) storage5 t B q p p Z ( f ) Figure 2:
A two-dimensional rendering of the the general structure of the ray-shooting mecha-nism. and preprocessing, for any ε >
0. We then query with e i in the substructure recursivelyconstructed for N τ i . If at least one of the two queries succeeds, i.e., outputs a point thatlies on e i , we report the point nearest to the starting point of e i , and terminate the wholequery. If both queries fail, we proceed to the next segment e i +1 and repeat this step. If themechanism fails for all the segments, we report that ρ does not hit any triangle of T . The case where ρ ⊂ Z ( f ) . We use the cylindrical algebraic decomposition (CAD) of Z ( f ) (see [18, 34]), which has already been constructed for the earlier case. One of its by-products is a stratification of Z ( f ), which is a decomposition of Z ( f ) into pairwise disjointrelatively open patches of dimensions 0, 1, and 2, called strata (each stratum is a cellof the CAD), so that each of the two-dimensional strata is xy -monotone and its relativeinterior is free of any singularities of Z ( f ), and Z ( f ) is the union of the closures of thesetwo-dimensional strata, excluding possible components of Z ( f ) of dimension at most 1,which we may ignore. We compute the intersection arcs γ ∆ := Z ( f ) ∩ ∆, for ∆ ∈ T , anddistribute each arc amid the closures of the two-dimensional strata that it traverses. Wethen project the closure of each two-dimensional stratum σ onto the xy -plane, including theportions of the arcs γ ∆ that the closure contains, and preprocess the resulting collection of O ( n ) algebraic arcs, each of degree O ( D ) = O (1), into a planar ray-shooting data structure,whose details are spelled out in Section 2.2. As we show there, we can answer a ray-shootingquery in O ( n / ε ) time, using O ( n / ε ) storage, for any ε >
0, where the constants ofproportionality depend on ε , as does the choice of D . The overall storage complexity, overall the (projected) strata of Z ( f ), is thus O ( n / ε ), and the overall query time, over allstrata met by the query ray ρ , is O ( n / ε ), for a larger constant of proportionality (thatdepends on ε ). This specific planar ray-shooting problem, amid constant-degree algebraic arcs, has not received fullattention in the past, although several algorithms have been proposed, mostly with suboptimal solutions.Consult, e.g., Table 2 in Agarwal [1]; see also [4, 27]. D when the query ray comes to lie on the zero set of thecurrent partitioning polynomial. When this happens, we solve the problem in this recursiveinstance using the (nonrecursive) procedure in Section 2.2 and terminate the (current branchof the) recursion. Another way of saying this is that the leaves of the D -recursion treerepresent either constant-size subproblems or subproblems on the zero set of the currentpartitioning polynomial, and the inner nodes represent subproblems of shooting within thepartition cells. Analysis.
The correctness of the procedure is fairly easy to establish. Denote by S ( n )the maximum storage used by the structure for a set of at most n triangles, and denoteby S ( n ) (resp., S ( n )) the maximum storage used by the auxiliary structure for a set ofat most n wide triangles in a cell of the partition, as analyzed in Section 2.1 (resp., fora set of at most n intersection arcs on Z ( f ), which we process for planar ray-shooting inSection 2.2). Then S ( n ) obeys the recurrence S ( n ) = O ( D ) S ( n ) + S ( n ) + O ( D ) S ( n/D ) , (3)for n > n , and S ( n ) = O ( n ) for n ≤ n , where n := cD , for a suitable constant c ≥
1. Weshow, in the respective Sections 2.1 and 2.2, that S ( n ) = O ( n / ε ) and S ( n ) = O ( n / ε ),for any ε >
0, where both constants of proportionality depend on D and ε , from which onecan easily show that the solution of (3) is S ( n ) = O ( n / ε ), for a slightly larger, but stillarbitrarily small ε >
0; to achieve this bound, we need to take D to be 2 Θ(1 /ε ) , as willfollow from our analysis. Regarding the bound on the preprocessing time T ( n ), we obtaina similar recurrence as in (3), namely, T ( n ) = O ( n ) + O ( D ) T ( n ) + T ( n ) + O ( D ) T ( n/D ) , where the non-recursive linear term is the time to compute the polynomial f , and T ( n ), T ( n ) are defined in an analogous manner as above, and have similar upper bounds as S ( n ), S ( n ) (see Sections 2.1 and 2.2).Similarly, denote by Q ( n ) the maximum query time for a set of at most n triangles, anddenote by Q ( n ) (resp., Q ( n )) the maximum query time in the auxiliary structure for a setof at most n wide triangles in a cell of the partition (resp., for a set of at most n intersectionarcs within Z ( f ), when the query ray lies on Z ( f )). Then Q ( n ) obeys the recurrence Q ( n ) = max (cid:8) O ( D ) Q ( n ) + O ( D ) Q ( n/D ) , Q ( n ) (cid:9) , (4)for n > n , and Q ( n ) = O ( n ) = O (1) for n ≤ n . (This reflects the observation, madeabove, that the current branch of the recursion terminates when the query ray lies on thezero set of the current partitioning polynomial.) Again, the analysis in Sections 2.1 and 2.2shows that Q ( n ) = Q ( n ) = O ( n / ε ), for any ε > D depends on ε , as above), from which one can easily show, using induction on n , that the solution of (4)is Q ( n ) = O ( n / ε ), for a slightly larger but still arbitrarily small ε > Theorem 2.1
Given a collection of n triangles in three dimensions, and a prescribed pa-rameter ε > , we can process the triangles into a data structure of size O ( n / ε ) , in time O ( n / ε ) , so that a ray shooting query amid these triangles can be answered in O ( n / ε ) time. .1 Ray shooting into wide triangles Preliminaries.
In this subsection we present and analyze our procedure for ray shootingin the set W τ of the wide triangles in a cell τ of the partition. We then present, in Section 2.2,a different approach that yields a procedure for ray shooting within Z ( f ). Both procedureshave the performance bounds stated in Theorem 2.1. The efficiency of our structuresdepends on D being a constant, since the constants of proportionality depend polynomially(and rather poorly) on D .We thus focus now on ray shooting in a set of wide triangles within a three-dimensionalcell τ of the partition. To appreciate the difficulty in solving this subproblem, we make thefollowing observation. A simple-minded approach might be to replace each wide triangle∆ ∈ W τ by the plane h ∆ supporting it. Denoting the set of these planes as H τ , we couldthen preprocess H τ for ray-shooting queries, each of which specifies a query ray ζ and asksfor the first intersection of ζ with the planes of H τ . Using standard machinery (see, e.g. [1]),this would result in an algorithm with the performance bounds that we want. However, thisapproach is problematic, since, even though ∆ is wide in τ , h ∆ could intersect τ in severalconnected components, some of which lie outside ∆. See Figure 3 for an illustration. Insuch cases, ray shooting amid the planes in H τ is not equivalent to ray shooting amid thetriangles of W τ , even for rays, or rather portions thereof, that are contained in τ . τ ∆ h ∆ ζ Figure 3:
Wide triangles cannot be replaced by their supporting planes for ray shooting within τ . Our solution is therefore more involved, and proceeds as follows.
Canonical sets of wide triangles.
Consider first, for exposition sake, the case wherethe starting point of the shooting segment lies on ∂τ (the terminal point always lies on ∂τ ). As we will show, for each such segment query, the set of wide triangles in W τ that itintersects can be decomposed into a small collection of precomputed “canonical” subsets,where in each canonical set the wide triangles can be treated as planes (for that particularquery segment). We show below that the overall size of these sets, over all possible segmentqueries, is O ( n / ε ), for any ε >
0. 8ctually, to prepare for the complementary case, where the starting point of the querysegment lies inside τ , we calibrate our algorithm, so that we control the storage that it uses,and consequently also the query time bound. To do so, we introduce a storage parameter s , which can range between n and n , as a second input to our procedure, and then requirethat the actual storage and preprocessing cost be both O ( s ε ), for any ε >
0. This relaxednotion of storage offers some simplification in the analysis. (We will also allow larger valuesof s when we discuss tradeoff between storage and query time, in Section 4.)For each ∆ ∈ W τ , let γ ∆ denote the intersection curve of ∆ with ∂τ . Note that γ ∆ doesnot have to be connected—it can have up to O ( D ) connected components, by Harnack’scurve theorem [24] (applied on the plane containing ∆). Note also that ∂τ does not haveto be connected, so γ ∆ can have nonempty components on different connected componentsof ∂τ , as well as several components on the same connected component of ∂τ .We construct the locus S τ of points on ∂τ that are either singular points of Z ( f ) orpoints with z -vertical tangency. Since D is constant, S τ is a curve of constant degree (byB´ezout’s theorem, its degree is O ( D )). We take a random sample R of r triangles of W τ ,where the analysis dictates that we choose r = D Θ(1 /ε ) , for the arbitrarily small prescribed ε >
0. Since we have chosen D to be 2 Θ(1 /ε ) , the actual choice of r is 2 Θ(1 /ε ) .Let Γ R = { γ ∆ | ∆ ∈ R} , and let A = A (Γ R ∪ { S τ } ) denote the arrangement of thesecurves within ∂τ , together with S τ . By construction, each face of A is xy -monotone anddoes not cross any other branch of Z ( f ) (at a singular point). We partition each face ϕ of A into pseudo-trapezoids (called trapezoids for short), using a suitably adapted versionof a two-dimensional vertical decomposition scheme. Let A ∗ denote the collection of thesetrapezoids on ∂τ . The number of trapezoids in A ∗ is proportional to the complexity of A , which is O D ( r ) = O (1) (we use the notation O D ( · ) to indicate that the constant ofproportionality depends on D , and recall that r also depends on D ).We assume that the trapezoids are relatively open. To cover all possible cases, we alsoinclude in the collection of trapezoids the relatively open subarcs of arcs in Γ R that thepartition generates, the vertical edges of the trapezoids, and the vertices of the partition,but, for exposition sake, we will only handle here the case of two-dimensional trapezoids.(The inclusion of lower-dimensional ‘trapezoids’ is simpler to handle; it does not affect theessence of the forthcoming analysis, nor does it affect the asymptotic performance bounds.)Let ψ , ψ be two distinct trapezoids of A ∗ . Let S ( ψ , ψ ) denote the collection of allsegments e such that one endpoint of e lies in ψ , the other endpoint lies in ψ , and therelative interior of e is fully contained in the open cell τ . We can parameterize such a segment e by four real parameters, so that two parameters specify the starting endpoint of e (as apoint in ψ , using, e.g., the xy -parameterization of the xy -monotone face containing ψ ),and the other two parameters similarly specify the other endpoint. (Fewer parameters areneeded when lower-dimensional trapezoids are involved.) Denote by F the corresponding (atmost) four-dimensional parametric space. Since each of τ , ψ , ψ is of constant complexity, S ( ψ , ψ ) is a semi-algebraic set in F of constant complexity. More specifically, we canwrite S ( ψ , ψ ) as an (implicitly) quantified formula of the form S ( ψ , ψ ) = { ( p , p ) | p ∈ ψ , p ∈ ψ , and p p ⊂ τ } , where p p denotes the line-segment connecting p to p . Using the singly exponentialquantifier-elimination algorithm in [10, Theorem 14.16], we can construct, in O D (1) time,9 quantifier-free semi-algebraic representation of S ( ψ , ψ ) of O D (1) complexity. Moreover,we can decompose S ( ψ , ψ ) into its connected components, in O D (1) time as well.For each segment e ∈ S ( ψ , ψ ), let T ( e ) denote the set of all wide triangles of W τ that e crosses. We have the following technical lemma. Lemma 2.2
In the above notations, each connected component C of S ( ψ , ψ ) can be as-sociated with a fixed set T C of wide triangles of W τ , none of which crosses ψ ∪ ψ , so that,for each segment e ∈ C , T C ⊆ T ( e ) , and each triangle in T ( e ) \ T C crosses either ψ or ψ . Proof.
Pick an arbitrary but fixed segment e in C , and define T C to consist of all thetriangles in T ( e ) that do not cross ψ ∪ ψ . See Figure 4 for an illustration. e ψ ψ τ e Figure 4:
The set T C (consisting of the triangles depicted as black segments), and an illustrationof the proof of Lemma 2.2. Let e be another segment in C . Since C is connected, as a set in F (recall that this isa four-dimensional parametric space representing the segments), there exists a continuouspath π in C that connects e and e (recall that each point on π represents a segment withone endpoint on ψ and the other on ψ , and π represents a continuous variation of such asegment from e to e ). Let ∆ be a triangle in T ( e ) that does not cross ψ ∪ ψ (that is,∆ ∈ T C ), and let h ∆ denote its supporting plane. As a segment e (cid:48) traverses π from e to e ,the point q ∆ ( e (cid:48) ) := e (cid:48) ∩ h ∆ is well defined and varies continuously in τ , unless e (cid:48) comes tobe contained in, or parallel to h ∆ , a situation that, as we now argue, cannot arise.In what follows, we are going to argue that the segment e (cid:48) is detached from ∆ wheneither (i) the relative interior of e (cid:48) touches the boundary of ∆ ∩ τ , which cannot happen sincethen e (cid:48) would have to (partially) exit τ and meet its boundary, contrary to the assumptionthat e (cid:48) is fully contained in τ (recall that τ is open), or (ii) ∆ ∩ τ touches an endpoint of e (cid:48) ,which again cannot happen because the endpoints of e (cid:48) lie on ψ ∪ ψ , and ∆ is assumednot to intersect ψ ∪ ψ . More formally, we argue as follows. By assumption, q ∆ ( e ) lies in∆, and, as long as q ∆ ( e (cid:48) ) is defined (i.e., e (cid:48) intersects ∆ at a unique point), q ∆ ( e (cid:48) ) cannotreach ∂ ∆ because the corresponding segment e (cid:48) is fully contained in the open cell τ and ∆is wide in τ . (We may assume that e (cid:48) does not overlap ∆, because, since ∆ is wide, that10ould mean that both endpoints of e (cid:48) lie on ∆, but then ∆ crosses both ψ and ψ , whichwe have assumed not to be the case.) We claim that q ∆ ( e (cid:48) ) must be nonempty throughoutthe motion of e (cid:48) along π , for otherwise q ∆ ( e (cid:48) ) would have to reach an endpoint of e (cid:48) , which,by definition of S ( ψ , ψ ), must lie on ψ or on ψ . But then ∆ would have to intersecteither ψ or ψ , contrary to assumption. It follows that q ∆ ( e ) also lies in ∆, so ∆ ∈ T ( e ).This establishes the first assertion of the lemma.We next need to show that each triangle in T ( e ) \ T C must cross either ψ or ψ , whichis our second assertion. Let ∆ be a triangle in T ( e ) \ T C , and assume to the contrary that ∆does not cross ψ ∪ ψ . We run the preceding argument in reverse (moving from e to e ), andobserve that, by assumption and by the same argument (and notations) as above, q ∆ ( e (cid:48) )remains inside e (cid:48) , for all intermediate segments e (cid:48) along the connecting path π , and doesnot reach ∂ ∆ ∩ τ , so ∆ ∈ T ( e ) and thus also ∆ ∈ T C (by definition of T C ), contradictingour assumption. This establishes the second assertion, and thereby completes the proof. (cid:50) Lemma 2.2 and its proof show that, for each connected component C of S ( ψ , ψ ), thecanonical set T C , of wide triangles that are crossed by all segments in C and do not cross ψ ∪ ψ , assigned to C , is unique and is independent of the choice of e . (This is becausethe sets T ( e ), for e ∈ C , differ from each other only in triangles that cross either ψ or ψ .) The collection of all these sets T C , over all connected components C , and all pairs oftrapezoids ( ψ , ψ ), is part of the whole output collection of canonical sets over τ ; the restof this collection is constructed recursively over the trapezoids ψ of A ∗ . The algorithm.
For each trapezoid ψ of A ∗ , the conflict list K ψ of ψ is the set of all widetriangles that cross ψ . By standard random sampling arguments [14], with high probability,the size of each conflict list is O (cid:16) nr log r (cid:17) , where the constant of proportionality dependson D .Two extreme situations that require special treatment are (i) 0-dimensional trapezoids(vertices), where there is no bound on the number of triangles of W τ that can contain avertex ψ (in which case we do not recurse at ψ ), but it suffices just to maintain one of themin the structure, because if the starting (or the other) endpoint of a query segment lies at ψ , it does not matter which of these incident triangles we use. Also, we do not recurseat ψ (technically, it has no conflict list, as no triangle crosses it). (ii) triangles that fullycontain a two-dimensional trapezoid ψ , where these triangles are contained in some planarcomponent of Z ( f ) (where only the triangles that cross ψ are processed recursively). Weassume for simplicity that these triangles do not overlap one another. Since we are handlinghere rays that are not contained in Z ( f ), such a ray ρ can cross Z ( f ) at only O ( D ) = O (1)points, and it is easy to find, in O (1) time, these crossing points, and then check, in O (log n )time (with linear storage), whether any of these points belongs to a triangle contained in Z ( f ). (The case where the triangles are overlapping is also easy to handle. The performancebounds deteriorate, but are still within the overall bounds that we derive.)For every pair of trapezoids ψ , ψ , we compute S ( ψ , ψ ) and decompose it into itsconnected components. We pick some arbitrary but fixed segment e from each component C , compute the set T ( e ) of the wide triangles that cross e , and remove from it any trianglethat crosses ψ ∪ ψ , thereby obtaining the set T C . All this takes O D ( r n ) = O D ( n ) time,and the overall size of the produced canonical sets is also O D ( n ).11et s be the storage parameter associated with the problem, as defined earlier, andrecall that we require that n ≤ s ≤ n . Each canonical set T C is preprocessed into a datastructure that supports ray shooting in the set of planes H C = { h ∆ | ∆ ∈ T c } , where h ∆ is the plane supporting ∆. We construct these structures so that they use O ( s ε ) storage(and preprocessing), for any ε >
0, and a query takes O ( n polylog( n ) /s / ) time (see,e.g., [1]).We now process recursively each conflict list K ψ , over all trapezoids ψ of A ∗ . Eachrecursive subproblem uses the same parameter r , but now the storage parameter thatwe allocate to each subproblem is only s/r . We keep recursing until we reach conflictlists of size close to n /s . More precisely, after j levels of recursion, we get a total of atmost ( c r ) j = c j r j subproblems, each involving at most (cid:16) c log r r (cid:17) j n wide triangles, forsome constants c , c that depend on D , and thus on ε (specifically, c depends on c and c = O ( D ) by B´ezout’s theorem), but are considerably smaller than r , which, as alreadymentioned, we take to be D Θ(1 /ε ) .We stop the recursion at the first level j ∗ at which ( c r log r ) j ∗ ≥ s/n . As a result,we have r j ∗ ≤ s/n , and we get c j ∗ r j ∗ = O ( s /n − ε ) subproblems, for any ε >
0, wherethe choice of D (and therefore also of c , c and r ) depends, as above, on ε . Each of thesesubproblems involves at most (cid:18) c log r r (cid:19) j ∗ n = (cid:18) ( c log r ) c r log r (cid:19) j ∗ n ≤ ( c log r ) j ∗ · n s = n ε s triangles, for any ε >
0. For this estimate to hold, we choose D = 2 Θ(1 /ε ) . Hence the overallsize of the inputs, as well as of the canonical sets, at all the subproblems throughout therecursion, is O (cid:18) s n − ε (cid:19) · n ε s = O ( sn ε ) = O ( s ε ), for a slightly larger ε > e arenot necessarily pairwise disjoint. This is because the sets K ψ and K ψ are not necessarilydisjoint (they are disjoint of T C , though). This does not pose a problem for ray shootingqueries, but will be problematic for counting queries ; see Section 3.At the bottom of the recursion, each subproblem contains at most n ε /s wide triangles,which we merely store in the structure. As just calculated, the overall storage that thisrequires is O ( s ε ), for a slightly larger ε , as above. We obtain the following recurrence forthe overall storage S ( N W , s W ) for the structure constructed on N W wide triangles, where s W denotes the storage parameter allocated to the structure (at the root N W = n , s W = s ). S ( N W , s W ) = (cid:40) O D ( r s εW ) + c r S (cid:16) c N W log r r , s W r (cid:17) for N W ≥ n ε /s , O ( N W ) for N W < n ε /s. (cid:41) (The overhead term is actually O D ( r N W + r s εW ), but the second term dominates.)Throughout the recursion we have N W ≤ s W ≤ N W . Indeed, starting with n and s , after j recursive levels we have N W ≤ (cid:16) c log r r (cid:17) j n and s W = s/r j . Hence the right inequalitycontinues to hold (for s ≤ n ), and the left inequality holds as long as (cid:16) c log r r (cid:17) j n ≤ s/r j ,or ( c r log r ) j ≤ s/n , which indeed holds up to the terminal level j ∗ , by construction.12nfolding the first recurrence up to the terminal level j ∗ , where N W < n ε /s , the sumof the nonrecursive overhead terms O D ( r s εW ), over all nodes at a fixed level j , is c j r j · O (cid:32) s εW r j (1+ ε )0 (cid:33) = O (cid:32) c j r jε s εW (cid:33) = O (cid:0) s εW (cid:1) , by the choice of r . Hence, starting the recurrence at ( N W , s w ) = ( n, s ), the overall contri-bution of the overhead terms (over the logarithmically many levels) is O ( s ε ), for a slightlylarger ε . At the bottom of recurrence, we have, as already noted, O ( s /n − ε ) subproblems,each with at most O ( n ε /s ) triangles, so the sum of the terms N W at the bottom of re-currence is also O ( s ε ). In other words, the overall storage used by the data structure is O ( s ε ). Using similar considerations, one can show that the overall preprocessing time is O ( s ε ) as well, since the time obeys essentially the same recurrence. Answering a query.
To perform a query with a segment e that starts at a point a (thatlies anywhere inside τ ), we extend e from a backwards, find the first intersection point a (cid:48) of the resulting backward ray with ∂τ , and denote by e (cid:48) the segment that starts at a (cid:48) andcontains e . See Figure 5 for an illustration. This takes O D (1) time. This step is vacuouswhen e starts on ∂τ , in which case we have e (cid:48) = e . τ eaa (cid:48) e (cid:48) Figure 5:
Segment shooting from inside the cell τ : Extending the segment backwards and theresulting canonical set of triangles. We find the pair of trapezoids ψ , ψ that contain the endpoints of e (cid:48) , find the connectedcomponent C ⊆ S ( ψ , ψ ) that contains e (cid:48) , and retrieve the canonical set T C . We thenperform segment shooting along e from a in the structure constructed for H C , and thencontinue recursively in the subproblems for K ψ and K ψ . We output the triangle that e hits at a point nearest to a , or, if no such point is produced, report that e does not hit anywide triangle inside τ . In case both endpoints of e (cid:48) lie in the same trapezoid ψ (that is, ψ = ψ ), we set T C to be empty at this step (it is easy to verify that this indeed must bethe case), and then continue processing e (cid:48) (and thus e ) in the recursion on K ψ .The correctness of the procedure follows from the fact that e (cid:48) intersects all the trianglesof T C , and thus replacing these triangles by their supporting planes cannot produce any13ew (false) intersection of any of these triangles with e , and any other wide triangle that e hits must belong to K ψ ∪ K ψ .The query time Q ( N W , s W ) satisfies the recurrence Q ( N W , s W ) = O D (1) + O (cid:18) N W polylog( N W ) s / W (cid:19) + 2 Q (cid:16) c N W log r r , s W r (cid:17) for N W ≥ n ε /s , O ( N W ) for N W < n ε /s. Unfolding the first recurrence, we see that when we pass from some recursive level to thenext one, we get two descendant subproblems from each recursive instance, and the term N W polylog( N W ) /s / W is replaced in each of them by the (upper bound) term c N W log r r (cid:16) s W r (cid:17) / · polylog( N W ) = c log r r / · N W polylog( N W ) s / W . Hence the overall bound for the nonrecursive overhead terms in the unfolding, starting from( N W , s W ) = ( n, s ), is at most O (cid:88) j ≥ (cid:32) c log r r / (cid:33) j · n polylog( n ) s / = O (cid:18) n polylog( n ) s / (cid:19) , provided that r is sufficiently large. Adding the cost at the 2 j ∗ subproblems at the bottomlevel j ∗ of the recursion, where the cost of each subproblem is at most n ε /s , gives anoverall bound for the query time of Q ( n, s ) = O (cid:18) n polylog( n ) s / + n ε s (cid:19) . (5)Starting with s = n / , the query time is O ( n / ε ). We thus obtain Proposition 2.3
For a (bounded) cell τ of the polynomial partition, and a set W of n widetriangles in τ , one can construct a data structure of size and preprocessing cost O ( n / ε ) ,so that a segment-shooting query within τ , from any starting point, can be answered in O ( n / ε ) time, for any ε > . The case where the query ray is contained in Z ( f ) is discussed in detail in the followingSection 2.2, culminating in Proposition 2.7, with the same performance bounds. Thus,combined with the results in this subsection, Theorem 2.1 follows. Z ( f ) We now consider the case where the (line supporting the) query ray is contained in thezero set Z ( f ) of f . We present our result in a more general form, in which we are givena collection Γ of n constant-degree algebraic arcs in the plane, and preprocess it into adata structure of O ( n / ε ) size, which can be constructed in O ( n / ε ) time, that supportsray-shooting queries in time O ( n / ε ) per query, for any ε > Recall that we project each stratum of Z ( f ) onto the xy -plane. ay shooting amid arcs in the plane. Let Γ be a set of n algebraic arcs of constantdegree in the plane. We may assume, after breaking each arc into a constant numberof subarcs, if needed, that each arc is x -monotone, has a smooth relative interior, andis either convex or concave. For concreteness, and with no loss of generality, we assumein what follows that all the arcs of Γ are convex. That is, the tangent directions turncounterclockwise along each arc as we traverse it from left to right.We present the solution in four steps. We first discuss the problem of detecting anintersection between a query line and the input arcs. We then extend this machinery todetecting intersection with a query ray, and finally to detecting intersection with a querysegment. Once we have such a procedure, we can use the parametric-search technique ofAgarwal and Matouˇsek [5] (this is our fourth step) to perform ray shooting, with similarperformance bounds. The reason for this gradual presentation of the technique is that eachstep uses the structure from the previous step as a substructure.We remind the reader, again, that the problem of ray shooting in the plane amid ageneral collection of constant-degree algebraic arcs, which is the problem considered in thissection, does not seem to have a solution with sharp performance bounds; see Table 2 in [1]and [4, 27]. Our approach is to transform the line-intersection problem to a planar point-location prob-lem, by mapping the lines to points and the arcs γ ∈ Γ to semi-algebraic sets (whose com-plexity depends on the complexity of γ ). Our mapping is based on quantifier elimination ,and proceeds as follows. Fix an arc γ ∈ Γ, and recall that it is a constant-degree algebraic arc in the plane, and,by assumption, γ is convex, smooth and x -monotone. Consider the smallest affine variety(curve) V γ that contains γ , known as the Zariski closure of γ [19], and let F ( x, y ) be thebivariate polynomial whose zero set is V . F is a polynomial of constant degree, which wedenote by d . Consider a line (cid:96) , given by the equation y := ax + b , where a, b are realcoefficients. (Vertical lines are easier to handle, and we ignore this special case in whatfollows.) Then (cid:96) intersects γ if and only if there exists x ∈ R such that ( x, ax + b ) ∈ γ . Thiscan be expressed as a quantified Boolean algebraic predicate of constant complexity (i.e.,involving a constant number of variables, and a constant number of polynomial equalitiesand inequalities of constant degrees); one of the clauses of the predicate is F ( x, ax + b ) = 0and the others restrict ( x, ax + b ) to lie in γ . Using the singly exponential quantifier-elimination algorithm in [10, Theorem 14.16] (also used earlier in Section 2.1), we canconstruct, in O d (1) time, a quantifier-free semi-algebraic set G := G γ in the ab -parametricplane, whose overall complexity is O d (1) as well, such that the quantified predicate is true ifand only if ( a, b ) ∈ G ; see, e.g., [6] for a concrete construction of such a set for the problemof intersection detection between lines and spheres in R .We have thus mapped the setting of our problem to a planar point location problemamid a collection G of n semi-algebraic regions of constant complexity. Using standard tech- There is another, more direct approach to solving this problem, which is easier to visualize but involvesseveral levels of range searching structures. The running time of this approach, which we do not detail here,is asymptotically the same as the bound that we get here. ε -cuttings (see, e.g., [17] for such constructions), one can construct, usingoverall storage and preprocessing time of O ( n / ε ), for any ε >
0, a data structure thatsupports point-location queries in the arrangement A ( G ) of these regions in time O ( n / )per query; note that the factor n ε does not appear in the query time bound, but only inthe preprocessing time bound.Briefly, to do so, we construct a (1 / √ n )-cutting of A ( G ) in O ( n / ) time. This is apartition of the plane into O ( n ) pseudo-trapezoids, each crossed by O ( n / ) boundaries ofthe regions in G (see [17]). Each pseudo-trapezoid (trapezoid for short) has a conflict list G t au of the set of regions whose boundaries cross τ , and another list G (0) τ of regions thatfully contain τ . The lists G τ are stored explcitly at the respective regions τ , as their overallsize is O ( n / ). The overall size of the lists G (0) τ is O ( n ), so we store them implicitly ina persistent data structure, based on some tour of the trapezoids of the cutting, using thefact that G (0) τ changes by only O ( n / ) regions as we pass from τ to an adjacent trapezoid τ (cid:48) (we gloss here over certain technical issues involved in the construction of such a tour).explcitly at the respective regions τ , as their overall size is O ( n / ).For the problem of detecting line intersection, it suffices to test whether the query point( a, b ) (representing a query line (cid:96) ) is contained in any of the input semi-algebraic regions.To do so, we locate ( a, b ) in the cutting. If its containing trapezoid τ has a nonempty list G (0) τ , we report that (cid:96) intersects an arc of Γ and stop. Otherwise we go over the conflictlist G τ and test explicitly whether (cid:96) interscts any of the associated arcs of Γ, in O ( n / )time. Moreover, this point-location machinery can also return a compact representationof the set of the arcs from Γ that intersect (cid:96) , as a disjoint union of O ( n / ) precomputedcanonical subsets of Γ (namely, the set G (0) τ of the trapezoid τ containing ( a, b ), and the O ( n / ) singleton sets corresponding to those regions in G τ that contain ( a, b )). This latterproperty is useful for the extensions of this procedure for detecting intersections of rays orsegments with the given arcs, described below. We next augment the data structure so that it can test whether a query ray ρ intersects anyarc in Γ. A similar, somewhat more involved approach, which is spelled out later in thissection, allows us also to test whether a query segment s intersects any arc in Γ. Using theparametric-search machinery of Agarwal and Matouˇsek [5], this latter structure allows usto answer ray shooting queries (finding the first arc of Γ hit by a query ray ρ ) with similarperformance bounds.We comment that in principle we could have simply used an extended version of thequantifier-elimination technique used in the previous subsection. However, such an exten-sion requires more parameters to represent a ray (three parameters) or a segment (fourparameters). As a consequence, the space in which we need to perform the search becomesthree- or four-dimensional, and the performance of the solution deteriorates. We thereforeuse a different, more explicit approach to these extended versions.We also comment that the analysis presented next only applies to nonvertical raysand segments. Handling vertical rays is much simpler, and amounts, with some careful We comment that we need to exploit our model of computation in which root extraction, and manipu-lations of these roots, can be performed in constant time, for univariate polynomials of constant degree. ρ be a query ray, let q be the apex of ρ , and let (cid:96) be the line supporting ρ . Weassume, without loss of generality, that ρ is directed to the right (for rays directed to theleft, a symmetric set of conditions apply). We have: Lemma 2.4
Let ρ , q = ( q x , q y ) and (cid:96) be as above. Then ρ intersects a convex x -monotonearc γ , oriented from left to right, if and only if (cid:96) intersects γ , and one of the followingconditions holds, where u and v are the left and right endpoints of γ , and where a is theslope of (cid:96) . (a) q lies to the left of u . See Figure 6(a). (b) q lies between u and v and below γ , and the tangent direction to γ at q x is smaller than a . See Figure 6(b). (c) q lies between u and v and above γ , and v lies above (cid:96) . See Figure 6(c). (a) (b) γ γρq u v qu v ρ (c) q ρu γ v Figure 6:
Scenarios where a ray ρ intersects a convex x -monotone arc γ : (a) q lies to the leftof u . (b) q lies between u and v and below γ , and the tangent direction to γ at q x is smallerthan a . (c) q lies between u and v and above γ , and v lies above (cid:96) . Proof.
The ‘only if’ part of the lemma is simple, and we only consider the ‘if’ part. Weare given that (cid:96) intersects γ . If q lies to the left of u then clearly ρ also intersects γ (this is17ase (a), where we actually have (cid:96) ∩ γ = ρ ∩ γ ), and if q lies to the right of v then clearly ρ does not intersect γ . Assume then that q lies between u and v . If q lies above γ , the rayintersects γ if and only if v lies above (cid:96) , as is easily checked, which is Case (c). If q liesbelow γ then, given that (cid:96) intersects γ , ρ intersects γ if and only if q lies to the left of theleft intersection point in (cid:96) ∩ γ , and this happens if and only if the slope of the tangent to γ at q x is smaller than the slope of (cid:96) . This is Case (b), and thus the proof is completed. (cid:50) Our data structure is constructed by taking the structure of Section 2.2.1 and augment-ing it with additional levels, in three different ways, each testing for one of the conditions(a), (b), (c) in Lemma 2.4.Testing for Condition (a) is easily done with a single additional level based on a one-dimensional search tree on the left endpoints of the arcs.Testing for Condition (b) requires three more levels. The first level is a segment treeon the x -spans of the arcs, which we search with q x , to retrieve all the arcs whose x -spancontains q x , as the disjoint union of O (log n ) canonical sets. The second level filters outthose arcs that lie above q . As in the line-intersection structure given in Section 2.2.1(except that the plane in which we perform the search is the actual xy -plane and not theparametric ab -plane), this level requires O ( n / ε ) storage and preprocessing (where n isthe size of the present canonical set), and answers a query in O ( n / ) time. In the third levelwe consider the tangent directions of the arcs of γ as partial functions of x , and constructtheir lower envelope (see [35, Corollary 6.2]). We can then test whether ( q x , a ) lies abovethe envelope in logarithmic time.Finally, testing for Condition (c) also requires three more levels, where the first twolevels are as in case (b), and the third level tests whether there is any right endpoint v ofan arc in the present canonical set that lies above (cid:96) , by constructing, in nearly linear time,the upper convex hull of the right endpoints and by testing, in logarithmic time, whether (cid:96) does not pass fully above the hull (see, e.g., [20]).It is easily verified that the overall data structure has the desired performance bounds,namely, O ( n / ε ) storage and preprocessing cost, and O ( n / ε ) query time, for any ε > Detecting segment intersection.
The same mechanism works when ρ is a segment,rather than a ray, except that the conditions for intersection with an arc of Γ are moreinvolved. To simplify the presentation, we reduce the problem to the ray-intersection de-tection problem just treated, thereby avoiding explicit enumeration of quite a few subcasesthat need to be tested.We associate with each arc γ ∈ Γ the semi-unbounded region κ = κ ( γ ) = { ( x, y ) | u x ≤ x ≤ v x and ( x, y ) lies strictly above γ } . That is, κ is bounded on the left by the upward vertical ray emanating from u , bounded onthe right by the upward vertical ray emanating from v , and bounded from below by γ ; seeFigure 7. Then we have the following extension of Lemma 2.4: Lemma 2.5
Let γ , u , v , and κ be as above. Let s be a segment, with left endpoint p =( p x , p y ) , right endpoint q = ( q x , q y ) , and slope a , and let (cid:96) be the line supporting s . Let ρ p be the ray that starts at p and contains s (so ρ p is rightward directed), and let ρ q be the ray hat starts at q and contains s (so ρ q is leftward directed). Then s intersects γ if and onlyif all the following conditions hold: (a) (cid:96) intersects γ . (b) At least one of p , q lies outside κ . (c) ρ p ∩ γ (cid:54) = ∅ and ρ q ∩ γ (cid:54) = ∅ . See Figure 7 for an illustration. γ κ γ κ (a) (b)
Figure 7:
A segment s and a convex x -monotone arc γ , where the line (cid:96) containing s intersects γ : (a) Both endpoints of s lie inside κ and therefore s is disjoint from γ , although in this case ρ p , ρ q (depicted by the dash arrows in the figure) both intersect γ . (b) Several different positionsof s , in each of which there is an endpoint of s outside κ . In this case s intersects γ if andonly if both ρ p and ρ q intersect γ (these rays are drawn for an illustration for only two of thesegments in the subfigure). Proof.
Here too, the ‘only if’ part of the lemma is simple, and we only consider the ‘if’part. Condition (a) and the convexity of γ imply that (cid:96) ∩ γ consists of one or two points.Assume first that (cid:96) ∩ γ consists of two points ξ , η . By Condition (b) at least one of p , q lies outside the (open) interval ξη . Assume, without loss of generality, that p lies outside ξη . If p lies to the right of that interval, ρ p misses γ , contradicting Condition (c). Thus p lies to the left of ξη . Then the only way in which s ∩ γ is empty is when q also lies to theleft of ξη , but then ρ q ∩ γ would be empty, again contradicting Condition (c).Assume next that (cid:96) ∩ γ consists of one point ξ . By Condition (c), p must lie to theleft of ξ and q must lie to the right of ξ , implying that s meets γ . See Figure 7(b) for anillustration. (cid:50) The description of the data structure is fairly straightforward given the criteria forintersection in Lemma 2.5. That is, we construct a multi-level data structure, where in the19rst level we test Condition (a), obtaining the set of arcs that (cid:96) intersects, as the disjointunion of canonical sets of arcs. At the next levels we test Condition (b). For an arc γ ,with endpoints u and v , a point p lies outside κ = κ ( γ ) when p lies either below γ , or tothe left of u , or to the right of v . Collecting the arcs γ that satisfy this property is easilydone using similar data structures as those described for the case of ray-intersection queries,where we first extract those arcs that lie above p and then the arcs that lie above q . Wethen use a one-dimensional search tree on the left (resp., right) endpoints of the arcs, tocollect those arcs that lie to the right of p (resp., to the left of q ). Overall this requires O ( n / ε ) storage and preprocessing and the query time is O ( n / ε ). To test for Condition(c), we build a multi-level data structure, over each final canonical set, that tests whetherConditions (a)–(c) of Lemma 2.4 are satisfied for the rightward-directed ray ρ p , and thattheir symmetric counterparts are satisfied for the leftward-directed ray ρ q .The overall performance bounds remain the same: O ( n / ε ) storage and preprocessingcost, and O ( n / ε ) query time.As noted above, the parametric-search approach in [5] yields a procedure for answeringray-shooting queries, given a procedure for answering segment-intersection queries, as wellas a parallel procedure for the same task. The preprocessing that constructs the struc-ture is performed only sequentially, as above. The query procedure, for detecting segmentintersection, is easy to parallelize, since it is essentially a multi-level tree traversal. Byallocating a processor to each node that the query visits, we can perform the traversal inparallel, in polylogarithmic parallel time. In other words, the parallel time to answer asegment-intersection detection query is O (polylog n ), using at most O ( n / ε ) processors.Integrating these bounds with [5, Theorem 2.1], we obtain that ray-shooting queries in a pla-nar collection of arcs can be answered using the same data structure for segment-intersectionqueries, where the query time for the former problem is only within a polylogarithmic factorof the time for the latter one, a factor that is hidden in our ε -notation, by slightly increasing ε . A simple modification of the segment-intersection query procedure allows us to reportan arc γ intersecting (i.e., containing) the endpoint of the query segment, when the segmentis otherwise empty. The easy details are omitted.In conclusion we have shown the following general result, which we believe to be ofindependent interest. Proposition 2.6
A collection Γ of n constant-degree algebraic arcs in the plane can bepreprocessed, in time and storage O ( n / ε ) , for any ε > , into a data structure thatsupports ray shooting queries in Γ , in O ( n / ε ) time per query. As a corollary, we thus obtain:
Proposition 2.7
For a partitioning polynomial f of sufficiently large constant degree, anda set W of n triangles, one can construct a data structure of size and preprocessing cost O ( n / ε ) , so that a segment-shooting query with a segment that lies in Z ( f ) , can be an-swered in O ( n / ε ) time, for any ε > . As already concluded, Proposition 2.7, combined with Proposition 2.3 of the previous sub-section, complete the proof of Theorem 2.1. 20
Segment-triangle intersection reporting, emptiness, andapproximate counting queries
We extend the technique presented in Section 2 to answer intersection reporting queriesamid triangles in R . Here too we have a set T of n triangles in R , and our goal is topreprocess T into a data structure that supports efficient intersection queries, each of whichspecifies a line, ray or segment ρ and asks for reporting the triangles of T that ρ intersects.In particular, this data structure also supports segment emptiness queries, in which wewant to determine whether the query segment meets any input triangle. Unfortunately,for technical reasons, the method does not extend to segment-triangle intersection (exact) counting queries, in which we want to find the (exact) number of triangles that intersecta query segment (or a line or a ray). This issue will be discussed later on in this section,and a partial solution, which supports queries that approximately count the number ofintersections, up to any prescribed relative error ε >
0, will be presented in Section 3.2.
Theorem 3.1
Given a collection of n triangles in three dimensions, and a prescribed pa-rameter ε > , we can process the triangles into a data structure of size O ( n / ε ) , in time O ( n / ε ) , so that a segment-intersection reporting (resp., emptiness) query amid these tri-angles can be answered in O ( n / ε + k log n ) (resp., O ( n / ε ) ) time, where k is the numberof triangles that the query segment crosses. Proof.
The algorithm that we develop here is a fairly easy adaptation of those given inthe previous section, which is fairly straightforward, except for one significant issue, notedbelow. The preprocessing is almost identical, except that now we preprocess the sets T C ofwide triangles for line- (ray-, or segment-)intersection reporting queries in a set of planesin R (namely, the corresponding planes in H C ); in this case the reporting query time is O (cid:18) n polylog ns / + k (cid:19) , where n is the number of wide triangles, s is the amount of storageallocated, and k is the output size; see [5, Theorem 3.3].To answer a query with a segment (ray, or line) ρ , we trace ρ through the cells andsubcells that it crosses, as before, but do not abort the search at cells where an intersectionhas been found, and instead follow the search to completion. We take each canonical set T C that the query collects, and access it via the intersection-reporting mechanism that wehave constructed for it. At the bottom level we examine all the triangles in the subproblem,and report those that are crossed by ρ .Recall that the canonical sets that we construct are not necessarily pairwise disjoint,even those that are encountered when querying with a fixed segment e . Thus, the trianglesthat we report may be reported multiple times, which we want to avoid. To this end, at eachlevel of the recursion (on the trapezoidal cells ψ ) within a single cell τ of the polynomialpartition, we take the outputs of the two recursive calls (recall the details in Section 2), andkeep only one copy of each triangle that is reported twice. (Recall that the sets of trianglesin the recursive calls are disjoint from the canonical set T C but may share triangles betweenthemselves.) Repeating this step at all levels of recursion guarantees that the reportedtriangles are all distinct. The overall cost of this overhead is O ( k log n ), where k is theoutput size. 21ote that this non-disjointness of the outputs makes it difficult to convert this procedureto one that counts the number of triangles that the query object crosses, and at the momentwe do not know how to perform intersection-counting queries with the same performancebounds. (It is also conceivable that the upper bound on the cost of a counting query islarger; see, e.g., [5] for similar phenomena.)A similar adaptation is applied for the substructure that handles queries that are con-tained in the zero set of the partitioning polynomial, and its easy details are omitted. (Infact, in this case, due to the nature of our range searching mechanism, the conflict listscomprising the answer to a single query are pairwise disjoint. Therefore in this case, we doobtain a range counting mechanism with similar asymptotic performance bounds).This completes the description of the required adaptations, and establishes Theorem 3.1. (cid:50) Let T be as above, and let δ > T intoa data structure that supports approximate counting queries of the following form: Givena query segment e , count how many triangles of T are crossed by e , up to a relative errorof 1 ± δ .To do so, we use the notion of a relative ( p, δ ) -approximation , as developed and analyzedin Har-Peled and Sharir [25]. We recall this notion and its basic properties. Consider therange space ( T, R ), where R is the collection of all subsets of T of the form T ( e ) = { ∆ ∈ T | ∆ ∩ e (cid:54) = ∅} , where e is a segment. It is easily shown that ( T, R ) has finite VC-dimension η . (A brief argument for this latter property follows by bounding the primal shatter function of the range space, as a function of | T | . This is done by representing the lines supportingthe triangle edges as surfaces in 4-space, and by observing that, for each of the O ( | T | ) cells C of their arrangement, all the lines whose Pl¨ucker images lie in C meet the same subset T C of triangles of T . For a segment e , we take the cell C containing the image of the linesupporting e , and argue that there are only polynomially many subsets of T C that can becrossed by such a segment e .)For a segment e and a subset X ⊆ T , write X ( e ) := | X ∩ e || X | ; this is the “relative size” ofthe range T ( e ) induced by e . Let 0 < p, δ < Z ⊆ T iscalled a relative ( p, δ ) -approximation if, for every segment e , we have:(1 − δ ) T ( e ) ≤ Z ( e ) ≤ (1 + δ ) T ( e ) , if T ( e ) ≥ pT ( e ) − δp ≤ Z ( e ) ≤ T ( e ) + δp, if T ( e ) ≤ p. As shown in [25], a random sample Z of T of size cδ p (cid:18) η log 1 p + log 1 q (cid:19) is a relative ( p, δ )-approximation with probability at least 1 − q , where c is some absolute constant.We use this notion as follows. Using Theorem 3.1 we construct our data structure forexact segment intersection reporting queries, with O ( n / ε ) storage and preprocessing andquery time O ( n / ε + k log n ), for any ε >
0, where k is the output size. We also construct22 relative ( p, δ )-approximation Z for T , by an appropriate random sampling mechanism,where the value of p will be determined shortly.An approximate counting query with a segment e is answered as follows. We firstquery with e in the data structure for exact segment intersection reporting, but stop theprocedure as soon as we collect more than np triangles. If the output size k does not exceedthis bound, we output k (as an exact count) and are done. The cost of the query so far is O ( n / ε + np log n ).If we detect that k > np , we compute Z ( e ) by brute force, in O ( | Z | ) time, and output thevalue k apx := nZ ( e ). By the properties of relative approximations, we have, since T ( e ) ≥ p ,(1 − δ ) k ≤ k apx ≤ (1 + δ ) k, so k apx satisfies the desired approximation property.The overall (deterministic) cost of the query is O (cid:16) n / ε + np log n + | Z | (cid:17) = O (cid:18) n / ε + np log n + 1 δ p (cid:18) η log 1 p + log 1 q (cid:19)(cid:19) . We ignore the effect of q , and balance the terms by choosing p := 1 δn / , making the querycost O (cid:32) n / ε + n / δ log n (cid:33) . As long as δ is not too small (but we can still choose δ to be 1 /n ε (cid:48) , for some ε (cid:48) < ε ), thefirst term dominates the bound, which is thus asymptotically the same as the bound forreporting queries.The storage is O (cid:0) n / ε + | Z | (cid:1) = O (cid:0) n / ε (cid:1) , as long as δ is not chosen too small.We thus conclude: Theorem 3.2
Given a collection of n triangles in three dimensions, and prescribed param-eters ε, δ > , where δ = ω (1 /n ε ) , we can process the triangles, using random sampling,into a data structure of size O ( n / ε ) , in time O ( n / ε ) , so that, for a query segment e ,the number of intersections of e with the input triangles can be approximately computed, upto a relative error of ± δ , with very high probability, in O ( n / ε ) time. In this section we extend the technique in Sections 2 and 3 to obtain a tradeoff betweenstorage (and preprocessing) and query time. A similar tradeoff holds for the other problemsstudied in Section 5.For a quick overview of our approach, consider the ray-shooting structure of Section 2,and let s be the storage parameter that we allocate to the structure, which now satisfies n ≤ s ≤ n . We modify the procedure for ray shooting inside a cell τ by (i) stopping potentiallythe r -recursion at some earlier ‘premature’ level, and (ii) modifying the structure at thebottom of recursion so that it uses the (weaker) ray-shooting technique of Pellegrini [32]23nstead of a brute-force scanning of the triangles (the current cost of O ( n /s ), a consequenceof this brute-force approach, is too expensive when s is small). A similar adaptation isapplied to the procedure of ray shooting on the zero set of the partitioning polynomial.With additional care we obtain the performance bounds (1) and (2) announced in theintroduction.We now present the technique in detail. Consider the ray-shooting structure of Section 2,and let s be the storage parameter that we allocate to the structure, which satisfies n ≤ s ≤ n . As before, we use this notation to indicate that the actual storage (and preprocessing)that the structure uses may be O ( s ε ), for any ε >
0. We comment that in the precedingsections s is assumed to be at most n . Handling larger values of s require some care,detailed below. For the time being, we continue to assume that s ≤ n , and will later showhow to extend the analysis for larger values.Consider first the subprocedure for handling ray shooting for rays that are not containedin the zero set of the partitioning polynomial. When s = O ( n / ), we run the recursivepreprocessing described in Section 2 up to some ‘premature’ level k , and when s = Ω( n / ),we run it all the way down. With a suitable choice of parameters, we obtain O ( D k + ε ) sub-problems at the bottom level of recursion, each involving at most n/D k (narrow) triangles.Except for the bottom level, we build, at each node τ of the recursion, the same structureon the set W τ of wide triangles in τ , with one (significant) difference. First, since we startthe recursion with storage parameter s , we allocate to each subproblem, at any level j , thestorage parameter s/D j , thus ensuring that the storage used by the structure is O ( s ε ).However, the cost of a query, even at the first level of recursion, given in (5), has the term O ( n ε /s ), which is the cost of a naive, brute-force processing of the conflict lists at thebottom instances of the r -recursion within the partition cells. This is fine for s = Ω( n / ε )but kills the efficiency of the procedure when s is smaller. For example, for s = n we get(near) linear query time, much more than what we aim to have. We therefore improve theperformance at the bottom-level nodes of the r -recurrence (within a cell), by constructing,for each respective conflict list, the ray-shooting data structure of Pellegrini [32], which, for N triangles and with storage parameter s , answers a query in time O ( N ε /s / ). Since atthe bottom of the r -recursion, both the number of triangles and the storage parameter are n ε /s , the cost of a query at the bottom of the recursion is O (( n /s ) / ε ). That is, themodified (improved) cost of a query at such a node is Q ( n, s ) = O (cid:32) n polylog( n ) s / + n / ε s / (cid:33) . (6)At each of the O ( D k + ε ) bottom-level cells τ , we take the set N τ of (narrow) trianglesthat have reached τ , whose size is now at most n/D k , allocate to it the storage parameter s/D k , and preprocess N τ using the aforementioned technique of Pellegrini [32], whichresults in a data structure, with storage parameter s/D k , which supports ray shootingqueries in time O (cid:18) |N τ | ε ( s/D k ) / (cid:19) = O (cid:18) ( n/D k ) ε ( s/D k ) / (cid:19) = O (cid:18) n ε s / D (5 / ε ) k (cid:19) . Multiplying this bound by the number O ( D k + ε ) of cells that the query ray crosses, the cost24f the query at the bottom-level cells is Q bot ( n, s ) = O (cid:18) n ε s / D (1 / ε ) k (cid:19) . The cost of a query at the inner recursive nodes of some depth j < k is the number, O ( D j + ε ), of j -level cells that the ray crosses, times the cost of accessing the data structurefor the wide triangles at each visited cell. Since we have allocated to each of the O ( D j + ε )cells at level j the storage parameter O ( s/D j ), the cost of accessing the structure for widetriangles in a j -level cell is, according to (6), at most Q inner ( n, s ) = O (cid:32) ( n/D j )polylog( n )( s/D j ) / + ( n/D j ) / ε ( s/D j ) / (cid:33) = O (cid:32) n polylog( n ) D j s / + n / ε D (3 / ε ) j s / (cid:33) . Summing over all j -level cells, for all j , and then adding the bottom-level cost, and the costof traversing the structure with the query segment, the overall cost of a query is (we remindthe reader that so far we only consider the case where s ≤ n ) O (cid:32) D k + ε + n / ε D k/ s / + n ε s / + n ε s / D (1 / ε ) k (cid:33) . (7)We choose k to (roughly) balance the second and the last terms; specifically, we choose D k = sn . Since D k + ε should not exceed O ( n / ε ), we require for this choice of k that s = O ( n / ε ).In this case it is easily verified that the second and last terms, which are O ( n / ε /s / ),dominate both the first and third terms (recall that we assume s ≥ n ), and the query timeis therefore O ( n / ε /s / ) . For larger values of s , that is, when s = Ω( n / ε ) (but we still assume s ≤ n ), we balancethe first term with the last term, so we choose D k = n / s / . Note that in this range we indeed have that D k + ε = O ( n / ε ). Moreover, in this case thefirst and last terms dominate the second and third terms, as is easily verified. Thereforethe query time is O ( n / ε /s / ) . As already promised, the case where the query ray lies on the current zero set will bepresented later.It remains to handle the range n < s ≤ n . Informally, at each cell τ of the polynomialpartition, at any level j of the D -recursion, we have n τ ≤ n/D j wide triangles and storageparameter s τ = s/D j . Since s ≥ n , we also have s τ ≥ n τ . With such ‘abundance’ ofstorage, we run the r -recursion until we reach subproblems of constant size, in which casewe simply store the list of wide triangles at each bottom-level node, and the query simplyinspects all of them, at a constant cost per subproblem. Hence the cost of a query at τ is25 ( n ετ /s / τ ). To be precise, this is the case as long as s τ ≤ n τ . If n ≤ s ≤ n there willbe some level j at whose cells τ s τ = s/D j becomes larger than ( n/D j ) ≥ n τ , and thenthe cost becomes O ( n ετ ). When n < s ≤ n the cost becomes O ( n ετ ) right away (and staysso). That is, the cost of a query in the structure for wide triangles at a cell τ at level j is O (cid:18) ( n/D j ) ε ( s/D j ) / (cid:19) = O (cid:18) n ε s / D j (1+2 ε ) (cid:19) for s ≤ n D j O ( n ε ) for s > n D j . Since a query visits O ( D j + ε ) cells τ at level j , the overall cost of searching amid the widetriangles, over all levels, is easily seen to be O (cid:18) n ε s / (cid:19) for n ≤ s ≤ n O (cid:16) D k n ε (cid:17) for n < s ≤ n , where k is the depth of the D -recursion.Querying amid the narrow triangles is done again as in Section 2 (once again, recallthat we now consider the case where s > n , whereas earlier in this section we assumed s ≤ n ). At each node τ at the bottom level k of the D -recursion we use Pellegrini’s datastructure [32], which, with at most n/D k narrow triangles and storage parameter s/D k ,answers a query in time O (cid:18) ( n/D k ) ε ( s/D k ) / (cid:19) = O (cid:18) n ε D (5 / ε ) k s / (cid:19) . We multiply by the number of cells that the query visits, namely O ( D k + ε ), and add thecost O ( D k + ε ) of traversing these cells, for a total of O (cid:18) D k + ε + n ε s / + n ε D (1 / ε ) k s / (cid:19) . In other words, we get the same bound as in (7), except for the second term which is missingnow (this term corresponds to querying at the bottom-level nodes of the r -recursion onthe wide triangles, which is not needed when s > n , since these bottom-level subproblemsnow have constant size). Repeating the same analysis as above, we get the same bound forthe query cost. Handling the zero set.
We next analyze the case where the query ray lies on the zero set.In order to obtain the trade-off bounds for ray shooting within Z ( f ), we recall the multi-leveldata structure presented in Section 2.2. Each level in this data structure is either a one- or atwo-dimensional search tree, where the dominating levels are those where we need to applya planar decomposition over a set of planar regions (or in an arrangement of algebraic arcs)and preprocess it into a structure that supports point-location queries. A standard propertyof multi-level range searching data structures is that the overall complexity of their storage(resp., query time) is governed by the level with dominating storage (resp., query time)bound, up to a polylogarithmic factor [3]. Recall that in each level of our data structure we26orm a collection of canonical sets of the arcs in Γ, which are passed on to the next level forfurther processing. Our approach is to keep forming these canonical sets, where at the verylast level we apply the ray-shooting data structure of Pellegrini [32], as described above.Therefore the overall query cost (resp., storage and preprocessing complexity) is the sumof the query (resp., storage and preprocessing time) bounds over all canonical sets of arcsthat the query reaches (resp., all the sets) at the last level.We now sketch the analysis in more detail. In order to simplify the presentation, weconsider one of the dominating levels, and describe the ray-shooting data structure at thatlevel. As stated above, we build this data structure only at the very last level, but theanalysis for the dominating level subsumes the bounds for the last level, and thus for theentire multi-level data structure, up to a polylogarithmic factor. In such a scenario wehave a set of algebraic arcs (or graphs of functions, or semi-algebraic regions representedby their bounding arcs), which we need to preprocess for planar point location. This isdone using the technique of (1 /r )-cuttings (see [17]), which forms a decomposition of theplane into O ( r ) pseudo-trapezoidal cells, each meeting at most n/r arcs (the “conflictlist” of the cell). The overall storage complexity is thus O ( nr ). More precisely, to achievepreprocessing time close to O ( nr ), one needs to use so-called hierarchical-cuttings (see [28]and also [8]), in which we construct a hierarchy of cuttings using a constant value r as thecutting parameter, instead of the nonconstant r . Using this approach, both storage andpreprocessing cost are O ( nr ε ) for any ε >
0. Let s be our storage parameter as above, sowe want to choose r such that s = rn . Thus we obtain that each cell of the cutting meetsat most n /s arcs. Following our approach above, for each cell of the cutting, the amountof allocated storage is s/r = n /s . We are now ready to apply Pellegrini’s data structure,leading to a query time of O (cid:16) n / ε s / (cid:17) . Integrating this bound into the query time in (7),we recall that at each level 0 ≤ j ≤ k the actual storage parameter is O ( s/D j ), and thenumber of triangles at hand is O ( n/D j ). We now need to sum the query bound over all O ( D j ) cells reached by the query at the j th level, and over all j . We thus obtain an overallbound of O (cid:32) D k ( n/D k ) / ε ( s/D k ) / (cid:33) = O (cid:32) n / ε D k/ s / (cid:33) . This is exactly the second term in (7). Therefore adding the query time for ray shootingon Z ( f ) does not increase the asymptotic bound in (7).We comment that the overall storage and preprocessing time is O ( s ε ) (see our discus-sion below). We also comment that the query bound we obtained applies when n ≤ s ≤ n .When s exceeds n , every cell of the cutting has a conflict list of O (1) elements, which thequery can handle in brute-force. This immediately brings the query time, for queries on thezero set, to O ( n ε ). Wrapping up.
In summary, our analysis implies that the query bound Q ( n, s ) satisfies: Q ( n, s ) = O (cid:16) n / ε s / (cid:17) , s = O ( n / ε ) ,O (cid:16) n / ε s / (cid:17) , s = Ω( n / ε ) . (8)We recall that the overall storage (and preprocessing) is O ( s ε ), since we allocate to eachsubproblem, at any level j , the storage parameter s/D j , thus at each fixed level the total27torage (and preprocessing) complexity is O ( s ε ), and since there are only logarithmicallymany levels, the overall storage (and preprocessing) is O ( s ε ) as well, for a slightly large ε . Note that for the threshold s ≈ n / , both bounds yield a query cost of O ( n / ε ).Note also that in the extreme cases s = n , s = n (extreme for the older ‘four-dimensional’tradeoff), we get the respective older bounds O ( n ε ) and O ( n / ε ) for the query time. Inthis case, when either s = n and s = n we have D k = O (1), implying that we handleall the narrow triangles at the root of the recursion tree, that is, we use the technique ofPellegrini [32] once altogether. Informally, the bound in (8) ‘pinches’ the tradeoff curve andpushes it down. The closer s is to Θ( n / ε ), the more significant is the improvement. SeeFigure 1. Processing m queries. The improved tradeoff in (8) implies that the overall cost ofprocessing m queries with n input triangles, including preprocessing cost, is O ( s ε + mQ ( n, s )) = O (cid:16) s ε + mn / s / (cid:17) , s = O ( n / ε ) ,O (cid:16) s ε + mn / s / (cid:17) , s = Ω( n / ε ) . To balance the terms in the first case we choose s = m / n / ; this choice satisfies s = O ( n / ε ) when m ≤ n . To balance the terms in the second case we choose s = m / n / ;this choice satisfies s = Ω( n / ε ) when m ≥ n . Recall also that s has to be in the rangebetween n and n . So in the first case we must have m / n / ≥ n , or m ≥ n / . Similarly,in the second case we must have m / n / ≤ n , or m ≤ n . We adjust the bounds, allowingalso values of m outside this range, by adding the near-linear terms, which dominate thebound for such off-range values of m . We thus get Corollary 4.1
We can process m ray-shooting queries on n triangles so that the total costis max (cid:110) O ( m / ε n / ε + n ε ) , O ( n / ε m / ε + m ε ) (cid:111) . (9) R It is more convenient, albeit not necessary, to consider the bichromatic version of the prob-lem, in which we are given a set R of n red lines and a set B of n blue lines in R , and thedetection problem asks whether there exists a pair of intersecting lines in R × B . Similarly,the counting problem asks for the number of such intersecting pairs, and the reportingproblem asks for reporting all these pairs.An algorithm that solves the detection problem in O ( n / ε ) time is easily obtainedby regarding the problem as a special degenerate (and much simpler) instance of the rayshooting problem, in which we regard the, say red lines as degenerate triangles (unboundedand of zero area), construct the data structure of Section 2 and query it with each of theblue lines. There exists a red-blue pair of intersecting lines if and only if at least one queryhas a positive outcome—the corresponding blue query line hits a red line.28ince there are no wide triangles in this special variant, there is no need to constructthe auxiliary data structure for wide triangles, as in Section 2.1, and we simply constructthe recursive hierarchy of polynomial partitions, where each cell in each subproblem isassociated with the set of red lines that cross it. A blue query line (cid:96) is propagated throughthe cells that it crosses until it reaches bottom-level cells, and we check, in each such cell,whether (cid:96) intersects any of the O (1) red lines associated with the cell.Handling lines that lie fully in the zero set Z ( f ) is also an easy task (which can beperformed using planar segment-intersection range searching, which also supports countingqueries); further details are omitted.Both correctness and runtime analysis follow easily, as special and simpler instances ofthe analysis in Section 2. Note that here we do not face the issue of non-disjointness ofcanonical sets of wide triangles, which has prevented us from extending the technique tosegment-triangle intersection counting problems; see Section 3. Let K and K be two polyhedra in 3-space, not necessarily convex, each with n edges (sothe number of vertices and faces of each of them is O ( n )). The goal is to compute theirintersection K := K ∩ K in an output-sensitive manner. We note that computing theunion K ∪ K can be done using a very similar approach, within the same time bound.While there are additional steps in the algorithm that construct a representation of K asa three-dimensional body, we will restrict here the presentation to the part that computes ∂K from ∂K and ∂K . Each face of ∂K is a connected portion of a face of ∂K or of ∂K ,each edge is either a connected portion of an edge of ∂K or of ∂K , or a connected portionof the intersection of a face of ∂K and a face of ∂K . Finally, each vertex of ∂K is eithera vertex of ∂K or of ∂K , or an intersection of an edge of one of these polyhedra with aface of the other. Note that not every vertex of K or of K is necessarily a vertex of K ,but every edge-face intersection is a vertex of K .The main step of the algorithm is to compute the vertices of ∂K , from which the otherfeatures of ∂K are fairly standard to construct, see, e.g., [32] where the graph of the edgesof K is constructed by a tracing procedure [31], given the vertices of ∂K . We iterate overthe edges of ∂K , and compute the intersections of each such edge with the faces of ∂K ,using the algorithm in Theorem 3.1. We apply a symmetric procedure to compute theintersections of each edge of ∂K with the faces of ∂K . Collectively, these intersectionsare the vertices of K of the second type (edge-face intersection vertices). The cost of thisstep is O ( n / ε + k log n ), where k is the number of edge-face intersections: we preprocessthe O ( n ) faces of, say K , and query with the O ( n ) edges of K , which overall takes O ( n · n / ε + k log n ) = O ( n / ε + k log n ) time. Then, applying the tracing procedurein [31] takes an additional cost of O ( k log k ).This gives us all the edge-face intersection vertices. The other vertices of K are verticesof K or of K , and finding these vertices is done as follows. If such a vertex v , say of K ,is incident to an edge e of K that intersects some face of K , then it is easy to determinewhether v ∈ K (and thus in K ). Otherwise, we collect, by a simple graph traversal, amaximal cluster of vertices of K that are connected by edges that have no intersectionwith ∂K . The vertices in such a cluster are either all inside K (and in K ) or all outside29 (and thus not in K ). If the cluster consists of all vertices of K then either K , K aredisjoint, or one contains the other. In such a case, we only need to test, in O ( n ) time, if thereis a vertex from one polyhedron that is contained in the other. Otherwise, we determine thestatus of the cluster (inside / outside K ) by examining the edges that connect vertices fromthe cluster to vertices not in the cluster. By iteratively repeating this step, we construct allsuch clusters, from which we obtain all the vertices of K and of K the lie in K .In summary we obtain: Corollary 5.1
Given two arbitrary polyhedra K and K each of complexity O ( n ) , theintersection K ∩ K can be computed in time O ( n / ε + k log n ) , where k is the size of theintersection. As discussed in the introduction, the overhead term in Pellegrini’s algorithm [32] is O ( n / ε ). Let T be a set of n possibly intersecting triangles in R , let A = A ( T ) denote theirarrangement, and let k denote its complexity, which, as in Section 5.2, we measure bythe number of its vertices, as the number of its other features (edges, faces, and cells) isproportional to k . The goal is to construct A in an output-sensitive manner with a small,subquadratic overhead. Pellegrini [32] gave such an algorithm that runs in O ( n / ε + k log k ), and the algorithm that we present here reduces the overhead to O ( n / ε ) time.As in the previous subsection, we focus on the main step of the algorithm that constructsthe features of A (vertices, edges, and faces) on each triangle of T . We will only brieflydiscuss the complementary part, which constructs the three-dimensional cells of A andestablishes the connections between the various features on the boundary of each cell. Albeitnot trivial, this latter step uses standard techniques, follows the approach in [32] and inother works, and does not increase the overhead cost of the algorithm.Fix a triangle ∆ ∈ T . We first construct the set of intersection segments ∆ ∩ ∆ (cid:48) , for∆ (cid:48) ∈ T \ { ∆ } . We observe that, for any such segment e = ∆ ∩ ∆ (cid:48) , each endpoint of e iseither a vertex of ∆, or an intersection of an edge of one triangle with the other triangle.We therefore take the collection of the 3 n edges of the triangles of T , and, for eachsuch edge e , apply Theorem 3.1, which reports all k e triangles that e meets. This identifiesall the intersection segments ∆ ∩ ∆ (cid:48) . We then take all the intersection segments within afixed triangle ∆, and run a sweepline procedure within ∆ to obtain the portion of A on ∆.Gluing these portions to each other, and some additional steps, complete the constructionof A . In this paper we have managed to improve the performance of ray shooting amid trianglesin three dimensions, as well as of several related problems. The improvement is based onthe polynomial partitioning technique of Guth. The improvement is most significant whenthe storage is about n / and the query takes about n / time, but one gets an improvement30or all values of the storage between n and n , except at the very ends of this range. Thisis a significant improvement, the first in nearly 30 years, in this basic problem.There are several open questions that our work raises. First, the improvement for thespecial values of O ( n / ε ) storage and O ( n / ε ) query time seems too specialized, andone would like to get similar improvements for all possible values of the storage, ideallyobtaining query time of O ( n ε /s / ), where s is the storage allocated to the structure,as in the case of ray shooting amid planes. Alternatively, can one establish a lower-boundargument that shows the limitations of our technique?Another open issue follows from our current inability to extend the technique to count-ing queries, due to the fact that the canonical sets that we collect during a query are notnecessarily pairwise disjoint. It would be interesting to obtain such an extension, or, alter-natively, to establish a gap between the performances of the counting and reporting versionsof the segment intersection query problem.Finally, could one obtain similar bounds for non-flat input objects? for shooting alongnon-straight curves? It would also be interesting to find additional applications of thegeneral technique developed in this paper. Acknowledgements.
We wish to thank Pankaj Agarwal for the useful interaction con-cerning certain aspects of the range searching problems encountered in this work.
References [1] P. K. Agarwal, Simplex range searching and its variants: A review, in
Journey throughDiscrete Mathematics: A Tribute to Jiˇr´ı Matouˇsek (M. Loebl, J. Neˇsetˇril, and R. Thomas(editors), Springer Verlag, Berlin-Heidelberg, 2017, pp. 1–30.[2] P. K. Agarwal, B. Aronov, E. Ezra and J. Zahl, An efficient algorithm for generalizedpolynomial partitioning and its applications,
Proc. Sympos. on Computational Geometry(SoCG) , 2019, 5:1–5:14. Also in arXiv:1812.10269.[3] P. K. Agarwal and J. Erickson, Geometric range searching and its relatives, in
Advancesin Discrete and Computational Geometry,
Contemp. Math. 223 (B. Chazelle, J. E. Good-man, and R. Pollack, eds.), AMS Press, Providence, RI, 1999, pp. 1–56.[4] P. K. Agarwal, M. van Kreveld, and M. Overmars, Intersection queries in curved objects,
J. Algorithms , 15 (1993), 229–266.[5] P. K. Agarwal and J. Matouˇsek, Ray shooting and parameric search,
SIAM J. Comput.
22 (1993), 794–806.[6] P. K. Agarwal and J. Matouˇsek, On range searching with semialgebraic sets,
DiscreteComput. Geom.
11 (1994), 393–418.[7] P. K. Agarwal and M. Sharir, Ray shooting amidst convex polyhedra and polyhedralterrains in three dimensions,
SIAM J. Comput.
25 (1996), 100–116.318] B. Aronov, E. Ezra and M. Sharir, Testing polynomials for vanishing on Cartesianproducts of planar point sets,
Proc. 36th Sympos. on Computational Geometry (2020),8:1–8:14. Also in arXiv:2003.09533.[9] B. Aronov, E. Ezra and J. Zahl, Constructive polynomial partitioning for algebraiccurves in R with applications, SIAM J. Comput.
49 (2020), 1109–1127. Also in
Proc.Sympos. on Discrete Algorithms (SODA) , 2019, 2636–2648. Also in arXiv:1904.09526.[10] S. Basu, R. Pollack, and M.-F. Roy,
Algorithms in Real Algebraic Geometry , Algorithmsand Computation in Mathematics 10, Springer-Verlag, Berlin, 2003.[11] M. de Berg,
Ray Shooting, Depth Orders and Hidden Surface Removal , Lecture NotesComput. Sci., 703, Springer Verlag, Berlin, 1993.[12] M. de Berg, D. Halperin, M. Overmars, J. Snoeyink, and M. van Kreveld, Efficient rayshooting and hidden surface removal,
Algorithmica , 12 (1994), 30–53.[13] O. Bottema and B. Roth,
Theoretical Kinematics , Dover, New York 1990.[14] B. Chazelle, H. Edelsbrunner, L. Guibas and M. Sharir, A singly exponential stratifi-cation scheme for real semi-algebraic varieties and its applications,
Theoretical ComputerScience
84 (1991), 77–105.[15] B. Chazelle, H. Edelsbrunner, L. Guibas and M. Sharir, Algorithms for bichromaticline segment problems and polyhedral terrains,
Algorithmica
11 (1994), 116–132.[16] B. Chazelle, H. Edelsbrunner, L. J. Guibas, M. Sharir and J. Stolfi, Lines in space:Combinatorics and algorithms,
Algorithmica
15 (1996), 428–447.[17] B. Chazelle and J. Friedman, A deterministic view of random sampling and its use ingeometry,
Combinatorica
Proc. 2nd GI Conf. Automata Theory and FormalLanguages , Springer LNCS 33, 1975.[19] D. Cox, J. Little and D. O’Shea,
Ideals, Varieties, and Algorithms: An Introduction toComputational Algebraic Geometry and Commutative Algebra , Springer Verlag, Heidel-berg, 2007.[20] D. P. Dobkin and D. G. Kirkpatrick, A linear algorithm for determining the separationof convex polyhedra,
J. Algorithms
Math. Proc. Camb. Phil. Soc.
159 (2015), 459–469. Also in arXiv:1410.8871.[22] L. Guth and N. H. Katz, On the ErdHos distinct distances problem in the plane,
AnnalsMath.
181 (2015), 155–190. Also in arXiv:1011.4105.[23] D. Halperin, M. Sharir and I. Yehuda, Throwing a sofa through the window, in prepa-ration.[24] C. G. A. Harnack, ¨Uber die Vielfaltigkeit der ebenen algebraischen Kurven,
Math. Ann.
10 (1876), 189–199. 3225] S. Har-Peled and M. Sharir, Relative ( p, (cid:15) )-approximations in geometry,
Discrete Com-put. Geom.
45 (2011), 462–496. Also in arXiv:0909.0717.[26] K. Hunt,
Kinematic Geometry of Mechanisms , Oxford 1990.[27] V. Koltun, Segment intersection searching problems in general settings
Discrete Com-put. Geom.
30 (2003), 25–44.[28] J. Matouˇsek, Range searching with efficient hierarchical cuttings,
Discrete Comput.Geom.
10 (1993), 157–182.[29] J. Matouˇsek and O. Schwarzkopf, On ray shooting in convex polytopes,
Discrete Com-put. Geom.
10 (1993), 215–232.[30] M. McKenna and J. O’Rourke, Arrangements of lines in 3-space: A data structurewith applications,
Proc. 4th ACM Sympos. Computational Geometry , 1988, pp. 371–380.[31] K. Mehlhorn and K. Simon, Intersecting two polyhedra one of which is convex, In
Proc.Fundamentals Comput. Theory , 199 (1985), 534–542.[32] M. Pellegrini, Ray shooting on triangles in 3-space,
Algorithmica handbook on Discreteand Computational Geometry (J. E. Goodman, J. O’Rourke, and C. D. T´oth, Eds.),CRC Press, Boca Raton, Florida, Third Edition, 2017, 1093–1112.[34] J.T. Schwartz and M. Sharir, On the Piano Movers’ problem: II. General techniquesfor computing topological properties of real algebraic manifolds,
Advances in Appl. Math.
Davenport-Schinzel Sequences and Their Geometric Ap-plications,
Cambridge University Press, Cambridge-New York-Melbourne, 1995.[36] J. Stolfi,