Jarvis March - Washington University in St. Louis

Download Report

Transcript Jarvis March - Washington University in St. Louis

Last Time:
Plane Sweep Algorithms,
Segment Intersection,
+ (Element Uniqueness)
Robert Pless, CS 546: Computational Geometry Lecture #3
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
Robert Pless, CS 546: Computational Geometry Lecture #3
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.
Robert Pless, CS 546: Computational Geometry Lecture #3
• 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.
Robert Pless, CS 546: Computational Geometry Lecture #3
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.
Robert Pless, CS 546: Computational Geometry Lecture #3
Counting elements of a PSLG
• 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.
Robert Pless, CS 546: Computational Geometry Lecture #3
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
Robert Pless, CS 546: Computational Geometry Lecture #3
• 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)
Robert Pless, CS 546: Computational Geometry Lecture #3
“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).
Robert Pless, CS 546: Computational Geometry Lecture #3
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).
Robert Pless, CS 546: Computational Geometry Lecture #3
Crazy Names
• Winged Edge Data
Structure.
• Quad Edge Data
Structure.
• Our focus on “Doubly
Connected Edge List”.
• 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
v2
v3
v1
f0 e
e4,0
v7
e’s f
1
twin
v0
e0,1
v6
v5
v4
[DCEL: doubly connected edge list]
- represent edge as 2 halves
- lists: vertex, face, edge/twin
-facilitates face traversal
Robert Pless, CS 546: Computational Geometry Lecture #3
Crazy Names
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.
v3
v1
f0 e
e4,0
v7
e’s f
1
twin
v0
e0,1
v6
v5
v4
Pop quiz.
-How to enumerate
all edges of a face?
-How to enumerate
all edges incident on
a node?
Robert Pless, CS 546: Computational Geometry Lecture #3
• 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'‘.
Robert Pless, CS 546: Computational Geometry Lecture #3
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
Robert Pless, CS 546: Computational Geometry Lecture #3
Given two intersecting
segments, select edge pointers
to a1 and b1 that go “forward”
across the sweep line.
a1
a1.twin
V
a2
Create: V
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
Robert Pless, CS 546: Computational Geometry Lecture #3
Given two intersecting
segments, select edge pointers
to a1 and b1 that go “forward”
across the sweep line.
a1
b2
a1.twin
V
Create: V
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
b2.twin
a2
b1
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
Robert Pless, CS 546: Computational Geometry Lecture #3
a1
b2
a1.twin
V
a2
b1
Fix up the “next”
pointers.
A1.next = ?
b2.twin
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
Robert Pless, CS 546: Computational Geometry Lecture #3
• 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
Inside
vulnerable
p0
– Calculate work in terms of how often
each edge is tested, not how much work
is done when looking at next segment.
Outside
vulnerable
Robert Pless, CS 546: Computational Geometry Lecture #3
• 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?
Robert Pless, CS 546: Computational Geometry Lecture #3
Next class
• Read Chapter 3!
• Art gallery theorem.
Robert Pless, CS 546: Computational Geometry Lecture #3