Notes 02
Notes 02
Roberto Tamassia
Computational Geometry Sem. II, 1992–1993
1
(since qµ ≤ n) = O(n log2 n). The space can be reduced to O(n log n) by noting that at each
node of T we do a one-dimensional range query for which a balanced search tree (which uses
O(n) storage with an input of size n) suffices.
2 Segment Intersection
In this section we modify the problem slightly to allow the segments in S to be arbitrarily
sloped. An important restriction is that these should not intersect each other. The query
segment is still vertical. We will see that essentially the same data structure as before solves
this problem
2
Now we have to do a range search in each of the nodes in the query path. Each such node
corresponds to a strip of the plane. Each such strip is decomposed into a set of trapezoids by
the segments stored at the corresponding node of T . Note that all these segments cross the
strip entirely. Further they do not intersect each other. Hence as we move from left to right
in the strip, the relative top-to-bottom order of the segments in that strip does not change.
We can now store these segments in a balanced search tree (the secondary data structure)
to do the range search.
Let us assume that in the balanced search tree the left child of a segment is a segment
below it in the strip and the right child is a segment above it. We search for y1 and y2 in
the balanced search tree. Reporting the segments at all the nodes between the two nodes
the two searches end in gives all the segments of S that s intersects. Suppose that during
the search for y1 , we are at a particular node of the balanced search tree. If y1 is below the
segment stored at that node, then we know that the search should proceed in the left subtree
of that node else in the right subtree. This test directs our search. Whether or not a point
is above or below a segment can be tested easily by projecting the point on the segment in
the y-direction and comparing the y-coordinates of the point and the point of projection.
3 Ray Shooting
Given a set S of horizontal segments on the plane and a query point p with coordinates (x, y)
find the first segment of S intersected by a vertical ray shooting up from p.
We can solve this problem by using a SR-tree to find all segments in S that intersect a
semi-infinite vertical line extending up from p and then determining which of these is first
intersected by the ray shooting up from p. However, this in the worst case can take O(n)
time. A better solution can be obtained by organizing the y-coordinates of the segments
stored at each node of the segment tree T (the primary data structure) in a binary search
tree. Then at each node in search path for x in T , we do a binary search for y in the binary
search tree and locate the lowest segment of S stored at that node which is above p. Thus
3
each node in the search path in T yields a possible answer. The lowest among these is the
required solution.
The correctness is clear from the above discussion. The space required is O(n log n). The
time required is O(log2 n) since a binary search is done at each of O(log n) nodes.
If s is the query rectangle and r is a rectangle in R, then the four cases can be solved (as
we have seen before) by using the SS-tree for 2-dimensional point enclosure, the RR-tree
for 2-dimensional range search, the SR-tree for orthogonal segment intersection (where the
query segment is horizontal and the other segments vertical) and the RS tree for orthogonal
segment intersection respectively. We thus use a four component data structure whose
elements are obtained by the symbolic expansion of (R + S)2 . The query processing time is
O(log n + k) where k is the number of intersections reported and the space requirement is
O(n log n).
This idea can be generalized to d-dimensions where the number of hyper-rectangles from a
given set that intersect a query hyper-rectangle can be found by using the data structures
determined by the symbolic expansion of (R + S)d .