200 likes | 287 Views
Last Time: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness). This time: Planar Subdivisions. Eventually, get to problems such as intersection of planar subdivisions, and show that these algorithms are easier (more efficient) than general segment intersection.
E N D
Last Time: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness)
This time: Planar Subdivisions Eventually, get to problems such as intersection of planar subdivisions, and show that these algorithms are easier (more efficient) than general segment intersection. Some slides in this lecture come from Carola Wenk, Univ. Texas, San Antonio
Don’t usually have “n segments” Common inputs represent something more interesting than n segments… perhaps a “subdivision” of the plane into regions. Today we won’t look at algorithms, rather we will define “planar subdivisions”, and look at: • A data structure to represent them, and • Relationships between edges, vertices and faces.
Planar subdivisions include: • Voronoi Diagrams • Polygon/Delaunay triangulations • Representation to reason about and manipulate the subdivision should, at least: • be able to list the edges that bound each face of the subdivision in cyclic order, and • be able to list the edges that surround each vertex.
Planar Graph: • Graph which can be drawn with edges intersecting only at endpoints. Planar Straight Line Graph (PSLG): • Embedded on the plane, and edges are all straight. PSLG subdivides the plane into different types of regions. • 0 dimensional vertices, • 1 dimensional edges, and • 2 dimensional faces. These regions are disjoint, • each edge is topologically open (it does not include it endpoints) • each face is open (it does not include its boundary). Fun Facts: • There is always one unbounded face, that stretches to infinity. • The underlying planar graph need not be a connected graph. • faces may contain holes (and these holes may contain other holes. • Can completely specify the embedding by giving the connectivity of the graph, and the cyclic order of edges around each vertex.
Counting elements of a PSLG Can add new vertex and new edge without adding a face Adding a new edge between existing vertices adds a face (or connects two components. • Variables: • V number of vertices, • E number of edgs, • F number of faces Euler's formula: V - E + F = 2. • If graph is disconnected, with C connected components: V - E + F - C = 1: • Example: • V = 13 • E = 12 • F = 4 • C = 4.
Euler and Complexity Theorem: A planar graph with V vertices has at most 3(V - 2) edges and at most 2(V - 2) faces. Idea: add extra edges and faces to make resulting graph easier to reason about. Proof: First, make new graph G(V,E’) Triangulate the graph. For each face that is bounded by more than three edges (or whose boundary is not connected) add new edge. Repeat until every face in the graph is bounded by exactly three edges. New graph has E’ edges and F’ faces. E' >= E and F' >= F
Resulting graph G(V,E’) has: • one connected component, • every face is bounded by exactly three edges, • each edge has a different face on either side of it. • Every face has 3 edges • So the number of “face bounding edges” is 3F’ • Every edge is part of 2 faces. • So number of “face bounding edges” is 2E’ • So 3F’ = 2E’, or… E’ = 3F’/2 • Euler's formula • Using: E' = 3F’/2 we have • V + E' - F' = 2, • V - 3F'/2 + F' = 2, • F’ = 2(V-2) • F <= F' = 2(V - 2); • F <= 2(V-2) • Using: F' = 2E' / 3 we have • V + E' - F' = 2, • V - E' + 2E'/3 = 2, so • E <= E' = 3(V - 2): • E <= 3(V - 2)
“A planar graph with V vertices has at most 3(V - 2) edges and at most 2(V - 2) faces” Why do we care? For planar graph, doing something a constant number of times for each edge, or a constant number of times for each face remains O(n).
Enough Theory… We require a convenient and efficient way to represent a planar subdivision. • Components in the planar subdivision: • Vertices, edges, faces • Data structure focus on preserving adjacency relationships between components, (but each could have a pointer to additional information).
Crazy Names v7 v2 v1 • Winged Edge Data Structure. • Quad Edge Data Structure. • Our focus on “Doubly Connected Edge List”. e’s twin f1 v3 e v6 f0 e0,1 v5 e4,0 v0 v4 • Every edge e is struct: • e.org, e.dest: pointer to origin and dest vertices. • e.face is face on left of edge • e.twin is the same edge, oriented the other direction. • e.next is next edge along the face [DCEL: doubly connected edge list] • represent edge as 2 halves • lists: vertex, face, edge/twin • facilitates face traversal
Crazy Names v7 v2 • Every edge e is struct: • e.org, e.dest: pointer to origin and dest vertices. • e.face is face on left of edge • e.twin is the same edge, oriented the other direction. • Each Face has a pointer to one edge of that face. • Each vertex has pointer to one edge away from that vertex. v1 e’s twin f1 v3 e v6 f0 e0,1 v5 e4,0 v0 v4 • Pop quiz. • How to enumerate all edges of a face? • How to enumerate all edges incident on a node?
Given two planar subdivisions, S1 and S2 , and we want to compute their overlay. • Overlay is a subdivision whose vertices are the union of the vertices + intersection of edges in S1 and S2. • S1 and S2 are planar, so all intersections are one edge from S1 and one edge from S2 • If each subdivision is represented using a DCEL, can we adapt the plane sweep algorithm update the DCEL (rather than just report intersections?) • First, build the edge and vertex records for the new subdivision. • Then fix up the faces. Faces are harder because we don’t know what faces there are without looking ``into the future'‘.
Important case is when sweep processes an intersection event. Given two intersecting segments, select edge pointers to a1 and b1 that go “forward” across the sweep line. a1 a1.twin V • Create: V b1 b1.twin
Given two intersecting segments, select edge pointers to a1 and b1 that go “forward” across the sweep line. a1 a1.twin V • Create: V a2 • Split edge a1 at V to create a1 and a2: • a2.dest = a1.dest • a2.org = V • a1.dest = V • a1.twin.org = V • a2.twin.dest = V • a2.twin.org = a2.dest a2.twin • Every edge e is struct: • e.org, e.dest: pointer to origin and dest vertices. • e.face is face on left of edge • e.twin is the same edge, oriented the other direction. • e.next is next edge along the face
Given two intersecting segments, select edge pointers to a1 and b1 that go “forward” across the sweep line. a1 b2 a1.twin b2.twin V • Create: V a2 b1 • Split edge a1 at V to create a1 and a2: • a2.dest = a1.dest • a2.org = V • a1.dest = V • a1.twin.org = V • a2.twin.dest = V • a2.twin.org = a2.dest b1.twin a2.twin • Every edge e is struct: • e.org, e.dest: pointer to origin and dest vertices. • e.face is face on left of edge • e.twin is the same edge, oriented the other direction. • e.next is next edge along the face
a1 b2 a1.twin b2.twin V a2 b1 • Fix up the “next” pointers. • A1.next = ? b1.twin a2.twin • Every edge e is struct: • e.org, e.dest: pointer to origin and dest vertices. • e.face is face on left of edge • e.twin is the same edge, oriented the other direction. • e.next is next edge along the face
Hints. • If line is always left turning, and the initial point “p” is (and always has been) on the left of the current segment, then there is no possible intersection. • Keep track of “ranges of vulnerability” • Inside vulnerability • Outside vulnerability • Calculate work in terms of how often each edge is tested, not how much work is done when looking at next segment. Inside vulnerable p0 Outside vulnerable
Hints 2 • Can have a circular sweep line. • Need to define what the sweep line keeps and what are events. • Need to show how to process each event. • Do this processing lead to a new event?
Next class • Read Chapter 3! • Art gallery theorem.