Skip to main content
Springer logoLink to Springer
. 2017 Oct 31;80(11):3253–3269. doi: 10.1007/s00453-017-0384-3

Finding Pairwise Intersections Inside a Query Range

Mark de Berg 1, Joachim Gudmundsson 2, Ali D Mehrabi 1,
PMCID: PMC6428404  PMID: 30956379

Abstract

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·polylogn) and with query time O((k+1)·polylogn) time, where k is the number of reported pairs, for two classes of objects in R2: 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 R3, we present a data structure of size O(nn·polylogn) and query time O((n+k)·polylogn). When the objects and query are fat, we obtain O((k+1)·polylogn) query time using O(n·polylogn) storage.

Keywords: Data structures, Computational geometry, Intersection searching

Introduction

The study of geometric data structures is an important subarea within computational geometry, and range searching forms one of the most widely studied topics within this area [4, 15]. In a range-searching query, the goal is to report or count all points 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 oiO should be reported (or counted) depends only on oi 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={o1,,on} of n objects in R2 or R3 such that, given a query range Q, we can efficiently report all pairs of objects oi,oj 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 R2) 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 Ω(n2) 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 R2 and the objects are axis-aligned line segments. Their data structure uses O(nlogn) storage and answers queries in time O(logn+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(nlogn) storage and has O(lognlogn+klogn) query time,1 where k is the number of reported pairs of objects. Our data structure for classes of objects with small union complexity—disks and other types of fat objects are examples—uses O(U(n)logn) storage, where U(n) is maximum union complexity of n objects from the given class, and it has O((k+1)log2n) 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(nnlogn) storage and O((n+k)log2n) query time. When the query range and the objects are fat, we improve this to O(nlog2n) storage and O((k+1)log2n) 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 (hvp) where hH, vV, and p is an endpoint of either of the segments and hvQ and dist(hv,p)δ can be reported efficiently. Their data structure needs O(nlog3n) space and is able to answer the desired queries in O(log2n+#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 R2 or boxes in R3. 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.

  1. Compute a seed set O(Q)O of objects such that the following holds: for any two objects oi,oj in O such that oi and oj intersect inside Q, at least one of oi,oj is in O(Q).

  2. For each seed object oiO(Q), perform an intersection query with the range oiQ in the set O, to find all objects ojoi intersecting oi inside Q.

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)|=O(1+k), where k is the number of pairs of objects intersecting inside Q, while for the 3-dimensional case we will have |O(Q)|=O(n+k).

The Planar Case

Let O={r1,,rn} be a set of axis-aligned rectangles in R2. 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 riO we define at most ten witness segments, two for each edge of ri and two in the interior of ri, as follows—see also Fig. 1.

Fig. 1.

Fig. 1

Gray areas are intersections of other rectangles with ri black segments indicate witness segments

Let e be an edge of ri, and consider the set S(e):=ejirj, 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 ri are defined as follows. Suppose there are vertical edges (belonging to other rectangles rj) completely crossing ri from top to bottom. Then we put eri into W, where e is the rightmost such crossing edge. Similarly, we put into W the topmost horizontal edge e completely crossing ri 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 D1 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 D2 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 D3 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 D4 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. Perform a query in D1 to find all witness segments intersecting Q. For each reported witness segment, insert the corresponding rectangle into O(Q).
    2. Perform queries in D2 and D3 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).
    3. For each corner point q of Q, perform a query in D4 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 ri,rj be two rectangles in O such that (rirj)Q. Then at least one of ri,rj is put into O(Q) by the above query procedure.

Proof

Let I:=(rirj)Q. Each edge of I is either contributed by ri or rj, or by Q. Let E(I) denote the (possibly empty) set of edges of ri and rj that contribute an edge to I. We distinguish two cases, with various subcases.

