Finding Pairwise Intersections Inside a Query Range

We study the following problem: preprocess a set O of objects into a data structure that allows us to efficiently report all pairs of objects from O that intersect inside an axis-aligned query range Q. We present data structures of size $O(n({\rm polylog} n))$ and with query time $O((k+1)({\rm polylog} n))$ time, where k is the number of reported pairs, for two classes of objects in the plane: axis-aligned rectangles and objects with small union complexity. For the 3-dimensional case where the objects and the query range are axis-aligned boxes in R^3, we present a data structures of size $O(n\sqrt{n}({\rm polylog} n))$ and query time $O((\sqrt{n}+k)({\rm polylog} n))$. When the objects and query are fat, we obtain $O((k+1)({\rm polylog} n))$ query time using $O(n({\rm polylog} n))$ storage.

from a given set O that lie inside a query range Q. The more general version, where O contains other objects than just points and the goal is to report all objects intersecting Q, is often called intersection searching and it has been studied extensively as well. A common characteristic of almost all range-searching and intersection-searching problems studied so far, is that whether an object o i ∈ O should be reported (or counted) depends only on o i and Q. In this paper we study a range-searching variant where we are interested in reporting pairs of objects that satisfy a certain criterion. In particular, we want to preprocess a set O = {o 1 , . . . , o n } of n objects in R 2 or R 3 such that, given a query range Q, we can efficiently report all pairs of objects o i , o j that intersect inside Q.
Our motivation for studying these problems is the following. Suppose we are given a collection of n discrete trajectories representing the movements of, say, people. Each trajectory is a sequence of locations (points in R 2 ) with a corresponding time stamp; for discrete trajectories the movement in between consecutive locations is not considered. The query we are interested in is: which pairs of people met inside a given rectangular query region Q? A natural way to define that two people meet is to require that they are within a given distance D from each other. When we restrict our attention to a fixed time instance, we can place a disk of radius D/2 around the location of each person and the question becomes: which pairs of disks intersect within Q? When we consider the ∞ metric, we get the same problem but now for squares instead of disks. A more general version of the query also specifies a time interval I : which pairs of people met within a region Q during time interval I ? To deal with the fact that the time stamps may not be synchronized for the different trajectories, we assume that each location is valid for some interval of time. If we then model time as the third dimension and consider distances in the ∞ metric, we get the question: which pairs of boxes (which are the product of a square around a location and a time interval) intersect with the query box Q := Q × I ?
An obvious approach to our problem is to precompute all intersections between the objects and store the intersections in a suitable intersection-searching data structure. This may give fast query times, but in the worst case any two objects intersect, so (n 2 ) is a lower bound on the storage for this approach. The main question is thus: can we achieve fast query times with a data structure that uses subquadratic (and preferably near-linear) storage in the worst case?
Rahul et al. [21] answered this question affirmatively when Q is an axis-aligned rectangle in R 2 and the objects are axis-aligned line segments. Their data structure uses O(n log n) storage and answers queries in time O(log n + k), where k is the number of answers. Our contribution is to obtain similar results for a broader class of objects than those of [21], namely axis-aligned rectangles and objects with small union complexity. For axis-aligned rectangles our data structure uses O(n log n) storage and has O(log n log * n + k log n) query time, 1 where k is the number of reported pairs of objects. Our data structure for classes of objects with small union complexitydisks and other types of fat objects are examples-uses O(U (n) log n) storage, where U (n) is maximum union complexity of n objects from the given class, and it has 1 Here log * n denotes the iterated logarithm.
O((k+1) log 2 n) query time. We also consider a 3-dimensional version of the problem, where the range Q and the objects in O are axis-aligned boxes. Here our data structure uses O(n √ n log n) storage and O(( √ n +k) log 2 n) query time. When the query range and the objects are fat, we improve this to O(n log 2 n) storage and O((k + 1) log 2 n) query time.
Related work The paper by Rahul et al. [21] mentioned above studies the same problem as we do (in a less general setting). There are a few more papers dealing with related problems. Das et al. [10] have studied the problem of preprocessing a set H of n horizontal and V of n vertical segments in the plane into a data structure such that given an axis-parallel query rectangle Q and a parameter δ, all the triples (h, v, p) where h ∈ H , v ∈ V , and p is an endpoint of either of the segments and h ∩ v ∩ Q = ∅ and dist (h ∩ v, p) δ can be reported efficiently. Their data structure needs O(n log 3 n) space and is able to answer the desired queries in O(log 2 n + #answers) time. Abam et al. [1], Gupta [16], and Gupta et al. [17] have presented data structures that return the closest pair inside a query range.

Axis-Aligned Objects
In this section we study the case where the set O is a set of n axis-aligned rectangles in R 2 or boxes in R 3 . We assume throughout the paper that the objects in O as well as the query rectangles are closed sets. Our approach for these cases is the same and uses the following two-step query process. For this approach to be efficient, O * (Q) should not contain too many objects that do not give an answer in Step 2. For the planar case we will ensure |O * (Q) where k is the number of pairs of objects intersecting inside Q, while for the 3dimensional case we will have |O * (Q)| = O( √ n + k).

The Planar Case
Let O = {r 1 , . . . , r n } be a set of axis-aligned rectangles in R 2 . The key to our approach is to be able to efficiently find the seed set O * (Q). To this end, during the preprocessing we compute a set W of axis-aligned witness segments. For each rectangle r i ∈ O we define at most ten witness segments, two for each edge of r i and two in the interior of r i , as follows-see also Fig. 1.
Let e be an edge of r i , and consider the set S(e) := e ∩ ∪ j =i r j , that is, the part of e covered by the other rectangles. The set S(e) consists of a number of sub-edges of e. If e is vertical then we add the topmost and bottommost sub-edge from S(e) (if any) to W ; if e is horizontal we add the leftmost and rightmost sub-edge to W . The two witness segments in the interior of r i are defined as follows. Suppose there are vertical edges (belonging to other rectangles r j ) completely crossing r i from top to bottom. Then we put e ∩ r i into W , where e is the rightmost such crossing edge. Similarly, we put into W the topmost horizontal edge e completely crossing r i from left to right. Our data structure to find the seed set O * (Q) now consists of the following components.
-We store the witness set W in a data structure D 1 that allows us to report the witness segments that intersect the query rectangle Q. -We store the vertical edges of the rectangles in O in a data structure D 2 that allows us to decide if the set V(Q) of edges that completely cross a query rectangle Q from top to bottom, is non-empty. The data structure should also be able to report all (rectangles corresponding to) the edges in V(Q). -We store the horizontal edges of the rectangles in O in a data structure D 3 that allows us to decide if the set H(Q) of edges that completely cross a query rectangle Q from left to right, is non-empty. -We store the set O in a data structure D 4 that allows us to report the rectangles that contain a query point q.
Step 1 of the query procedure, where we compute O * (Q), proceeds as follows. 1(i) Perform a query in D 1 to find all witness segments intersecting Q. For each reported witness segment, insert the corresponding rectangle into O * (Q). 1(ii) Perform queries in D 2 and D 3 to decide if the sets V(Q) and H(Q) are both non-empty. If so, report all rectangles corresponding to edges in V(Q) and put them into O * (Q). 1(iii) For each corner point q of Q, perform a query in D 4 to report all rectangles in O that contain q, and put them into O * (Q).
The following lemma proves the correctness of our query procedure.
Lemma 1 Let r i , r j be two rectangles in O such that (r i ∩ r j ) ∩ Q = ∅. Then at least one of r i , r j is put into O * (Q) by the above query procedure.
Proof Let I := (r i ∩ r j ) ∩ Q. Each edge of I is either contributed by r i or r j , or by Q. Let E(I ) denote the (possibly empty) set of edges of r i and r j that contribute an edge to I . We distinguish two cases, with various subcases. Case A: At least one edge e ∈ E(I ) has an endpoint, v, inside Q. Now the witness sub-edge on e closest to v must intersect Q and, hence, the corresponding rectangle will be put into O * (Q) in Step 1(i). Case B-3-i: Edges e 1 and e 2 belong to the same rectangle, say r i , as in Fig. 2. If e 1 has an endpoint, v, inside r j , then e 1 has a witness sub-edge starting at v that intersects Q, so r i is put into O * (Q) in Step 1(i). If r j contains a corner of Q then r j will be put into O * (Q) in Step 1(iii). In the remaining case the right edge of r j crosses Q and there are vertical edges completely crossing r j (namely e 1 and e 2 ). Hence, the rightmost edge completely crossing r j , which is a witness for r j , intersects Q. Thus r j is put into O * (Q) in Step 1(i).
Case B-3-ii: Edge e 1 is an edge of r i and e 2 is an edge of r j (or vice versa). Assume without loss of generality that the y-coordinate of the top endpoint of e 1 is less than or equal to the y-coordinate of the top endpoint of e 2 . Then the top endpoint, v, of e 1 must lie in r j , and so e 1 has a witness sub-edge starting at v that intersects Q. Hence, r i is put into O * (Q) in Step 1(i).
In the second part of the query procedure we need to report, for each rectangle r i in the seed set O * (Q), the rectangles r j ∈ O intersecting r i ∩ Q. Thus we store O in a data structure D 5 that can report all rectangles intersecting a query rectangle. Putting everything together we obtain the following theorem.

Theorem 1 Let O be a set of n axis-aligned rectangles in
There is a data structure that uses O(n log n) storage and can report, for any axis-aligned query rectangle Q, all pairs of rectangles r i , r j in O such that r i intersects r j inside Q in O((k + 1) log n) time, where k denotes the number of answers.
Proof For the data structure D 1 on the set W we use the data structure developed by Edelsbrunner et al. [13], which uses O(n log n) preprocessing time and storage, and has O(log n +#answers) query time. For data structure D 2 (and, similarly, D 3 ) we note that a vertical segment . Hence, we can use the data structure of Afshani et al. [2], which uses O(n log n/ log log n) storage and has O(log n + #answers) query time. For data structure D 4 we use the point-enclosure data structure developed by Chazelle [6], which uses O(n) storage and can be used to report all rectangles in O containing a query point in O(log n + #answers) time.
Note that |O * (Q)| 2k + 4 where k is the total number of reported pairs. Indeed, each rectangle in O * (Q) intersects at least one other rectangle inside Q and for every reported pair we put at most two rectangles into the seed set; the extra term "+4" is because in Step 1 (iii) we may report at most one rectangle per corner of Q that does not have an intersection inside Q. Hence, the time for It remains to analyze Step 2 of the query procedure, where we need to find for a given r i ∈ O * (Q) all r j ∈ O such that r i ∩ Q intersects r j . First notice that a rectangle r j intersects a rectangle r i := r i ∩ Q if and only if (i) a corner of r j is inside r i , or (ii) a corner of r i is inside r j , or (iii) an edge of r j intersects an edge of r i . Thus D 5 consists of three components: All r j satisfying (i) can be found in O(log n +#answers) time using a range tree with fractional cascading [11], which uses O(n log n) storage. All r j satisfying (ii) and (iii) can be found using, respectively, the data structure by Chazelle [6] and the one by Edelsbrunner et al. [13]. Thus the running time of Step 2 is r i ∈O * (Q) O(log n + k i ), where k i denotes the number of rectangles in O that intersect r i inside Q, and so the total time for Step 2 is O((k + 1) log n).

The 3-Dimensional Case
We now study the case where the set O of objects and the query range Q are axisaligned boxes in R 3 . We first present a solution for the general case, and then an improved solution for the special case where the input as well as the query are cubes. Both solutions use the same query strategy as above: we first find a seed set O * (Q) that contains at least one object o i from every pair that intersects inside Q and then we find all other objects intersecting o i inside Q. The general case Let O := {b 1 , . . . , b n } be a set of axis-aligned boxes. The pairs of boxes b i , b j intersecting inside Q come in three types: Type (i) is easy to handle without using seed sets: we simply store O in a data structure for 3-dimensional point-enclosure queries [19], which allows us to report all boxes b i ∈ O containing a query point in O(log 2 n · log log n + #answers) time. If we query this structure with a corner q of Q and report all pairs of boxes containing q then we have found all intersecting pairs of Type (i).

Lemma 2 We can find all intersecting pairs of boxes of Type
where k is the number of such pairs, with a structure of size O(n log * n).
Remark The query bound in Lemma 2 can be improved to O(log 2 n + k) at the cost of O(n log n) storage, by using the data structure of Afshani et al. [3] instead of that of Rahul [19].
For Type (ii) we proceed as follows. Note that a vertex of b i ∩ b j is either a vertex of b i or b j , or it is the intersection of an edge e of one of these two boxes and a face f of the other box. To handle the first case we create a set W of witness points, which contains for each box b i all its vertices that are contained in at least one other box. We store W in a data structure for 3-dimensional orthogonal range reporting [3]. In the query phase we then query this data structure with Q, and put all boxes corresponding to the witness vertices inside Q into the seed set O * (Q). For the second case we show next how to find the intersecting pairs e, f where e is a vertical edge (that is, parallel to the z-axis) and f is a horizontal face (that is, parallel to the x y-plane); the intersecting pairs with other orientations can be found in a similar way.
Let E be the set of vertical edges of the boxes in O and let F be the set of horizontal faces. We sort F by z-coordinate-we assume for simplicity that all z-coordinates of the faces are distinct-and partition F into O( √ n) clusters: the cluster F 1 contains the first √ n faces in the sorted order, the second cluster F 2 contains the next √ n faces, and so on. We call the range between the minimum and maximum z-coordinate in a cluster its z-range. For each cluster F i we store, besides its z-range and the set F i itself, the following information. Let E i ⊆ E be the subset of edges that intersect at least one face in F i , and let E i denote the set of points obtained by projecting the edges in E i onto the x y-plane. We store E i in a data structure D(E i ) for 2dimensional orthogonal range reporting. Note that for a query box Q whose z-range contains the z-range of F i we have: an edge e ∈ E intersects at least one face f ∈ F i inside Q if and only if e ∈ E i and e lies in Q, the projection of Q onto the x y-plane.
A query with a box Q = [x 1 : is now answered as follows. We first find the clusters F i and F j whose z-range contains z 1 and z 2 , respectively, and we put (the boxes corresponding to) the faces in these clusters into the seed set O * (Q). Next we perform, for each i < t < j, a query with the projected range Q in the data structure D(E t ). For each of the reported points e we put the box corresponding to the edge e into the seed set O * (Q). Finally, we remove any duplicates from the seed set. This leads to the following lemma.

Lemma 3 Using a data structure of size O(n
boxes containing at least one box from every intersecting pair of Type (ii), where k is the number of such pairs. Here ε > 0 is an arbitrary small, but fixed, positive constant.
Proof The Type (ii) intersections b i ∩ b j either have a vertex that is a vertex of b i or b j inside Q, or they have an edge-face pair intersecting inside Q. To find seed objects for the former pairs we used O(n(log n/ log log n) 2 ) storage and O(log n + k) query time [3], and we put O(k) boxes into the seed set. For the latter pairs, we used an approach based on clusters. For each cluster F i we have a data structure D(E i ), namely the 2-dimensional orthogonal range reporting structure of Chazelle [7], that uses O(n log ε n) storage, giving O(n √ n log ε n) storage in total. Besides the O( √ n) boxes in the two clusters F i and F j , we put boxes into the seed set for the clusters F t with i < t < j, namely when querying the data structures D(E t ). This means that the same box may be put into O * (Q) up to √ n times. (Note that these duplicates are later removed.) However, each copy we put into the seed set for some F t corresponds to a different intersecting pair. Together with the fact that the query time in each D(E t ) is O(log n + #answers) this means the total query time and size of the seed set are as claimed.
It remains to handle the Type (iii) pairs, in which b i ∩ b j intersects a face of Q. We describe how to find the pairs such that b i ∩ b j intersects the bottom face of Q; the pairs intersecting the other faces can be found in a similar way.
We first sort the z-coordinates of the horizontal faces of the boxes in O. For 1 i 2 √ n, let h i be a horizontal plane containing the (i √ n)th horizontal face. These planes partition We call a box b ∈ O short at i if it has a horizontal face inside i , and we call it long if it completely crosses i . For each i , we store the short boxes in a list. We store the projections of the long boxes onto the x y-plane in a data structure D( i ) for the 2-dimensional version of the problem, namely the structure of Theorem 1.
A query with the bottom face of Q is now answered as follows. We first find the slab i containing the face. We put all short boxes of i into our seed set O * (Q). We then perform a query with Q, the projection of Q onto the x y-plane, in the data structure D( i ). For each answer we get from this 2-dimensional query-that is, each pair of projections intersecting inside Q-we directly report the corresponding pair of long boxes. (There is no need to go through the seed set for these pairs.) This leads to the following lemma for the Type (iii) pairs. In Step 2 of our query procedure we need to report all boxes b j ∈ O intersecting a query box B : contains a vertex of b j , or (ii) a vertex of B is contained in b j , or (iii) an edge e of B intersects a face of b j , or (iv) a face f of B intersects an edge of b j . We build a data structure D * consisting of several components to handle all of the cases.
All r j satisfying (i) and (ii) can be found using a 3-dimensional range reporting data structure and the 3-dimensional point-enclosure data structure of Afshani et al. [3]. Next we present the components of D * needed to deal with (iii) and (iv).
For (iii), assume e is parallel to the z-axis and consider the faces of b j parallel to the x y-plane. Then we can use a 2-level structure whose first level is a tree on the z-coordinates of the faces, and whose second-level structures are 2-dimensional pointenclosure structures [6] on the projections onto the x y-plane. Note that e intersects a face f if and only if the z-coordinate of f lies in the z-range of e, and the projection of e onto the x y-plane lies inside the projection of f onto the x y-plane. A query with an edge e is now answered as follows. We first query the first level of tree with the z-range of e to locate O(log n) canonical nodes whose union covers the set of all faces whose z-coordinates lie in the queried range. We then query the associated structures of each of the selected nodes with the projection of e onto the x y-plane to report all faces that contain the point corresponding to the projected edge. Since the point-enclosure data structure uses O(n log n) storage and has O(log n) query time, this component of D * needs O(n log 2 n) storage and a query can be answered in O(log 2 n + #answers) time.
For (iv), we build a 2-level structure whose first level is a segment tree storing all the edges of all boxes. Each node ν of the first level is then associated with a 2D range tree storing the points corresponding to projections of the edges stored at the subtree rooted at ν onto the x y-plane. Now a query with a face f parallel to x y-plane can be answered as follows. We first query the first level of the structure with the z-coordinate of f to find a collection of O(log n) canonical nodes that together contain the set of edges whose z-ranges contain the queried y-coordinate. We then query the associated structures of each of the selected nodes with the projection of f onto the x y-plane to report all edges whose corresponding projections onto the x y-plane lie inside the queried projected range. Since this component of D * needs O(n log 2 n) storage and a query can be answered in only O(log 2 n + #answers) time we end up with the following theorem.

Theorem 2 Let O be a set of n axis-aligned boxes in R 3 . Then there is a data structure that uses O(n √ n log n) storage and that allows us to report, for any axis-aligned query box Q, all pairs of boxes
where k denotes the number of answers.
As observed by Rahul [20] one can prove a conditional lower bound for our 3dimensional queries by a reduction from set intersection queries. The set intersection query problem is to preprocess m sets S 1 , S 2 , . . . , S m of positive real numbers into a data structure that supports set intersection queries asking whether or not the sets S i and S j are disjoint, for given query indices i and j. Davoodi et al. [9] make the following conjecture. HereÕ(·) and˜ (·) hide polylog-factors.

Conjecture 1 Given a collection of m sets of N real numbers in total, where the maximum cardinality of the sets in polylogarithmic in m, any real-RAM data structure that supports set intersection queries inÕ(t) time without using the floor function, requires˜ ((N /t) 2 ) storage, for 1 t N .
Davoodi et al. [9] use this conjecture for a conditional lower bound for diameter queries. As observed by Rahul [20], we can also use it to prove a conditional lower bound for our problem, as described next.
Let S 1 , S 2 , . . . , S m be a collection of sets and let N = m i=1 |S i |. We transform the sets into a set of 2N boxes in R 3 . We map each element z r ∈ S i into two boxes b 1 (i, z r ) and b 2 (i, z r ) as follows, letting M := 2m+1.  Fig. 3a for an example. In addition, notice that for z r ∈ S i and z r ∈ S j with i = j the boxes b 1 (i, z r ) and b 2 ( j, z r ) (as well as the boxes b 1 ( j, z r ) and b 2 (i, z r )) intersect each other at z = z r . Also, for z r ∈ S i and z r ∈ S j with z r = z r none of the corresponding boxes of S i and S j intersect each other, since they have different z-ranges. Therefore, to verify the disjointness of S i and S j , we ask to check if there is a pair of boxes that intersect each other inside the range [2i − 3/4, 2i − 1/4] × [2 j − 3/4, 2 j − 1/4] × (−∞, +∞). See Fig. 3b for an illustration.
The above reduction implies the following result.  1 (i, z r ) and b 2 (i, z r ) (resp. b 1 (i, z r ), b 2 (i, z r )) for some integer 1 i m and z r ∈ S i (resp. z r ∈ S i ). Right figure: the two blue boxes are the boxes b 1 (i, z r ) and b 2 (i, z r ) for some integer 1 i m and z r ∈ S i . The two red boxes are the boxes b 1 ( j, z r ) and b 2 ( j, z r ) for some integer 1 j m with j = i and z r ∈ S j . Either of the two red-blue intersections verifies the non-disjointness of S i and S j (Color figure online)

Theorem 3 Suppose we have a data structure storing a set O of n axis-aligned boxes in R 3 that uses s(n) storage and that can decide in t (n) time for a given query axisaligned box Q if there is a pair of boxes from O that intersect inside Q. Then we can build a data structure of size s(2N ) supporting set intersection queries in t (2N ) time, for input sets containing N elements in total.
Now Theorem 3 along with Conjecture 1 imply the following result.

Theorem 4 Let O be a set of n axis-aligned boxes in R 3 . Assuming Conjecture 1, any real-RAM data structure that can decide for a given query box Q inÕ(t) time, and without using the floor function, if there is a pair of boxes from O that intersect inside Q, requires˜ ((n/t) 2 ) storage.
Fat boxes Next we obtain better bounds when the boxes in O and the query box Q are fat, that is, when their aspect ratio-the ratio between the length of the longest edge and the length of the shortest edge-is bounded by a constant α. First we consider the case of cubes.
Let O := {c 1 , . . . , c n } be a set of n cubes in R 3 and let Q be the query cube. We compute a set W of witness points for each cube c i , as follows. Let e be an edge of c i , and consider the set S(e) := e ∩ ∪ j =i c j , that is, the part of e covered by the other cubes. We put the two extreme points from S(e)-in other words, the two points closest to the endpoints of e-into W . Similarly, we assign each face f of c i at most four witness points, namely points from S( f ) := f ∩ (∪ j =i c j ) that are extreme in the axis-aligned directions parallel to f . For example, if f is parallel to the x y-plane, then we take points of maximum and minimum x-coordinate in S( f ) and points of maximum and minimum y-coordinate in S( f ) as witnesses. Our data structure to find the seed set O * (Q) now consists of the following components.
-We store the set W of witness points in a data structure D 1 for 3-dimensional orthogonal range queries.
-We store O in a data structure D 2 that allows us to report the set of cubes that contain a query point q.
The first step of the query procedure, where we compute O * (Q), now proceeds as follows. Proof Suppose c i ∩ c j intersects Q, and assume without loss of generality that c i is not larger than c j . If c i or c j contains a corner q of Q then the corresponding cube will be put into the seed set when we perform a point-enclosure query with q, so assume c i and c j do not contain a corner. We have two cases. Case A: c i does not intersect any edge of Q. Because c i and Q are cubes, this implies that c i is contained in Q or c i intersects exactly one face of Q. Assume that c i intersects the bottom face of Q; the cases where c i intersects another face and where c i is contained in Q can be handled similarly. We claim that at least one of the vertical faces of c i contributes a witness point inside Q. To see this, observe that c j will intersect at least one vertical face, f , of c i inside Q, since c j intersects c i inside Q and c i is not larger than c j . Hence, the witness point on f with maximum z-coordinate will be inside Q. Thus c i will be put into O * (Q).   y-axis that intersects c i inside Q, and one of the witness points on e will be inside Q-note that e lies fully inside Q because c j does not contain a corner of Q.

1(i) Perform a query in
To handle fat boxes, we need the following observation.

Observation 1 Let b be a box of aspect ratio α. Then we can cover b by O(α 2 ) cubes such that any cube in the covering intersects at most three other cubes from the covering.
To adapt the above solution to boxes of aspect ratio at most α, we cover each box b i ∈ O by O(α 2 ) cubes, and preprocess the resulting collection O of cubes as described above, making sure we do not introduce witness points for pairs of cubes used in the covering of the same box b i . To perform a query, we cover Q by O(α 2 ) query cubes and compute a seed set for each query cube. We take the union of these seed sets, replace the cubes from O in the seed set by the corresponding boxes in O, and filter out duplicates. This gives us our seed set O * (Q) for the second phase of the query procedure.
In the second phase we take each b i ∈ O * (Q) and report all b j ∈ O intersecting b i ∩ Q, using the data structure D * described just before Theorem 2. We obtain the following theorem.

Theorem 5 Let O be a set of n axis-aligned boxes in R 3 of aspect ratio at most α.
Then there is a data structure that uses O(α 2 n log 2 n) storage and that allows us to report, for any axis-aligned query box Q of aspect ratio at most α, all pairs of cubes c i , c j in O such that c i intersects c j inside Q in O(α 2 (k + 1) log 2 n) time, where k denotes the number of answers.
Proof The data structures D 1 and D 2 can be implemented such that they use O(n(log n/ log log n) 2 ) storage in total, and have O(log n + #answers) and O(log 2 n/ log log n + #answers) query time, respectively [3]. Since Step 2 of the query procedure is the same as the second step of query procedure of Sect. 2.2 we can use the data structures that we designed there, which need O(n log 2 n) storage and have O(log 2 n + #answers) query time. The conversion of boxes of aspect ratio α to cubes give an additional factor O(α 2 ). Each input box now has O(α 2 ) witness points, but each witness point will be reported by at most three of the query cubes, by Observation 1. Similarly, each corner of a query cube is inside at most two cubes from the covering of any box b i ∈ O.

Objects with Small Union Complexity in R 2
In the previous section we presented efficient solutions for the case where O consists of axis-aligned rectangles. In this section we obtain results for classes of constantcomplexity objects (which may have curved boundaries) with small union complexity. More precisely, we need that U (n), the maximum union complexity of any set of n objects from the class, is small. This is for instance the case for disks (where U (m) = O(m) [18]) and for locally fat objects (where U (m) = m2 O(log * m) [5]). In Step 2 of the query algorithm of the previous section, we performed a range query with o i ∩ Q for each o i ∈ O * (Q). When we are dealing with arbitrary objects, this will be expensive, so we modify our query procedure.

Lemma 7 We can find all o * i that have a component completely inside Q in O(log n + k) time, where k is the number of pairs of objects that intersect inside Q, with a data structure that uses O(U (n) log n) storage.
Proof For each o i , take an arbitrary representative point inside each component of o * i , and store all the representative points in a structure for orthogonal range reporting. By Lemma 6 we store O(U (n)) points, and so the structure for orthogonal range reporting uses O(U (n) log n) storage.
The query time is O(log n + t), where t is the number of representative points inside Q. This implies the query time is O(log n+k), because if o * i has t i representative points inside Q then o i intersects (t i ) other objects inside Q. This is true because the objects have constant complexity, so a single object o j cannot generate more than a constant number of components of o * i . Next we describe a data structure for reporting all o * i intersecting a vertical edge of Q; the horizontal edges of Q can be handled similarly. The data structure is a balanced binary tree T , whose leaves are in one-to-one correspondence to the objects in O. For an (internal or leaf) node ν in T , let T (ν) denote the subtree rooted at Proof To report all o * i intersecting s we walk down T , only visiting the nodes ν such that s intersects U(ν). This way we end up in the leaves corresponding to the o * i intersecting s. To decide if we have to visit a child ν of an already visited node, we do a point location with both endpoints of s in the trapezoidal map of U(ν). Now s intersects U(ν) if and only if one of these endpoints lies in a trapezoid inside U(ν) and/or the two endpoints lie in different trapezoids. Thus we spend O(log n) time for the decision. Since we visit O(t log n) nodes, the total query time is as claimed.
To analyze the storage we claim that the sum of the complexities of U(ν) over all nodes ν at any fixed height of T is O (U (n)). The bound on the storage then follows because the point-location data structures take linear space [12] and the height of T is O(log n). It remains to prove the claim. Consider a node ν at a given height h in T . Lemma 9 argues that each vertex in U(ν) is either a level-0 or level-1 vertex of the arrangement induced by the objects in O(ν), or a vertex of o * i , for some o i in O(ν). The proof of the claim then follows from the following two facts. First, the number of vertices of the former type is O(U (|O(ν)|)), which sums to O(U (n)) over all nodes at height h. Second, by Lemma 6 the number of vertices of the latter type over all nodes at height h sums to O(U (n)). i ∩ ∂o * j we now distinguish three cases. Case A: Intersections between two regular arcs. In this case u is either a level-0 vertex of the arrangement defined by O(ν) (namely when u is contained in no other object o k ∈ O(ν)), or a level-1 vertex of that arrangement (when u is contained in a single object o k ∈ O(ν)). Note that u cannot be contained in two objects from O(ν), because then u would be in the interior of some o * k ∈ O * (ν), contradicting that u is a vertex of U(ν). See Fig. 7a. Case B: Intersections between a regular arc and an irregular arc. Without loss of generality, assume that u is the intersection of a regular arc of ∂o * i and an irregular arc of ∂o * j . Note that this implies that u lies in the interior of o j . If there is no other object o k ∈ O containing u then u would be a vertex of o * j , and if there is at least one object o k ∈ O containing u then u would not lie on ∂o * j . So, under the assumption that u is not already a vertex of o * j , Case B does not happen. See Fig. 7b. Case C: Intersections between two irregular arcs. In this case u lies in the interior of both o i and o j . But then u should also be in the interior of o * i and o * j , so this case cannot happen.

Lemma 9 Each vertex in
Putting everything together we obtain the following result.

Discussion
We presented data structures for finding intersecting pairs of objects inside a query rectangle. An obvious open problem is whether our bounds can be improved. In particular, one would hope that better solutions are possible for 3-dimensional boxes, where we obtained O((k + √ n) · polylog n) query time with O(n √ n log n) storage. (We can reduce the query time to O((k + m) · polylog n), for any 1 m √ n, but at the cost of increasing the storage to O((n 2 /m) · polylog n).) Two settings where we have not been able to obtain efficient solutions are when the objects are balls in R 3 , and when they are arbitrary segments in R 2 . Especially the latter case is challenging. Indeed, suppose O consists of n/2 horizontal lines and n/2 lines of slope 1. Suppose furthermore that the query is a vertical line and that we only want to check if contains at least one intersection. A data structure for this can be used to solve the following 3Sum-hard problem: given three sets of parallel lines, decide if there is a triple intersection [14]. Thus it is unlikely that we can obtain a solution with sublinear query time and subquadratic preprocessing time. However, storage is not the same as preprocessing time. This raises the following question: is it possible to obtain sublinear query time with subquadratic storage? Another interesting question would be to see whether or not the query time in Theorem 1 can be improved to O(log n + k).