Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to Computational Geometry Joseph S. B. Mitchell Stony Brook University.

Similar presentations


Presentation on theme: "An Introduction to Computational Geometry Joseph S. B. Mitchell Stony Brook University."— Presentation transcript:

1 An Introduction to Computational Geometry Joseph S. B. Mitchell Stony Brook University

2 Point Location Point-in-polygon test: Is point q inside simple polygon P ? Point-in-polygon test: Is point q inside simple polygon P ? P n-gon q Naïve: O(n) per test CG: O(log n) 5 crossings  q inside

3 Point Location More generally: Search for which face of a planar map contains query point q More generally: Search for which face of a planar map contains query point q Example: Map of Manhattan Applet Example: Map of Manhattan AppletApplet 3 Trapezoid under the mouse is highlighted q

4 Valuable Resources Preprocessing time Preprocessing time Memory/storage: how big is the data structure? Memory/storage: how big is the data structure? Query time Query time 4

5 Point Location in 1D Given a partition of the x-axis by a set of points {x 1, x 2, …}. Given a partition of the x-axis by a set of points {x 1, x 2, …}. Preprocess for location of a query point q: Sort the x i ‘s O(n log n) time, O(n) space, O(log n) query time Preprocess for location of a query point q: Sort the x i ‘s O(n log n) time, O(n) space, O(log n) query time Can we achieve these same bounds (optimal) in 2D? Can we achieve these same bounds (optimal) in 2D? 5

6 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 6 One Method: Partition the Plane into Slabs Query time : O(log n) binary search in x and then binary search in y direction. Storage space O(n 2 ) n/2

7 Slab Method 7 Draw vertical lines through all vertices. Search: Binary search in x; then, within a slab, in y. Point location in time O(log n) BUT, space (and preprocessing) is O(n 2 ), which can be realized in some cases:

8 Method 1: Randomized Incremental Construction of a Trapezoidal Map 8

9 Trapezoidal Map 9

10 Cases for Cases for 10

11 Trapezoidal Map Complexity of the map: Complexity of the map: Proof: (a). Vertices: Proof: (a). Vertices: 4 + 2n + 2(2n) 4 + 2n + 2(2n) 11 Corners of R Endpts of S Endpts of upper/lower extension through each endpt of S

12 Trapezoidal Map Complexity of the map: Complexity of the map: Proof: (b). Trapezoids: Charge each trapezoid to its leftp Proof: (b). Trapezoids: Charge each trapezoid to its leftp Each segment left endpt is charged 2 times; each right endpt charged 1 time Each segment left endpt is charged 2 times; each right endpt charged 1 time One trapezoid (unbounded, left of all segs) has no segment to charge One trapezoid (unbounded, left of all segs) has no segment to charge 12

13 Representation of Trapezoidal Maps Trapezoids adjacent to  Trapezoids adjacent to  13

14 Representation of Trapezoidal Maps Instead of DCEL: Instead of DCEL: Line segments SLine segments S Endpts of SEndpts of S Trapezoids with pointers toTrapezoids with pointers to Leftp, rightp Leftp, rightp Top, bottom Top, bottom At most 4 neighboring trapezoids At most 4 neighboring trapezoids 14

15 Trapezoidal Map, Search Structure, D 15

16 Constructing TrapezoidalMap 16

17 17

18 18

19 19

20 Summary We have seen that a simple randomized method yields: We can also address degeneracies: 20

21 More Details: Slides of Thomas Ottmann 21 (of “Bentley-Ottmann sweep”)

22 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 22 Partitioning into Trapezoids Assumption : Segments are in “general position“ Observation : Every vertical edge has one point in common with a segment end. R

23 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 23 Observations R f f is convex f is bounded Every non - vertical side of f is part of a segment of S or an edge of R

24 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 24 Trapezoidal Decomposition Lemma : Each face in a trapezoidal map of a set S of line segments in general position has 1 or 2 vertical sides and exactly two non-vertical sides

