* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Planar Point Location - Brown Computer Science
Survey
Document related concepts
Transcript
C.S. 252 Computational Geometry Prof. Roberto Tamassia Sem. II, 1992–1993 Planar Point Location Lecture 04 Date: February 15, 1993 Scribe: John Bazik 1 Introduction In range searching, a set of values, or one-dimensional points, divide a line into segments, and the problem is to find the segment on which a query point falls. The analogous problem in two dimensions is planar point location. In planar point location, the search space is a plane subdivided by the edges of a graph. The graph is constructed of edges connecting vertices. Since the graph is planar, the edges are straight lines that do not cross one another. Without an embedded graph, the plane is a single infinite region. As the edges of a graph enclose portions of that region, a planar subdivision is created. r1 r2 r6 r3 r4 r5 Figure 1: A Planar Subdivision. Essential to any discussion of planar graph algorithms is Euler’s formula, which relates the number of edges to the number of vertices in a completely connected planar straight-line graph (PSLG). If R is the number of regions, V the number of vertices and E the number of edges, then Euler’s formula states R + V = E + 2. (1) Proof: The proof is by induction. For any fixed number of vertices, V , if there is only one region, R = 1, then there are V − 1 edges, since the graph is connected. Each new edge creates exactly one new region, so R increases with E. 2 1 If the graph is not completely connected, the formula becomes R + V = E + 1 + C. (2) where C is the number of completely connected components. If C is 1, this is just Euler’s formula. Any incompletely connected graph can be transformed into a completely connected one by connecting the components to each other with edges. This requires at least C − 1 edges, and can be done without adding any new regions or vertices. Hence the problem becomes the completely connected one. The number of regions is bounded by the number of edges in a PSLG as given by the following formula. R ≤ (2/3)E (3) Proof: The proof is by induction. We prove that the smallest number of edges used to form the largest number of regions is bounded by the formula. At least 3 edges are required to form 2 regions, creating a triangle. We assume that the formula holds as we create regions using the smallest number of edges possible. New regions are created by connecting two existing vertices with either one or two new edges. One edge is used when the vertices are not already connected, otherwise the two-edge method is required. If the minimum number of edges are always used, then to maintain planarity, these methods must be applied in alternating sequence. Two edges are needed to increase the number of regions from 2 to 3. If the edges are added interior to the original triangle, then it is possible to add a single edge to increase the regions from 3 to 4. But now each interior region is triangular and two edges are required to advance further. 2 Combining these two formulas gives a useful result for reasoning about planar graphs. R R=E−V +2 (1/3)E E E ≤ ≤ ≤ ≤ = (2/3)E (2/3)E V −2 3V − 6 O(V ) (4) Euler’s formula is important for the analysis of graph algorithms in the plane because it establishes a linear relationship among the numbers of regions, edges and vertices in planar graphs. We look at three methods for planar point location next. 2 Segment Tree Method A method suggested by Overmars [1] applies ray-shooting to the point location problem. A ray originates at a query point in a planar subdivision and is directed, by convention, downward. Each edge of the graph stores the name of the region above it, so the first edge encountered by the ray identifies the region containing the point. 2 r1 r2 r6 r3 q r4 r5 Figure 2: Vertical ray shooting. The primary data structure is a segment tree T . Each segment represents a vertical slab of the plane, delimited by the sorted x components of the vertices of the embedded graph. Since the graph is planar, the edges that cross each slab do not cross one another, and so they are strictly ordered in the vertical dimension. The secondary data structure captures this ordering of the edges. At each node of T , a balanced tree contains the edges whose projections on the x axis span the interval represented by that node, but do not span the interval of its parent node. That is, edges are stored with each allocation node of their “segment” along the x axis. q Figure 3: Segment Tree Method. To locate a point P , we search the segment tree for the interval containing the x component of P . At each node encountered during this search, we search the secondary tree for the edge closest to P but below it. Each of these secondary searches represents a ray shot downward at some of the edges of the graph. The closest edge discovered in these repeated searches supplies the region containing P . O(log n) searches of O(log n) each yield a query time of O(log2 n) for this algorithm. The segment tree contains O(n) nodes, since each internal node corresponds to a vertex in the graph. Each edge may be stored at at most O(log n) nodes since there are at most 2 3 allocation nodes at each level of the segment tree for each edge. By Euler’s theorem, there are O(n) edges, so the total space used is O(n log n). 3 Slab Method The slab method (Dobkin and Lipton [2]) offers optimal query time behavior, at the expense of needing possibly worst-case space. r4 e1 e2 e3 e4 e1 e2 e3 e4 r4 Figure 4: The Slab Method. A planar subdivision is divided into horizontal slabs delimited by the sorted y components of the vertices of the embedded graph. Each slab consists of trapezoids created by the nonintersecting segments of the graph edges that pass through it. Finding the region containing a query point means identifying first the slab, then the trapezoid that contains it. The primary data structure is a segment tree T . Each segment represents a horizontal slab of the plane. Each leaf of T contains a balanced tree. These secondary structures contain all the graph edges that pass through the slab, ordered left to right. The region names are stored with the edges. To locate a point P , we search the segment tree for the interval containing the y component of P . Then we search the secondary tree for the edges between which P lies. These two searches give us a query time of O(log n). A worst-case storage requirement of O(n2 ) results from O(n) slabs of O(n) segments each (see Figure 5). The preprocessing cost of this data structure is as onerous as its size. First, an O(n log n) sort of the vertices by y coordinate is needed. Then a line-sweep algorithm is used to construct the tree as follows. Consider each vertex in ascending y order, and maintain at all times a left-to-right ordered list of graph edges. Initially that list is empty. As each vertex is encountered, edges below and incident upon it are deleted from the list and edges above and incident upon it are added. If the list is kept as a balanced tree, a single upward sweep produces at each vertex the secondary structure for the slab above it. Since each edge is inserted and deleted exactly once, the time complexity of the sweep is O(n log n). But generating the secondary trees requires O(n2 ) time – equal to their aggregate size. 4 Figure 5: Worst-Case PSLG. 4 Trapezoid Method The trapezoid method of Preparata [3] refines the slab method by reducing storage and preprocessing time while maintaining O(log n) query time. In this approach, a search tree is constructed by slicing the graph into regions, as in the slab method. However, the slices are alternately horizontal and vertical, producing more “slabs” (or trapezoids), but fewer and simpler secondary structures. Figure 6: The Trapezoid Method. As defined by this method, a trapezoid has two horizontal sides and may be bounded to the left and right by edges of the graph, or it may be unbounded on either or both sides. Furthermore, it may not contain an edge that spans from top to bottom. Such an edge is a spanning edge that effects a vertical cut of the trapezoid, dividing it in two. A horizontal cut is a horizontal line drawn through the median interior vertex of a trapezoid, again, dividing it in two (see Figure 7). Consider a planar subdivision as a trapezoid, with horizontal sides drawn through the top and bottom vertices, and unbounded to the left and right. The data structure is a tree constructed by alternately and recursively applying horizontal and vertical cuts to the initial trapezoid. The nodes of the tree are of two types. ∇–nodes have two children and correspond to a horizontal cut. There are exactly n of these, one 5 Figure 7: Vertical and Horizontal Cuts. for each vertex. O–nodes have k children and correspond to k − 1 vertical cuts (spanning edges). The leaves of O–nodes correspond to empty trapezoidal regions. Compound nodes are O–nodes that correspond to more than one spanning edge (see Figure 9). These contain a secondary search tree analogous to that used in the slab method. e4 r1 e3 e 13 e9 e5 e 14 e6 e 15 e 12 e 20 e 11 l1 e 21 e2 e 10 e 22 l2 e7 e1 e 19 e 16 e8 e 17 e 18 Figure 8: Trapezoidal Decomposition. To search for a query point, the primary tree is traversed by comparing the y–value of the point with each ∇–node encountered, and the left-to-right ordering of the point with respect to the spanning edge represented by each O–node encountered. If the point is neither to the left nor to the right of a compound O–node, the O–node’s secondary tree is traversed. The data structure contains n − 2 ∇–nodes. The number of O–nodes depends on how many fragments the O(n) edges are divided into. To estimate this number, consider the way the data structure is created. After the first horizontal cut of an edge, each additional horizontal cut of that edge produces a trapezoid spanned by it (the trapezoid bounded by the two horizontal cuts). Since each horizontal cut takes place at the median vertex in its trapezoid, half of those vertices will not result in further cutting of the edge. That is, the edge is not exposed to further horizontal cuts from the vertices in any trapezoid that it spans. Since the horizontal cuts proceed in a binary fashion, the worst-case number of fragments an edge can be cut into is O(log n). So for O(n) edges, O(n log n) O–nodes may be needed. Together with the ∇ nodes, the total space complexity of the Trapezoid method is O(n log n). 6 l1 l2 e 11 e 16 e 17 e 18 e 21 e2 e 16 e 17 e 18 e 21 e 21 e 21 e 21 e 21 e 10 e 22 Figure 9: The Data Structure. Discussion of the Trapezoid Method continues in the next lecture. References [1] M. Overmars, “Range Searching in a Set of Line Segments,” Proc. (1st) ACM Symposium on Computational Geometry, pp. 177–185, 1985. [2] D. Dobkin and R. Lipton, “Multidimensional Searching Problems,” SIAM Journal of Computing vol. 5, no. 2, pp. 181–186, June 1976. [3] F. P. Preparata, “A New Approach to Planar Point Location,” SIAM Journal of Computing vol. 10, no. 3, pp. 473–482, 1985. 7