Computational Geometry the DCEL Data Structure Line Segment Intersection Plane Sweep Chapter 2 Euler’S Formula Basic Techniques
Total Page:16
File Type:pdf, Size:1020Kb
On the Agenda Computational Geometry The DCEL Data Structure Line Segment Intersection Plane Sweep Chapter 2 Euler’s Formula Basic Techniques 12. 22. Doubly Connected Edge List - DCEL DCEL face Record for each face, edge and vertex: f1 Geometric information Topological information Attribute information f2 f3 aka Half-Edge Structure f4 Main ideas: f5 Edges are oriented counterclockwise inside each face. Since an edge boarders two facets, we replace each edge with two half-edges, once from each side of the face. vertex edge 32. 42. DCEL DCEL v v v3 6 v3 6 e6,1 e6,1 e4,2 e7,1 e4,2 e7,1 f3 e f3 e e4,1 e7,2 9,1 e4,1 e7,2 9,1 e1,1 f1 e1,1 f1 e e 3,2 f2 f4 3,2 f2 f4 e e3,1 e e e3,1 e v1 2,1 e 8,1 v1 2,1 e 8,1 5,1 v4 5,1 v4 v5 v5 v2 v2 Vertex coordinate IncidentEdge face edge Half-edge origin twin IncidentFace next prev v1 (x 1,y 1,z 1) e2,1 f1 e1,1 e v e f e e v2 (x 2,y 2,z 2) e5,1 3,1 2 3,2 1 1,1 2,1 f2 e5,1 e v e f e e v3 (x 3,y 3,z 3) e1,1 3,2 3 3,1 2 5,1 4,1 f3 e4,2 e v e f e e v4 (x 4,y 4,z 4) e7,1 4,1 4 4,2 2 3,2 5,1 f4 e8,1 e v e f e e v5 (x 5,y 5,z 5) e9,1 4,2 3 4,1 3 7,1 6,1 v6 (x 6,y 6,z 6) e7,2 52. 62. 1 DCEL DCEL Support for: Vertex record: next(e) Walk around boundary of given face Coordinates Visit all edges incident to vertex v (how ?) Pointer to one half- IncFace(e) e ) edge that has v as its p e Queries: re ( origin v in (e w Most queries are O(1) Face record: ) t Pointer to one half- edge on its boundary Half-edge record: origin(e) Pointer to its origin: origin(e) Pointer to its twin half-edge: twin(e) Pointer to the face it bounds: IncidentFace(e) (face lies to left of e when traversed from origin to destination) Next and previous edge on boundary of IncidentFace(e): next(e), prev(e) 72. 82. DCEL DCEL v v6 Want to 3 e6,1 Walk around the boundary of a given face of a polygon e4,2 e7,1 f3 e Access a face from an adjacent one e4,1 e7,2 9,1 e1,1 f1 Visit all the edges around a given vertex e 3,2 f2 f4 e e3,1 e v1 2,1 e 8,1 5,1 v4 DCEL v Geometric structures combined by polygonal faces, edges and r v 5 vertices 2 Linear space representation Allow easy retrieval of data More “interseting” queries (in the homework): Given DCEL description, a line r and a halfedge that this line cuts, find efficiently all the facets cut by r. 92. 102. Line Segment Intersection Computing the Intersection Theorem: Segments ( p1,p 2) and ( p3,p 4) intersect in their interior iff p and p are on 1 2 ptp()=+− ( ppt ) 0 ≤≤ t 1 different sides of the line p p and p and p 1 2 1 3 4 3 4 p p are on different sides of the line p p . 2 =+− ≤≤ 2 1 2 qsqqqs()1 ( 2 1 ) 0 s 1 This can be checked by computing the p4 q1 orientations of four triangles . Which ? Question: What is the meaning of other p3 values of s and t ? q2 p1 p1 Special cases: Solve (2D) linear vector equation for t and s: pt()= qs () checkthatt∈[0,1] and s ∈ [0,1] 112. 122. 2 Point in Polygon Plane Sweep Given a polygon P with n sides, and q Problem : Given n segments in a point q, decide whether q∈P. the plane, compute all their intersections. P Assume: Solution A: Count how many times a No line segment is vertical. ray r originating at q intersects P. No two segments are collinear. Then q∈P iff this number is odd. No three segments intersect at a common point. Complexity: O( n) r Naive algorithm: Check each two segments for Question: Are there special cases ? intersection. Complexity: Θ(n2). 132. 142. Plane Sweep – Algorithm Plane Sweep - Basic Idea Event is any end point or We are able to identify all intersections by intersection point. looking only at adjacent segments in the Sweep the plane using a vertical sweep line status during the sweep. line. Maintain two data structures: Theorem: Just before an intersection Event priority queue – sorted by x occurs, the two relevant segments are coordinate. adjacent to each other in the sweep line Sweep line status – Stores segments status. currently intersected by sweep line, sorted by y coordinate. In practice: Look ahead: whenever two line segments become adjacent along the sweep line, check for their intersection to the right of the sweep line. 152. 162. Plane Sweep – Algorithm Plane Sweep – Algorithm Initialization: Add all segments’ endpoints to the event queue (O( n log n)). Event A: Beginning of segment Sweep line status is empty. Insert segment into sweep line status. Algorithm proceeds by inserting and deleting discrete events Test for intersection to the right of the from the queue until it is empty . sweep line with the segments immediately above and below. Insert point (if found) into event queue. Complexity: n such events, O(log n) each → O( n log n) total. 172. 182. 3 Plane Sweep – Algorithm Plane Sweep – Algorithm Event C: Intersection point Event B: End of segment Report the point. Delete segment from sweep line Swap the two line relevant status. segments in the sweep line status. Test for intersection to the right For the new upper segment – test it of the sweep line between the against its predecessor for an segments immediately above intersection. Insert point (if found) and below. Insert point (if found) into event queue. into event queue. Similar for new lower segment (with Complexity: n such events, successor). → O(log n) each O( n log n) Complexity: k such events, total. O(log n) each → O( klog n) total. 192. 202. Plane Sweep – Example Plane Sweep – Example a3 a3 b4 b4 s3 s3 e1 s4 e1 s4 a2 a2 a4 b3 a4 b3 s2 s2 b1 b1 b0 b0 s1 s1 b2 b2 s0 s0 a1 a0 a1 a0 Insert s4 to SLS Sweep Line s0,s1,s2,s3 Action Status Test s4-s3 and s4-s2. Add e1 to EQ Sweep Line s0,s1,s2, s4, s3 Event Status Queue a4, b1, b2, b0, b3, b4 Event 212. Queue b1, e1, b2, b0, b3, b4 222. Plane Sweep – Example Plane Sweep – Example a3 a3 b4 b4 s3 s3 e1 s4 e1 s4 a2 a2 a4 b3 a4 b3 s2 s2 e2 b0 e2 b0 b1 b1 s1 s1 b2 b2 s0 s0 a1 a0 a1 a0 Delete s1 from SLS Swap s3 and s4 . Action Action Test s0-s2. Add e2 to EQ Test s3-s2. Sweep Line Sweep Line Status s0,s2,s4,s3 Status s0,s2,s3,s4 232. 242. Event Queue e1, e2, b2, b0, b3, b4 Event Queue e2, b2, b0, b3, b4 4 Plane Sweep – Graph Definitions B Complexity Analysis C G = < V,E> V = vertices = A J L D {A,B,C,D,E,F,G,H,I,J,K,L} ≈ 2 E = edges = Total time complexity: O(( n+k ) log n). If k n this is I {(A,B),(B,C),(C,D),(D,E),(E,F),(F,G), almost like the naive algorithm. (G,H),(H,A),(A,J),(A,G),(B,J),(K,F), Event queue: heap K (C,L),(C,I),(D,I),(D,F),(F,I),(G,K), H E (J,L),(J,K),(K,L),(L,I)} Sweep line status: balanced binary tree Total space complexity: O( n+k ). F G Vertex degree (valence) = number of edges incident on vertex. deg(J) = 4, deg(H) = 2 k-regular graph = graph whose vertices all have degree k A face of a graph is a cycle of vertices/edges which cannot be shortened. F = faces = {(A,H,G),(A,J,K,G),(B,A,J),(B,C,L,J),(C,I,J),(C,D,I), (D,E,F),(D,I,F),(L,I,F,K),(L,J,K),(K,F,G),(A,B,C,D,E,F,G,H)} 252. 262. Connectivity Graph Embedding A graph is connected if there is a path of edges connecting every two vertices. A graph is embedded in R d if each vertex is d A graph is k-connected if between every two assigned a position in R . vertices there are k edge-disjoint paths. A graph G’=< V’,E’> is a subgraph of a graph G=< V,E> if V’ is a subset of V and E’ is the subset of E incident on V’. A connected component of a graph is a maximal connected subgraph. A subset V’ of V is an independent set in G if the subgraph it induces does not contain any edges of E. Embedding in R 2 Embedding in R 3 272. 282. Planar Graphs Triangulation Planar Graph Plane Graph A triangulation is a straight line plane B B graph whose faces are all triangles.