25 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 25 Left Edge of a Trapezoid R For every trapezoid Δ  T(S), except the left most one, the left vertical edge of Δ is defined by a segment endpoint p, denoted by leftp(Δ).

26 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 26 Partitioning into Trapezoids Assumption : Segments are in “general position“ Observation : Every vertical edge has one point in common with a segment end. R

27 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 27 Observations R f f is convex f is bounded Every non - vertical side of f is part of a segment of S or an edge of R

28 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 28 Trapezoidal Decomposition Lemma : Each face in a trapezoidal map of a set S of line segments in general position has 1 or 2 vertical sides and exactly two non-vertical sides

29 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 29 Left Edge of a Trapezoid R For every trapezoid Δ  T(S), except the left most one, the left vertical edge of Δ is defined by a segment endpoint p, denoted by leftp(Δ).

30 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 30 The 5 Cases: Left Edges of a Trapezoid a)top(  ) bottom(  ) leftp(  ) b) leftp(  ) top(  ) d) leftp(  ) top(  ) c) leftp(  ) top(  ) bottom(  ) e) It is left edge of R. This case occurs for a single trapezoid of T(S) only, namely the unique leftmost trapezoid of T(S)

31 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 31 Size of the Trapezoidal Map Theorem: The trapezoidal map T(S) of a set of n line segments in general position contains at most 6n + 4 vertices and at most 3n + 1 trapezoids. Proof (1):A vertex of T(S) is either - a vertex of R or 4 - an endpoint of a segment in S or 2n - a point where the vertical extension starting in an endpoint abuts on another segment or on the boundary R. 2 * (2n) 6n + 4

32 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 32 Size of the Trapezoidal Map Theorem: The trapezoidal map T(S) of a set of n line segments in general position contains at most 6n + 4 vertices and at most 3n + 1 trapezoids. Proof (2):Each trapezoid has a unique point leftp(  ), which is - the lower left corner of R - the left endpoint of a segment (can be leftp(  ) of at most two different trapezoids) - the right endpoint of a segment (can be leftp(  ) of at most one trapezoid) 1 2n n 3n + 1

33 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 33 Adjacent Trapezoids Two trapezoids  and  ´ are adjacent if they meet along a vertical edge.  11 22 33 44 55  11 22 33 44 55 66 1)Segments in general position : A trapezoid has at most four adjacent trapezoids 2) Segments not in general position : A trapezoid can have an arbitrary number of adjacent trapezoids.

34 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 34 Vertical Neighbors: Upper, Lower Left Trapezoid  ' is (vertical) neighbor of  top(  ) = top(  ’) or bottom(  ) = bottom(  ’) In the first case  ´ is upper left neighbor of , in the second case  ´ is lower left neighbor of .

35 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 35 Representing Trapezoidal Maps There are records for all line segments and endpoints of S, the structure contains records for trapezoids of T(S), but not for vertices or edges of T(S). The record for trapezoid  stores pointers to top(  ), and bottom(  ), pointers to leftp(  ) and rightp(  ) and finally pointers to its at most 4 neighbors.  is uniquely defined by top(  ), bottom(  ), leftp(  ) and rightp(  ).

36 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 36 Search Structure: DAG A B C D F E G 1l 1r 2l 2r A B C D E F G 1l 1r 2r 2l 1 2 2 End points decide between left, right Segments decide between below, above 1 2

37 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 37 A Randomized Incremental Algorithm Input : A set S of n non-crossing line segments Output : The trapezoidal map T(S) and a search structure D(S) for T(S) in a bounding box. Determine a bounding box R, initialize T and D Compute a random permutation s 1,s 2,..., s n of the elements of S for i = 1 to n do add s i and change T(S i - 1 ) into T(S i ) and D(S i -1 ) into D(S i ) Invariant : In the step i T(S i ) is correct trapezoidal map of S i and D(S i ) is an associated search structure.