Case A: At least one edge eE(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: All edges in E(I) cross Q completely. We now have several subcases.

Case B-1: |E(I)|1. Now Q contributes at least three edges to I, so at least one corner of I is a corner of Q. Hence, both ri and rj are put into O(Q) in Step 1(iii).

Case B-2: |E(I)|3. Since each edge of E(I) crosses Q completely and |E(I)|3, both V(Q) and H(Q) are non-empty. Thus at least one of ri and rj is put into O(Q) in Step 2(ii).

Case B-3: |E(I)|=2. Let e1 and e2 denote the segments in E(I). If one of e1,e2 is vertical and the other is horizontal, we can use the argument from Case B-2. It remains to handle the case where e1 and e2 have the same orientation, say vertical.

Case B-3-i: Edges e1 and e2 belong to the same rectangle, say ri, as in Fig. 2. If e1 has an endpoint, v, inside rj, then e1 has a witness sub-edge starting at v that intersects Q, so ri is put into O(Q) in Step 1(i). If rj contains a corner of Q then rj will be put into O(Q) in Step 1(iii). In the remaining case the right edge of rj crosses Q and there are vertical edges completely crossing rj (namely e1 and e2). Hence, the rightmost edge completely crossing rj, which is a witness for rj, intersects Q. Thus rj is put into O(Q) in Step 1(i).

Fig. 2.

Fig. 2

Example of Case B-3-I

Case B-3-ii: Edge e1 is an edge of ri and e2 is an edge of rj (or vice versa). Assume without loss of generality that the y-coordinate of the top endpoint of e1 is less than or equal to the y-coordinate of the top endpoint of e2. Then the top endpoint, v, of e1 must lie in rj, and so e1 has a witness sub-edge starting at v that intersects Q. Hence, ri is put into O(Q) in Step 1(i).

In the second part of the query procedure we need to report, for each rectangle ri in the seed set O(Q), the rectangles rjO intersecting riQ. Thus we store O in a data structure D5 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 R2. There is a data structure that uses O(nlogn) storage and can report, for any axis-aligned query rectangle Q, all pairs of rectangles ri,rj in O such that ri intersects rj inside Q in O((k+1)logn) time, where k denotes the number of answers.

Proof

For the data structure D1 on the set W we use the data structure developed by Edelsbrunner et al. [13], which uses O(nlogn) preprocessing time and storage, and has O(logn+#answers) query time. For data structure D2 (and, similarly, D3) we note that a vertical segment si:=xi×[yi,yi] crosses Q:=[xQ,xQ]×[yQ,yQ] if and only if the point (xi,yi,yi) lies in the range [xQ,xQ]×[-,yQ]×[yQ,]. Hence, we can use the data structure of Afshani et al. [2], which uses O(nlogn/loglogn) storage and has O(logn+#answers) query time. For data structure D4 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(logn+#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 Step 1 is O(logn+|O(Q)|)=O(logn+k).

It remains to analyze Step 2 of the query procedure, where we need to find for a given riO(Q) all rjO such that riQ intersects rj. First notice that a rectangle rj intersects a rectangle ri:=riQ if and only if (i) a corner of rj is inside ri, or (ii) a corner of ri is inside rj, or (iii) an edge of rj intersects an edge of ri. Thus D5 consists of three components: All rj satisfying (i) can be found in O(logn+#answers) time using a range tree with fractional cascading [11], which uses O(nlogn) storage. All rj 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 riO(Q)O(logn+ki), where ki denotes the number of rectangles in O that intersect ri inside Q, and so the total time for Step 2 is O((k+1)logn).

The 3-Dimensional Case

We now study the case where the set O of objects and the query range Q are axis-aligned boxes in R3. 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 oi from every pair that intersects inside Q and then we find all other objects intersecting oi inside Q.

The general case Let O:={b1,,bn} be a set of axis-aligned boxes. The pairs of boxes bi,bj intersecting inside Q come in three types: (i) bibj fully contains Q, (ii) bibj lies completely inside Q, (iii) bibj intersects a face of Q.

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 biO containing a query point in O(log2n·loglogn+#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 (i) in O(log2n·loglogn+k) time, where k is the number of such pairs, with a structure of size O(nlogn).

Remark

The query bound in Lemma 2 can be improved to O(log2n+k) at the cost of O(nlogn) 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 bibj is either a vertex of bi or bj, 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 bi 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 ef where e is a vertical edge (that is, parallel to the z-axis) and f is a horizontal face (that is, parallel to the xy-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 F1 contains the first n faces in the sorted order, the second cluster F2 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 Fi we store, besides its z-range and the set Fi itself, the following information. Let EiE be the subset of edges that intersect at least one face in Fi, and let Ei¯ denote the set of points obtained by projecting the edges in Ei onto the xy-plane. We store Ei¯ in a data structure D(Ei¯) for 2-dimensional orthogonal range reporting. Note that for a query box Q whose z-range contains the z-range of Fi we have: an edge eE intersects at least one face fFi inside Q if and only if eEi and e¯ lies in Q¯, the projection of Q onto the xy-plane.

A query with a box Q=[x1:x2]×[y1:y2]×[z1:z2] is now answered as follows. We first find the clusters Fi and Fj whose z-range contains z1 and z2, 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(Et¯). 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(nnlogεn) we can find in time O(nlogn+k) a seed set O(Q) of O(n+k) 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 bibj either have a vertex that is a vertex of bi or bj inside Q, or they have an edge-face pair intersecting inside Q. To find seed objects for the former pairs we used O(n(logn/loglogn)2) storage and O(logn+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 Fi we have a data structure D(Ei¯), namely the 2-dimensional orthogonal range reporting structure of Chazelle [7], that uses O(nlogεn) storage, giving O(nnlogεn) storage in total. Besides the O(n) boxes in the two clusters Fi and Fj, we put boxes into the seed set for the clusters Ft with i<t<j, namely when querying the data structures D(Et¯). 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 Ft corresponds to a different intersecting pair. Together with the fact that the query time in each D(Et¯) is O(logn+#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 bibj intersects a face of Q. We describe how to find the pairs such that bibj 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 1i2n, let hi be a horizontal plane containing the (in)th horizontal face. These planes partition R3 into O(n) horizontal slabs Σ0,,Σ2n+1. We call a box bO 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 xy-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 xy-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.

Lemma 4

Using a data structure of size O(nnlogn) we can find in time O(n+klogn) a seed set O(Q) of O(n) boxes plus a collection B(Q) of pairs of boxes intersecting inside Q such that, for each pair of Type (iii) boxes, either at least one of these boxes is in O(Q) or bi,bj is a pair in B(Q).

In Step 2 of our query procedure we need to report all boxes bjO intersecting a query box B:=Qbi, where biO(Q). Note that B intersects bj if (i) B contains a vertex of bj, or (ii) a vertex of B is contained in bj, or (iii) an edge e of B intersects a face of bj, or (iv) a face f of B intersects an edge of bj. We build a data structure D consisting of several components to handle all of the cases.

All rj 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 bj parallel to the xy-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 point-enclosure structures [6] on the projections onto the xy-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 xy-plane lies inside the projection of f onto the xy-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(logn) 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 xy-plane to report all faces that contain the point corresponding to the projected edge. Since the point-enclosure data structure uses O(nlogn) storage and has O(logn) query time, this component of D needs O(nlog2n) storage and a query can be answered in O(log2n+#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 xy-plane. Now a query with a face f parallel to xy-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(logn) 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 xy-plane to report all edges whose corresponding projections onto the xy-plane lie inside the queried projected range. Since this component of D needs O(nlog2n) storage and a query can be answered in only O(log2n+#answers) time we end up with the following theorem.

Theorem 2

Let O be a set of n axis-aligned boxes in R3. Then there is a data structure that uses O(nnlogn) storage and that allows us to report, for any axis-aligned query box Q, all pairs of boxes bi,bj in O such that bi intersects bj inside Q in O((n+k)log2n) time, where k denotes the number of answers.

As observed by Rahul [20] one can prove a conditional lower bound for our 3-dimensional queries by a reduction from set intersection queries. The set intersection query problem is to preprocess m sets S1,S2,,Sm of positive real numbers into a data structure that supports set intersection queries asking whether or not the sets Si and Sj are disjoint, for given query indices i and j. Davoodi et al. [9] make the following conjecture. Here O~(·) 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 O~(t) time without using the floor function, requires Ω~((N/t)2) storage, for 1tN.

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 S1,S2,,Sm be a collection of sets and let N=i=1m|Si|. We transform the sets into a set of 2N boxes in R3. We map each element zrSi into two boxes b1(i,zr) and b2(i,zr) as follows, letting M:=2m+1. We set b1(i,zr):=[2i-1,2i]×[0,M]×zr, and we set b2(i,zr):=[0,M]×[2i-1,2i]×zr. Note that the boxes of all elements of Si will have the same xy-projections. Only their z-ranges are different. See Fig. 3a for an example. In addition, notice that for zrSi and zrSj with ij the boxes b1(i,zr) and b2(j,zr) (as well as the boxes b1(j,zr) and b2(i,zr)) intersect each other at z=zr. Also, for zrSi and zrSj with zrzr none of the corresponding boxes of Si and Sj intersect each other, since they have different z-ranges. Therefore, to verify the disjointness of Si and Sj, we ask to check if there is a pair of boxes that intersect each other inside the range [2i-3/4,2i-1/4]×[2j-3/4,2j-1/4]×(-,+). See Fig. 3b for an illustration.

Fig. 3.

Fig. 3

Left figure: the two boxes at height zr (resp. zr) are the boxes b1(i,zr) and b2(i,zr) (resp. b1(i,zr),b2(i,zr)) for some integer 1im and zrSi (resp. zrSi). Right figure: the two blue boxes are the boxes b1(i,zr) and b2(i,zr) for some integer 1im and zrSi. The two red boxes are the boxes b1(j,zr) and b2(j,zr) for some integer 1jm with ji and zrSj. Either of the two red-blue intersections verifies the non-disjointness of Si and Sj (Color figure online)

The above reduction implies the following result.

Theorem 3

Suppose we have a data structure storing a set O of n axis-aligned boxes in R3 that uses s(n) storage and that can decide in t(n) time for a given query axis-aligned 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 R3. Assuming Conjecture 1, any real-RAM data structure that can decide for a given query box Q in O~(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:={c1,,cn} be a set of n cubes in R3 and let Q be the query cube. We compute a set W of witness points for each cube ci, as follows. Let e be an edge of ci, and consider the set S(e):=ejicj, 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 ci at most four witness points, namely points from S(f):=f(jicj) that are extreme in the axis-aligned directions parallel to f. For example, if f is parallel to the xy-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 D1 for 3-dimensional orthogonal range queries.

  • We store O in a data structure D2 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.

  1. Perform a query in D1 to find all witness points inside Q. For each reported witness point, insert the corresponding cube into O(Q).

  2. For each corner point q of Q, perform a query in D2 to report all cubes in O that contain q, and put them into O(Q).

The next lemma proves correctness of this procedure.

Lemma 5

Let ci,cj be two cubes in O such that (cicj)Q. Then at least one of ci,cj is put into O(Q) by the above query procedure.

Proof

Suppose cicj intersects Q, and assume without loss of generality that ci is not larger than cj. If ci or cj 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 ci and cj do not contain a corner. We have two cases.

Case A: ci does not intersect any edge of Q. Because ci and Q are cubes, this implies that ci is contained in Q or ci intersects exactly one face of Q. Assume that ci intersects the bottom face of Q; the cases where ci intersects another face and where ci is contained in Q can be handled similarly. We claim that at least one of the vertical faces of ci contributes a witness point inside Q. To see this, observe that cj will intersect at least one vertical face, f, of ci inside Q, since cj intersects ci inside Q and ci is not larger than cj. Hence, the witness point on f with maximum z-coordinate will be inside Q. Thus ci will be put into O(Q).

Case B: ci intersects one edge of Q. (If ci intersects more than one edge of Q then it would contain a corner of Q.) Assume without loss of generality that ci intersects the bottom edge of the front face of Q; see Fig. 4. Observe that if cj intersects the top face of ci then the witness point of the face with minimum x-coordinate is inside Q. Similarly, if cj intersects the back face of ci (the face parallel to the yz-plane and with minimum x-coordinate) then the witness point of the face with maximum z-coordinate is inside Q. Otherwise, as illustrated in Fig. 5, cj must have an edge e parallel to the y-axis that intersects ci inside Q, and one of the witness points on e will be inside Q—note that e lies fully inside Q because cj does not contain a corner of Q.

Fig. 4.

Fig. 4

Case B in the proof of Lemma 5; cj is not shown

Fig. 5.

Fig. 5

Cross-section of Q, ci, and cj with a plane parallel to the xz-plane. The gray area indicates Qci in the cross-section

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 biO 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 bi. 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 biO(Q) and report all bjO intersecting biQ, 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 R3 of aspect ratio at most α. Then there is a data structure that uses O(α2nlog2n) storage and that allows us to report, for any axis-aligned query box Q of aspect ratio at most α, all pairs of cubes ci,cj in O such that ci intersects cj inside Q in O(α2(k+1)log2n) time, where k denotes the number of answers.

Proof

The data structures D1 and D2 can be implemented such that they use O(n(logn/loglogn)2) storage in total, and have O(logn+#answers) and O(log2n/loglogn+#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(nlog2n) storage and have O(log2n+#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 biO.

Objects with Small Union Complexity in R2

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 constant-complexity 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)=m2O(logm) [5]).

In Step 2 of the query algorithm of the previous section, we performed a range query with oiQ for each oiO(Q). When we are dealing with arbitrary objects, this will be expensive, so we modify our query procedure.

  1. Compute a seed set O(Q)O of objects such that, for any two objects oi,oj in O intersecting inside Q, both oi and oj are in O(Q). (Contrary to before, where we only required one of oi,oj to be in the seed set.)

  2. Compute all intersecting pairs of objects in the set {oiQ:oiO(Q)} by a plane-sweep algorithm.

Next we describe how to efficiently find O(Q), which should contain all objects intersecting at least one other object inside Q, when the union complexity U(n) is small. For each object oiO we define oi:=ojO,ji(oioj) as the union of all intersections between oi and all other objects in O. See Fig. 6 for an illustration. Let |oi| denote the complexity (that is, number of vertices and edges) of oi.

Fig. 6.

Fig. 6

An illustration of the regions oi for disks. Only o1 and o3 are shown. o1 is shown in red, and o3 is shown in blue (Color figure online)

Lemma 6

i=1n|oi|=O(U(n)).

Proof

Consider the arrangement induced by the objects in O. We define the level of a vertex v in this arrangement as the number of objects from O that contain v in their interior. We claim that every vertex of any oi is a level-0 or level-1 vertex. Indeed, a level-k vertex for k>1 is in the interior of more than one object, which implies it cannot be a vertex of any oi.

Since the level-0 vertices are exactly the vertices of the union of O, the total number of level-0 vertices is U(n). It follows from the Clarkson–Shor technique [8] that the number of level-1 vertices is O(U(n)) as well. The lemma now follows, because each level-0 or level-1 vertex contributes to at most two different oi’s.

Our goal in Step 1 is to find all objects oi such that oi intersects Q. To this end consider the connected components of oi. If oi intersects Q then one of these components lies completely inside Q or an edge of Q intersects oi.

Lemma 7

We can find all oi that have a component completely inside Q in O(logn+k) time, where k is the number of pairs of objects that intersect inside Q, with a data structure that uses O(U(n)logn) storage.

Proof

For each oi, take an arbitrary representative point inside each component of oi, 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)logn) storage.

The query time is O(logn+t), where t is the number of representative points inside Q. This implies the query time is O(logn+k), because if oi has ti representative points inside Q then oi intersects Ω(ti) other objects inside Q. This is true because the objects have constant complexity, so a single object oj cannot generate more than a constant number of components of oi.

Next we describe a data structure for reporting all oi 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 ν and let O(ν) denote the set of objects corresponding to the leaves of T(ν). Define U(ν):=oiO(ν)oi. At node ν, we store a point-location data structure [12] on the trapezoidal map of U(ν). (If the objects are curved, then the “trapezoids” may have curved top and bottom edges.)

Lemma 8

The tree T uses O(U(n)logn) storage and allows us to report all oi intersecting a vertical edge s of Q in O((t+1)log2n) time, where t is the number of answers.

Proof

To report all oi 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 oi 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(logn) time for the decision. Since we visit O(tlogn) 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(logn). 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 oi, for some oi 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)).

Lemma 9

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 oi, for some oi in O(ν).

Proof

Define O(ν):={oi:oiO(ν)}. Any vertex u of U(ν) that is not a vertex of some oiO(ν) must be an intersection of the boundaries of some oi,ojO(ν). Note that the boundary oi of an object oi consists of two types of pieces: regular arcs, which are parts of the boundary of oi itself, and irregular arcs, which are parts of the boundary of some other object ok. To bound the number of vertices of U(ν) of the form oioj 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 okO(ν)), or a level-1 vertex of that arrangement (when u is contained in a single object okO(ν)). Note that u cannot be contained in two objects from O(ν), because then u would be in the interior of some okO(ν), contradicting that u is a vertex of U(ν). See Fig. 7a.

Fig. 7.

Fig. 7

Different cases in the proof of Lemma 9. To simplify the presentation we assumed the objects are disks. oi and oj are surrounded by dark green and dark red, respectively. Regular arcs are in solid and irregular arcs are in dashed. The blue vertex refers to vertex u in the proof. a Case A in the Proof of Lemma 9. b Case B in the Proof of Lemma 9 (Color figure online)

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 oi and an irregular arc of oj. Note that this implies that u lies in the interior of oj. If there is no other object okO containing u then u would be a vertex of oj, and if there is at least one object okO containing u then u would not lie on oj. So, under the assumption that u is not already a vertex of oj, 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 oi and oj. But then u should also be in the interior of oi and oj, so this case cannot happen.

Putting everything together we obtain the following result.

Theorem 6

Let O be a set of n constant-complexity objects in R2 from a class of objects such that the maximum union complexity of any m objects from the class is U(m). Then there is a data structure that uses O(U(n)logn) storage and that allows us to report for any axis-aligned query rectangle Q, in O((k+1)log2n) time all pairs of objects oi,oj in O such that oi intersects oj inside Q, where k denotes the number of answers.

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)·polylogn) query time with O(nnlogn) storage. (We can reduce the query time to O((k+m)·polylogn), for any 1mn, but at the cost of increasing the storage to O((n2/m)·polylogn).)

Two settings where we have not been able to obtain efficient solutions are when the objects are balls in R3, and when they are arbitrary segments in R2. 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(logn+k).

Acknowledgements

M. de Berg and A. D. Mehrabi were supported by the Netherlands Organization for Scientific Research (NWO) under Grants 024.002.003 and 612.001.118, respectively. J. Gudmundsson was supported by the Australian Research Council (Project Nos. FT100100755 and DP150101134). The authors also thank the anonymous reviewers for useful comments.

Footnotes

1

Here logn denotes the iterated logarithm.

Contributor Information

Mark de Berg, Email: mdberg@win.tue.nl.

Joachim Gudmundsson, Email: joachim.gudmundsson@gmail.com.

Ali D. Mehrabi, Email: amehrabi@win.tue.nl

References

  • 1.Abam M, Carmi P, Farshi M, Smid M. On the power of semi-separated pair decomposition. Comput. Geom. 2013;46:631–639. doi: 10.1016/j.comgeo.2013.02.003. [DOI] [Google Scholar]
  • 2.Afshani, P., Arge, L., Larsen, K.D.: Orthogonal range reporting in three and higher dimensions. In: Proceedings of IEEE Symposium, pp. 149–158 (2009)
  • 3.Afshani, P., Arge, L., Larsen, K.D.: Orthogonal range reporting: query lower bounds, optimal structures in 3-d, and higher-dimensional improvements. In: Proceedings of ACM Symposium on Computational Geometry, pp. 240–246 (2010)
  • 4.Agarwal PK, Erickson J. Geometric range searching and its relatives. Contemp. Math. 1999;223:1–56. doi: 10.1090/conm/223/03131. [DOI] [Google Scholar]
  • 5.Aronov B, de Berg M, Ezra E, Sharir M. Improved bounds for the union of locally fat objects in the plane. SIAM J. Comput. 2014;43(2):543–572. doi: 10.1137/120891241. [DOI] [Google Scholar]
  • 6.Chazelle B. Filtering search: a new approach to query-answering. SIAM J. Comput. 1986;15(3):703–724. doi: 10.1137/0215051. [DOI] [Google Scholar]
  • 7.Chazelle B. A functional approach to data structures and its use in multidimensional searching. SIAM J. Comput. 1988;17:427–462. doi: 10.1137/0217026. [DOI] [Google Scholar]
  • 8.Clarkson KL, Shor PW. Applications of random sampling in computational geometry. II. Discrete Comput. Geom. 1989;4:387–421. doi: 10.1007/BF02187740. [DOI] [Google Scholar]
  • 9.Davoodi, P., Smid, M., van Walderveen, F.: Two-dimensional range diameter queries. In: Proceedings of Latin American Symposium on Theoretical Informatics, pp. 219-230 (2012)
  • 10.Das AS, Gupta P, Srinathan K. Data structures for extension violations in a query range. J. Math. Model. Algorithms. 2011;10(1):79–107. doi: 10.1007/s10852-010-9144-y. [DOI] [Google Scholar]
  • 11.de Berg M, Cheong O, van Kreveld M, Overmars M. Computational Geometry: Algorithms and Applications. 3. Berlin: Springer; 2008. [Google Scholar]
  • 12.Edelsbrunner H, Guibas LJ, Stolfi J. Optimal point location in a monotone subdivision. SIAM J. Comput. 1986;15:317–340. doi: 10.1137/0215023. [DOI] [Google Scholar]
  • 13.Edelsbrunner H, Overmars MH, Seidel R. Some methods of computational geometry applied to computer graphics. Comput. Vis. Graphics Image Proc. 1984;28:92–108. doi: 10.1016/0734-189X(84)90142-7. [DOI] [Google Scholar]
  • 14.Gajentaan A, Overmars MH. On a class of O(n2) problems in computational geometry. Comput. Geom. Theory Appl. 1995;5:165–185. doi: 10.1016/0925-7721(95)00022-2. [DOI] [Google Scholar]
  • 15.Goodman, J.E., O’Rourke, J.: Range searching. In: Handbook of Discrete and Computational Geometry, Chapter 36, 2nd edn (2004)
  • 16.Gupta P. Range-aggregate query problems involving geometric aggregation operations. Nord. J. Comput. 2006;13(4):294–308. [Google Scholar]
  • 17.Gupta P, Janardan R, Kumar Y, Smid M. Data structures for range-aggregate extent queries. Comput. Geom. Theory Appl. 2014;47:329–347. doi: 10.1016/j.comgeo.2009.08.001. [DOI] [Google Scholar]
  • 18.Keden K, Livne R, Pach J, Sharir M. On the union of Jordan regions and collision-free translational motion amidst polygonal obstacles. Discr. Comput. Geom. 1986;1:59–71. doi: 10.1007/BF02187683. [DOI] [Google Scholar]
  • 19.Rahul, S.: Improved bounds for orthogonal point enclosure query and point location in orthogonal subdivisions in R3. In: ACM-SIAM Symposium on Discrete Algorithms, pp. 200–211 (2015)
  • 20.Rahul, S.: Personal communication
  • 21.Rahul, S., Das, A.S., Rajan, K.S., Srinatan, K.: Range-aggregate queries involving geometric aggregation operations. In: Workshop on Algorithms and Computation, vol. 1, pp. 122–133 (2011)

Articles from Algorithmica are provided here courtesy of Springer

RESOURCES