cs6100 topics in design and analysis of algorithms
play

CS6100: Topics in Design and Analysis of Algorithms Point Location - PDF document

CS6100: Topics in Design and Analysis of Algorithms Point Location John Augustine CS6100 (Even 2012): Point Location Planar Subdivision Recall that a planar subdivision is an straight edge embedding of a (possibly disconnected) planar graph


  1. CS6100: Topics in Design and Analysis of Algorithms Point Location John Augustine CS6100 (Even 2012): Point Location

  2. Planar Subdivision Recall that a planar subdivision is an straight edge embedding of a (possibly disconnected) planar graph that comprises of vertices, edges, and faces. In a DCEL representation, ⋆ Each edge is represented as two “half” edges. • Each vertex record of a vertex v stores the coordinates and an arbitrary half edge originating from v . • Each face record of a face f stores 1. a pointer to one of the half edges in its outer boundary. This is null for the open face. 2. A list of pointers to edges; for each “hole” inside f , one half edge is chosen arbitrarily. • Each half edge bounds a face f , which is the face to our left as we walk along the half edge. For each half edge e , we store 1. A pointer to its origin vertex, 2. A pointer to its twin half edge, 3. A pointer to the face it bounds. CS6100 (Even 2012): Point Location 1

  3. Point Location Given for preprocessing: A planar subdivision S comprising n edges stored as a Doubly Connected Edge List (DCEL). Queries: Each query is a point q . We are to quickly report the face that contains q . Application: Clicking on an online map, should be able to report the country. Assumptions: • No two endpoints of edges lie on the same vertical line. • Also, assume that the subdivision is enclosed by a large axis parallel rectangle R . We say that such subdivisions are in general position. CS6100 (Even 2012): Point Location 2

  4. Point Location: Easy Solution Further subdivide S by adding vertical lines through each vertex. This creates several vertical slabs whose x coordinates can be preprocessed so that, given a query q , we can quickly find the slab in which it falls. Each slab consists of edges that go all the way across without intersecting each other. Therefore, they can be ordered top to bottom. So a BBST can be constructed for each slab as well. Given q , we can find the slab that contains q and then we can use the associated BBST to return the face in the slab that contains q . This in turn will lead us CS6100 (Even 2012): Point Location 3

  5. to the face in S that contains q . The query time is O (log n ) . The complexity of the planar subdivision can increase significantly (to Θ( n 2 ) ) when vertical lines are added. Hence storage is Θ( n 2 ) in the worst case. n 4 n 4 slabs CS6100 (Even 2012): Point Location 4

  6. Trapezoidal Map aka Vertical Decomposition of S From each vertex in S , draw vertical extensions, one going upward and the other going down. These extensions stop when they meet another segment (or boundary). The trapezoidal map T ( S ) is (i) the subdivision S , (ii) the rectangle R and (iii) the upper and lower vertical extensions. R CS6100 (Even 2012): Point Location 5

  7. Properties of Faces in Trapezoidal Maps First a definition. Recall that the subdivision is in general position. Nevertheless some of the edges around a face in T ( S ) may be adjacent and collinear; we merge such edges and call them a side . sides Lemma 1. Each face in a trapezoidal map T ( S ) has either one or two vertical sides and exactly 2 non- vertical sides. Proof Sketch. We first show that each face in T ( S ) is convex. Simply look at the interior angles at each face. They will all be < 180 ◦ . Therefore, # of vertical sides is at most 2. Secondly, show that no two non-vertical sides of a face can be adjacent. This implies at most 2 non-vertical sides. CS6100 (Even 2012): Point Location 6

  8. Four Objects that define a Face Let ∆ be a face in T ( S ) . Define top (∆) and bottom (∆) as below. top ( ∆ ) ∆ bottom ( ∆ ) Observe that the left side (symmetrically, right side) can fall into one of five cases. Four cases are shown below. The fifth case is when the left side is the left edge of the bounding box R . leftp ( ∆ ) leftp ( ∆ ) leftp ( ∆ ) top ( ∆ ) top ( ∆ ) top ( ∆ ) top ( ∆ ) bottom ( ∆ ) s bottom ( ∆ ) bottom ( ∆ ) bottom ( ∆ ) leftp ( ∆ ) (a) (b) (c) (d) Note that a single vertex leftp (∆) “defines” the left vertical edge. Similarly, we define rightp (∆) . CS6100 (Even 2012): Point Location 7

  9. Bounding the Complexity of T ( S ) Lemma 2. The trapezoidal map of a set S of n line segments in general position contain (i) at most 6 n + 4 vertices and (ii) at most 3 n + 1 trapezoids. Proof Sketch. (i) Note that each vertex in S spawns 2 vertices in T ( S ) . Also, consider the bounding box. (ii) Focus on leftp (∆) for each ∆ . A right end of a line segment in S is the leftp for at most 1 face. The left end of a line segment in S is the leftp for at most 2 faces. Finally, the bottom-left point of R can also be a leftp. CS6100 (Even 2012): Point Location 8

  10. Representing Trapezoidal Maps We say that two trapezoids ∆ and ∆ ′ are adjacent if they meet along a vertical edge. When S is in general position, each trapezoid has at most four neighbours: (i) lower left, (ii) upper left, (iii) lower right, and (iv) upper right. To store T ( S ) , we have records for: • Line segments in S . • End points. • Adjacent trapezoids defined by leftp, rightp, top and bottom. Furthermore, pointers to its four neighbours are also included. The geometry of the trapezoid can be deduced from this information. CS6100 (Even 2012): Point Location 9

  11. A Randomized Incremental Algorithm for Constructing Point Location Datastructure T ( S ) can be constructed easily by plane sweeping from left to right. However, when a query point is given to us, we need to navigate T ( S ) to find the correct trapezoid ∆ q where q is located. For this, we will need an associated data structure, a directed acyclic graph (DAG) D . D has a single root node and leaves represent trapezoids. Inner nodes of D have degree 2. There are two types of inner nodes. The x -nodes correspond to vertices in S . The y nodes correspond to segments in S . When queried with a point q , we start at the root and traverse to a leaf which points to the trapezoid in S that contains q . There are two types of questions we ask at each node to guide our traversal. At an x -node, we ask if q is to the left or right of the CS6100 (Even 2012): Point Location 10

  12. vertex associated with the x -node. If yes, we go to the left child, otherwise, we go to the right child. At a y -node, we ask if q is above or below the segment associated with the y -node. If yes, we go to the left child, otherwise, we go to the right child. p 1 B q 1 A s 1 q 1 s 1 q 2 p 1 D E G s 2 p 2 p 2 s 2 B G A q 2 E C s 2 F C D F CS6100 (Even 2012): Point Location 11

  13. Overview of the Algorithm: Input: The set S of n non-crossing lines. Output: The trapezoidal map T ( S ) and an associated DAG D . 1. Compute the bounding box R , which is a rectangular box large enough to encompass all the segments in S , and compute T and D for R . D will be a single root which will also be the leaf. 2. Compute a random permutation ( s 1 , s 2 , . . . , s n ) of elements of S . 3. Repeat the following steps for values of i from 1 to n : (a) Find the sequence (∆ 0 , ∆ 1 , ∆ k ) of trapezoids in the current T that are intersected by s i . (b) Remove them from T and replace them with new trapezoids. (c) Remove the leaves in D corresponding to the trapezoids in (∆ 0 , ∆ 1 , ∆ k ) and create leaves for new trapezoids. (d) Link the new leaves to D using some inner nodes. CS6100 (Even 2012): Point Location 12

  14. Invariant: At i th step, we have T and D for S i = { s 1 , s 2 , . . . , s i } . The initialization step in which we create T and D for R is easy, so we focus on the iterative steps. At each iteration i , we need to find the trapezoids intersected by the new segment s i that is inserted. ∆ 0 ∆ 1 ∆ 3 s i ∆ 2 For this, we first locate the trapezoid ∆ 0 in which the left most point of s i falls and then follows s i left to right (with some care) in enumerate the trapezoids intersected by s i . The details are in the pseudocode below CS6100 (Even 2012): Point Location 13

  15. Algorithm F OLLOW S EGMENT ( T , D , s i ) Input. A trapezoidal map T , a search structure D for T , and a new segment s i . Output. The sequence ∆ 0 ,..., ∆ k of trapezoids intersected by s i . 1. Let p and q be the left and right endpoint of s i . 2. Search with p in the search structure D to find ∆ 0 . j ← 0; 3. while q lies to the right of rightp ( ∆ j ) 4. do if rightp ( ∆ j ) lies above s i 5. 6. then Let ∆ j + 1 be the lower right neighbor of ∆ j . 7. else Let ∆ j + 1 be the upper right neighbor of ∆ j . j ← j + 1 8. return ∆ 0 , ∆ 1 ,..., ∆ j 9. The leaf in D associated with each trapezoid intersected by s i is then deleted and each new trapezoid created as a consequence of inserting s i is added as a leaf to D . Furthermore, each newly added leaf has to be connected to the rest of D via some internal nodes. To see how this is done, we see a couple of examples. CS6100 (Even 2012): Point Location 14

  16. Consider first the example where s i is fully contained in some trapezoid in T . T ( S i − 1 ) T ( S i ) ∆ C A B q i s i D p i This creates four new trapezoids (while eliminating one, i.e., the one in which s i falls). The leaf in D corresponding to the eliminated trapezoid ∆ is deleted from D and 4 new leaves are added (corresponding to trapezoids A, B, C, and D shown above). See below for how these four leaves are connected in the place of the leaf corresponding to ∆ . CS6100 (Even 2012): Point Location 15

Recommend


More recommend