38 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 38 A Randomized Incremental Algorithm Input : A set of n non-crossing line segments Output : The trapezoidal map T(S) and a search structure D for T(S) in a bounding box. Determine a bounding box R, initialize T and D Compute a random permutation s 1,s 2,..., s n of the elements of S for i = 1 to n do Find the set  0,  1,...,  k of trapezoids in T properly intersected by s i. Remove  0,  1,...,  k from T and replace them by new trapezoids that appear because of the intersection of s i. Remove the leaves for  0,  1,...,  k from D and create leaves for the new Trapezoids. Link the new leaves to the existing inner nodes by adding some new inner nodes.

39 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 39 Questions How can we find the intersecting trapezoids? How can T and D be updated a) if new segment intersects no previous trapezoid ? b) if new segment intersects previous trapezoids ?

40 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 40 Finding the Intersecting Trapezoids 00 sisi 11 22 33  j+1 is lower right neighbour of  j In T(S i ) exactly those trapezoids are changed, which are intersected by s i if rightp(  j ) lies above s i then Let  j+1 be the lower right neighbor of  j. else Let  j+1 be the upper right neighbor of  j Clue :  0 can be found by a query in the search structure D(S i -1 ) constructed in iteration stage i -1.

41 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 41 New Segment Completely Contained in Trapezoid Decomposition t p q s T(S i-1 ) A C B D T(S i ) Search structure D(S i-1 ) t A B CD p q s 4 new trapezoids, -1 old trapezoid, search depth + 3

42 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 42 New Segment Intersects Previous Trapezoids Decomposition p q 00 11 22 33 s T(S i - 1 ) 00 11 22 33 D(S i - 1 ) Search structure F A B C E D T(S i ) D(S i ) A B C D E F sss q s 6 new trapezoids, – 4 old, depth + 2

43 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 43 New Segment Intersects Previous Trapezoids Decomposition p q t0t0 t1t1 t2t2 t3t3 s T(S i - 1 ) t0t0 t1t1 t2t2 t3t3 D(S i - 1 ) Search structure F A B C E D T(S i ) D(S i ) A B C D E F sss q s 6 new trapezoids, – 4 old, depth + 2

44 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 44 Estimation of the Depth of the Search Structure Let S be a set of n segments in general position, q be an arbitrary fixed query point. Depth of D(S): worst case : 3n, average case : O(log n) Consider the path traversed by the query for q in D Let X i = # of nodes on the search path for q created in iteration step i. X i <= 3 P i = probability that there exists node on the search path for q that is created in iteration step i. E[X i ] <= 3 P i

45 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 45 Observation Iteration step i contributes a node to the search path for q exactly if  q (S i - 1 ), the trapezoid containing q in T(S i - 1 ), is not the same as  q (S i ), the trapezoid containing q in T(S i ) P i = Pr[  q (S i )   q (S i - 1 )]. If  q (S i ) is not same as  q (S i - 1 ), then  q (S i ) must be one of the trapezoids created in iteration i.  q (S i ) does not depend on the order in which the segments in S i have been inserted. Backwards analysis : We consider T(S i ) and look at the probability that  q (S i ) disappears from the trapezoidal map when we remove the segment s i.  q (S i ) disappears if and only if one of top(  q (S i )), bottom(  q (S i )), leftp(  q (S i )), or right(  q (S i )) disappears with removal of s i.

46 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 46 Observation Prob[top(  q (S i ))] = Prob[bottom(  q (S i ))] = 1/i. Prob[leftp(  q (S i ))] disappears is at most 1/i. Prob[rightp(  q (S i ))] disappears is at most 1/i. P i = Pr[  q (S i )   q (S i - 1 )] = Pr[  q (S i )  T(S i - 1 )]  4/i

47 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 47 Analysis: Size of Search Structure Leaves in D are in one – to – one correspondence with the trapezoids in , of which there are O(n). The total number of nodes is bounded by : (# of inner nodes created in iteration step i) The worst case upper bound on the size of the structure

48 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 48 Analysis: Size of Search Structure Theorem: The expected number of nodes of D is O(n). Proof: The # of leaves is in O(n). Consider the internal nodes: X i = # of internal nodes created in iteration step i if  disappears from T(S i ) when s is removed from S i otherwise There are at most four segments that cause a given trapezoid to disappear

49 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 49 Analysis: Size of Search Structure The expected number of newly created trapezoids is O(1) in every iteration of the algorithm, from which the O(n) bound on the expected amount of storage follows.

50 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann 50 Summary Let S be a planar subdivision with n edges. In O(n log n) expected time one can construct a data structure that uses O(n) expected storage, such that for any query point q, the expected time for a point location query is O(log n).

51 Bottom Line There are deterministic methods that spend worst-case O(n log n) time to build a structure of worst-case size O(n), supporting worst-case O(log n) point location queries Next, we discuss one such method 51

52 Method 2: Deterministic Construction of a Hierarchical Triangulation 52 Can also be applied to trapezoidal maps

53 An Optimal Method: Kirkpatrick Hierarchical Triangulation Begin with full triangulation Begin with full triangulation Remove a “large” set of low-degree (  8) vertices that are independent Remove a “large” set of low-degree (  8) vertices that are independent (such a set always exists in a planar graph, by Euler) Retriangulate the resulting “holes” Retriangulate the resulting “holes” Repeat until only the big outer triangle remains Repeat until only the big outer triangle remains Build DAG for searching Build DAG for searching (no two adjacent) O(n) “large” :  Cn  only O(log n) iterations

54 Convert Arbitrary PSLG to Full Triangulation Place big triangle around it Place big triangle around it Triangulate every face Triangulate every face 54 [Lecture 27, David Mount notes; based on section 2.2.2.4 of Preparata and Shamos, “Computational Geometry”]

55 55 [O’Rourke, page 277] Proof uses Euler’s formula (f-e+v=2) and the fact that each vertex has degree at least 3 in our graph G.

56 56 [Lecture 27, David Mount notes; based on section 2.2.2.4 of Preparata and Shamos, “Computational Geometry”]

57 Proof of Theorem 7.10.1 Sum of vertex degrees = ∑= 2E Sum of vertex degrees = ∑= 2E Recall: in a planar n-vertex graph: E≤3n-6 Recall: in a planar n-vertex graph: E≤3n-6 Thus, ∑ ≤ 6n-12 Thus, ∑ ≤ 6n-12 Claim: There are ≥n/2 vertices of degree ≤8 Claim: There are ≥n/2 vertices of degree ≤8 Pf: Assume there are > n/2 vertices of deg ≥9Pf: Assume there are > n/2 vertices of deg ≥9 Then, sum of degrees of these is ≥ 9n/2, and the other vertices have deg ≥3, so the total degree sum, ∑, would satisfy: ∑ ≥ 9n/2+3n/2=6n 57 Contradicts ∑ ≤ 6n-12

58 Independent Set Algorithm Input: planar graph G Input: planar graph G Output: an independent set I of vertices of low degree (≤ 8) Output: an independent set I of vertices of low degree (≤ 8) I ← Ø I ← Ø Mark vertices of G of degree ≥ 9 Mark vertices of G of degree ≥ 9 While some nodes are unmarked, do While some nodes are unmarked, do Choose an unmarked vertex v (lowest index)Choose an unmarked vertex v (lowest index) Mark v and all neighbors of vMark v and all neighbors of v I ← I  {v}I ← I  {v} 58

59 Independent Set Algorithm 59 [Lecture 27, David Mount notes; based on section 2.2.2.4 of Preparata and Shamos, “Computational Geometry”]

60 Analysis of Algorithm Each time we mark v, and the neighbors of v, the number of unmarked nodes goes down by at most 9 Each time we mark v, and the neighbors of v, the number of unmarked nodes goes down by at most 9 Thus, at least 1/9-th of the m unmarked (deg ≤8) vertices are added to I Thus, at least 1/9-th of the m unmarked (deg ≤8) vertices are added to I We know m ≥ n/2 We know m ≥ n/2 Thus, I ≥ n/18 Thus, I ≥ n/18 Thus, the Algorithm always gives an independent set of deg ≤8 vertices of size ≥ n/18 Thus, the Algorithm always gives an independent set of deg ≤8 vertices of size ≥ n/18 60 Initially: the unmarked vertices are those with deg≤8.

61 Kirkpatrick Example Full triangulation, T 0 Triangles in T 0

62 62 T0T0 T1T1 Independent sets: {2,5} {3,7} {4} {6}

63 63 T2T2 T3T3 T4T4 Final DAG hierarchy and search path for query point p Independent sets: {2,5} {3,7} {4} {6}

64 Another Example 64 [Lecture 27, David Mount notes; based on section 2.2.2.4 of Preparata and Shamos, “Computational Geometry”]

65 65 [Lecture 27, David Mount notes; based on section 2.2.2.4 of Preparata and Shamos, “Computational Geometry”]

66 Another Example 66 1 2 3 4 5 6 7 10 9 8 Build Kirkpatrick hierarchy, for extra practice. (note that vertex 2 has “high” degree)

67 Kirkpatrick Approach to Trapezoidal Decomposition Deterministic method (in place of randomized) Deterministic method (in place of randomized) Obtain worst-case optimal bounds: Obtain worst-case optimal bounds: O(n log n) preprocessingO(n log n) preprocessing O(n) spaceO(n) space O(log n) query timeO(log n) query time Applies to curved subdivisions, not just polygonal (straight-edge) ones (PSLG) Applies to curved subdivisions, not just polygonal (straight-edge) ones (PSLG) 67

68 Interference Graph IG(S): IG(S): Nodes: SNodes: S Edge (s,s’) iffEdge (s,s’) iff (1) s,s’ bound same trapezoid of T(S); or (1) s,s’ bound same trapezoid of T(S); or (2) vertical extensions through endpts of s,s’ bound same trapezoid of T(S) (2) vertical extensions through endpts of s,s’ bound same trapezoid of T(S) 68 s s’ s (1) (2)

69 Interference Graph Claim 1: IG(S) has <4n edges Claim 1: IG(S) has <4n edges Edges of type (1): at most one per trapezoid, so at most 3n+1Edges of type (1): at most one per trapezoid, so at most 3n+1 Edges of type (2): charge to right endpt of s; rightmost right endpt does not pay; thus, <nEdges of type (2): charge to right endpt of s; rightmost right endpt does not pay; thus, <n 6969 s s’ s (1) (2)

70 Interference Graph Claim 2: There is an indep set in IG(S) of size >= n/8 and we can find it in O(n) time. Claim 2: There is an indep set in IG(S) of size >= n/8 and we can find it in O(n) time. Proof: Claim 1 implies e<4n Proof: Claim 1 implies e<4n So, Sum of deg(s) = 2e < 8n So, Sum of deg(s) = 2e < 8n So there is a node of deg <8 (<=7) So there is a node of deg <8 (<=7) So we can recursively 8-color IG(S) So we can recursively 8-color IG(S) Pick largest color class; it has >= n/8 Pick largest color class; it has >= n/8 Time: T(n) <= O(n) +T((7/8)n) =…=O(n) Time: T(n) <= O(n) +T((7/8)n) =…=O(n) 70

71 Data Structure As with RIC algorithm, build the DAG as the search structure As with RIC algorithm, build the DAG as the search structure Properties: Properties: Longest path is O(log n)Longest path is O(log n) Bounded out-degreeBounded out-degree 71


Download ppt "An Introduction to Computational Geometry Joseph S. B. Mitchell Stony Brook University."

Similar presentations


Ads by Google