Slide 4

advertisement
COSC 6114
Prof. Andy Mirzaian
References:
• [M. de Berge et al] chapter 3
• [Preparata-Shamos’85] chapter 6
• [O’Rourke’98] chapter 1
Applications:






Graphics: Ray Shooting
Robotics: Geodesic Shortest Paths inside polygon, visibility
GIS: Planar Point Location
GIS: Elevation estimate on polyhedral terrain:
GIS: Piece-wise linear interpolation of bi-variate function f(x,y).
...
Polygon Triangulation
Guarding and Art Gallery
Art Gallery Problem [Victor Klee 1973]
How many camera guards do we need to guard a given gallery and
how do we decide where to place them?
• It’s NP-hard to determine the MINIMUM number of camera guards for
an arbitrary given simple polygon [Aggarwal 1984].
• Let P be an n-vertex simple polygon.
• If P is convex, then a single guard anywhere inside P is sufficient.
• n guards for P are always sufficient; one guard at each vertex.
[This does not work for 3D polytopes!]
• Can we use less than n guards? Yes. Use Triangulation of P.
A simple polygon P
A triangulation of P
Dual Tree of the Triangulation
Diagonal of a simple polygon P: Any line-segment between two
non-adjacent vertices of P that is completely inside P.
no
yes
LEMMA 1 Any simple n-gon with n>3 admits at least one diagonal.
Such a diagonal can be found in O(n) time.
Proof: Let x be any convex vertex of the polygon
(e.g., an extreme vertex, say, the lowest-leftmost).
(case a) yz is a diagonal
(case b) xw is a diagonal
y
y
x
x
w
z
z
[Shaded triangle does not contain any vertex of the polygon]
THEOREM 2 Any simple n-gon P admits at least one Triangulation.
Such a triangulation T can be computed in O(n2) time.
Any such triangulation has n-3 diagonals, and n-2 triangles.
Proof: By induction on n.
Basis (n=3): Obvious.
Ind. Step (n>3): By previous Lemma, a diagonal d of P exists and can be found in
O(n) time, and divides P into simple polygons P1 & P2 with, say, n1 & n2 vertices,
where d is an edge of both. Note, n = n1+n2 -2.
Triangulations T1 & T2 of P1 & P2 can be obtained recursively.
Now set T = T1T2 with d as an extra diagonal.
Total computation time: Time(n) = Time(n1) + Time(n2) + O(n) = O(n2).
By induction hypothesis:
T1 has n1–3 diagonals and n1–2 triangles,
T2 has n2–3 diagonals and n2–2 triangles,
These imply:
T has n–3 diagonals and n–2 triangles.
d
P1
P
P2
THEOREM 3 [Chvătal 1975, Fisk 1978]
n/3 guards are always sufficient and sometimes necessary to
guard any simple n-gon.
Proof: Necessity:
Sufficiency:
1.
T = a triangulation of the n-gon.
2.
3-colour vertices of T (so that the vertices of each triangle get 3 different colours).
This can be done (implicitly) by a DFS traversal on the dual tree of T.
3.
Choose a colour least often used (break ties arbitrarily).
4.
Place a guard at the vertices of the chosen colour. (Each triangle has a guard.)
B
G
R=4
B=3
G=4
R
R
G
R
B
G
R
B
G
Geodesic Shortest Paths inside polygon
Geodesic Shortest Paths inside polygon
A
B
A shortest path: Walk along the path of the dual tree from
triangle of A to B.
Geodesic Shortest Paths inside polygon
source
Single-source shortest paths: Do a DFS on dual tree of the triangulation
and maintain the visibility funnel for frontier diagonals.
Geodesic Shortest Paths inside polygon
source
Single-source shortest paths
Geodesic Shortest Paths inside polygon
source
Single-source shortest paths
Simple Polygon Triangulation Algorithms
• O(n2) time
See Theorem 2. Also by “ear removal”, Lennes 1911.
• O(n log n)
Garey-Johnson-Preparata-Tarjan (plane sweep) 1978.
• O(n log log n)
Tarjan-van Wyk (balanced-cut & Jordan-sort) 1986-88.
• O(n log* n) randomized
Clarkson-Tarjan-van Wyk 1989.
• O(n)
Chazelle 1991. [Complicated. Can it be simplified?]
• O(n) randomized
Amato-Goodrich-Ramos 2000. [See LN15]
A possible generic candidate for simpler & efficient polygon triangulation algorithm:
• via pseudo-triangulations
Mirzaian 1988 [See LN14]
Garey-Johnson-Preparata-Tarjan
• FACT: P is y-monotone if and only if it does not have any cusps.
• A monotone polygon can easily be triangulated in linear time.
• Subdivide the simple polygon into monotone sub-polygons by adding diagonals to cusps.
y
y
y
x
y-monotone
x
Cusp: concave local y-min or y-max vertex.
x
3 y-monotone sub-polygons.
Garey-Johnson-Preparata-Tarjan
How to partition the polygon into monotone sub-polygons by adding suitable diagonals
Garey-Johnson-Preparata-Tarjan
How to partition the polygon into monotone sub-polygons by adding suitable diagonals
1.
Trapzoidize using plane sweep in O(n log n) time.
Garey-Johnson-Preparata-Tarjan
How to partition the polygon into monotone sub-polygons by adding suitable diagonals
1.
2.
Trapzoidize using plane sweep in O(n log n) time.
Remove visibility chords outside polygon.
Garey-Johnson-Preparata-Tarjan
How to partition the polygon into monotone sub-polygons by adding suitable diagonals
1.
2.
3.
Trapzoidize using plane sweep in O(n log n) time.
Remove visibility chords outside polygon.
Add one supporting diagonal (if any) per trapezoid.
These diagonals eliminate cusps and subdivide
polygon into y-monotone sub-polygons.
Garey-Johnson-Preparata-Tarjan
How to partition the polygon into monotone sub-polygons by adding suitable diagonals
1.
2.
3.
4.
Trapzoidize using plane sweep in O(n log n) time.
Remove visibility chords outside polygon.
Add one supporting diagonal (if any) per trapezoid.
These diagonals eliminate cusps and subdivide
polygon into y-monotone sub-polygons.
Ignore visibility chords.
Garey-Johnson-Preparata-Tarjan
How to partition the polygon into monotone sub-polygons by adding suitable diagonals
1.
2.
3.
4.
5.
Trapzoidize using plane sweep in O(n log n) time.
Remove visibility chords outside polygon.
Add one supporting diagonal (if any) per trapezoid.
These diagonals eliminate cusps and subdivide
polygon into y-monotone sub-polygons.
Ignore visibility chords.
Triangulate each y-monotone sub-polygon in
total O(n) time. [See next slides.]
17
Triangulating a y-monotone polygon
16
• Merge y-sorted left & right boundary chains of
the polygon to obtain the y-sorted vertex list.
15
• Advance along y-sorted vertex-list:
14
 An “uncapped” chord (edge or diagonal) is one
that is considered but doesn’t yet have an
incident triangle above. These chords form a
13
concave chain.
12
11
 For each vertex v in y-sorted order, add
downward visible chords and triangles from v to
uncapped visible diagonals, starting from most
recent & backwards. (Use a stack. See next
slide.)
10
9
8
7
6
4
y
5
3
2
x
1
Algorithm Triangulate y-monotone polygon P
• merge the vertices of the left and right chains of P into y-sorted order, say, u1, u2, … , un.
• push u1 and u2 into an initially empty stack S.
• for j 3 .. n-1 do
if
uj & top(S) are on different chains
then pop all vertices from S and add a diagonal between uj and each popped
vertex except the last.
push uj-1 and uj onto S.
else pop(S)
pop the other vertices from S while they are visible from uj, and add
a diagonal between uj and each popped vertex.
push last popped vertex back onto S.
push uj onto S.
• add diagonals from the last vertex un to all stack vertices except first and last.
end
A straight-line planar subdivision with n vertices can be triangulated in O(n log n)
time and O(n) space.
Use the same approach: plane-sweep; trapzoidize; monotonize; and triangulate the
resulting monotone polygons.
This approach can also triangulate a polygon with polygonal obstacles inside,
in O(n log n) time (applications in robotics).
THEOREM 4
[Art Gallery Theorem for polygons with holes]
A polygon P with h polygonal holes and n vertices (including vertices of the holes)
can be guarded with (n+2h)/3 guards.
Proof: Triangulate P. Dual graph is not a tree.
Use h of the diagonals to connect the holes and the outer boundary of P.
Double-up these h diagonals to open up narrow corridors.
We now have a simple polygon with n+2h vertices. Now apply Theorem 3.
If you do a DFS of the
non-tree dual graph,
you get a DFS tree,
plus h back-edges.
How can you deal with
these back-edges that
would correspond to
opening corridors?
Jordan Sorting
Suppose line L and an unknown Jordan curve J intersect at k points X = {x1 , x2 , … , xk }.
Given X in sorted order along J, obtain X in sorted order along L.
[Hoffman-Mehlhorn-Rosenstiehl-Tarjan 1986]
show how to do this in O(k) time using an efficient finger-search tree data structure.
(Complexity of the unknown J could be much larger than k.)
J
x8
x7
x6
x2
x1
x3
x4
x5
x12
x10
x9
x11
L
O(n log log n) time polygon Triangulation: Tarjan–van Wyk 1988
v
L
Exercises
1.
Give a simple linear time algorithm to triangulate any given star polygon.
Assume a kernel point of the polygon is available.
2.
Guarding the walls: Construct a simple polygon P and a placement of guards such
that every boundary point of P is seen by some guard, but there is at least one point
interior to P not seen by any guard.
3.
Visibility: Consider an arbitrary simple polygon P. Two points a and b in P are visible
from each other if the line-segment ab does not intersect the exterior of P.
(a) Prove or disprove: Let v be any point in P such that every vertex of P is visible
from v. Then every point in P is also visible from v.
(b) Prove or disprove: Let v and w be any pair of points in P such that every vertex
of P is visible from v or w. Then every point in P is also visible from v or w.
4.
Suppose that a simple polygon P with n vertices is given, together with a set of
diagonals that partitions P into convex quadrilaterals. How many point guards are
sufficient to guard the interior of P? Why doesn't this contradict the Art Gallery
Theorem 3?
5.
Balanced Split: Let P be any simple polygon with n vertices. A diagonal d of P is said
to be a balanced diagonal, if it splits P into two simple polygons, each with at most
2n/3 + 1 vertices.
(a) Show that any simple polygon has a balanced diagonal.
(b) Show the bound 2n/3 + 1 is tight, i.e., for every n>2, there are simple n-gons
that have no diagonal that splits the polygon with both sides containing less than
2n/3 + 1 vertices each.
(c) Give an O(n log n) time algorithm to find a balanced diagonal of P. [Hint: Use the
dual graph of a triangulation. This has applications in divide-&-conquer algorithms.]
6.
Polygon Area: Prove the following fact about the algebraic area of a simple
polygon as stated in the introductory Lecture Slide 1:
2A (P) 
n
  ( O, p , p
i 1
i
i 1
n
n
i 1
i 1
)   ( x i y i 1  x i 1 y i )   x i ( y i 1  y i 1 )
( where O  origin , p n 1  p1 , p 0  p n ).
7.
Polygon Triangulation by Horn Cutting:
We are given a simple n-gon P = [ p0 , p1, ..., pn-1]. We want to find a triangulation
T(P) of P by a horn-cutting method. A horn of P is any vertex pi of P, such that
(the interior of) P contains (the interior of) triangle (pi-1 , pi , pi+1) formed by pi and
its two neighboring vertices pi-1 and pi+1 (index arithmetic is done mod n). We can
cut this horn by removing vertex pi from the sequence of polygon vertices,
resulting in a sub-polygon P' with n-1 vertices. The line-segment (pi-1 pi+1) now
becomes an edge of the new polygon P'. We say we have cut the horn pi (or the
horn-triangle (pi-1 , pi , pi+1) from the simple polygon P).
(a) Argue that the sub-polygon P' that results from cutting a horn of P is itself a
simple polygon (i.e., it has a non-self-crossing boundary).
(b) Prove that any simple polygon P with n >3 vertices has at least two horns.
(c) Algorithmically show how in O(n) time we can test whether a given vertex pi is
a horn of P.
(d) Design and analyze an O(n2) time algorithm to compute a triangulation T(P)
of simple polygon P by an iterative horn-cutting process.
8.
Diagonal Flip in Polygon Triangulation: Let P be a simple polygon with n vertices
and T a triangulation of P. Consider a diagonal D=(a,b), incident to two triangles
(a,b,c) and (a,b,d) in T. The union of these two triangles is the quadrangle (a,c,b,d).
If this quadrangle is convex, then we can flip D to obtain the new diagonal D’=(c,d).
This creates a new triangulation T’ where the two triangles (a,b,c) and (a,b,d) are
replaced by the two new triangles (c,d,a) and (c,d,b). (See the figure below.). Note
that flipping is reversible, i.e., you can go from T’ back to T by flipping D’.
Let T and T’ be two arbitrary triangulations of P. We say T is flip-connected to T’, if
there is a sequence of zero or more diagonal flips that transforms T to T’. Let the
flip-distance, denoted FD(T,T’), be the minimum number of flips required to
transform T to T’. FD(T,T’) = if T and T’ are not flip-connected. Flip-connectivity is
an equivalence relation on the set of triangulations of P. So, it partitions the set into
equivalence classes. (Can there be more than one equivalence class?)
(a) Show that if P is a convex polygon, then T,T’, FD(T,T’) = O(n).
(b) What if P is a simple polygon? Can there be a pair T, T’ such that FD(T,T’) =?
Why or why not? If not, then derive a tight asymptotic upper-bound on FD(T,T’)
over all triangulation pairs T and T’ of P.
a
a
c
b
D
flip D
d
c
b
D’
d
9.
Geodesic in a Simple Polygon: The following problem has a number of
applications including robot path planning.
We are given a simple n-gon P and a triangulation T of P. The triangulation is
given by its list of triangles, and their incidence relationship, where two triangles
are incident iff they share a common diagonal. We are also given two points a
and b inside P. The problem is to find the shortest path from a to b inside P. Such
a path is called the geodesic between a and b inside P (see the figure below).
Design and analyze an O(n)-time algorithm to solve this problem.
[Hint: after locating the triangles that contain a and b, "walk" along the triangles
from a to b (which way?), while maintaining the two shortest paths from a to the
two ends of the next diagonal on the walk. These two shortest paths form a funnel
that encloses a prefix of the final geodesic. Carefully analyze how you update the
funnel as you advance from one diagonal to the next on your "walk".]
a
b
10. Polygon Area Bisection: We are given a simple n-vertex polygon P in the plane.
We already know how to compute the area of polygon P in O(n) time.
(a) The problem here is to find a vertical line L such that the area of P in the left halfplane defined by L is equal to the area of P in the right half-plane defined by L
(Fig. (a)). Describe an O(n log n) time algorithm to solve this problem by the
plane sweep method.
(b) Develop an O(n) time algorithm to solve the above problem provided that we
are already given TZ(P), the trapezoidization of the interior of P (Fig. (b)).
(c) Can you solve the problem in O(n) time without the use of TZ(P) and without
using any preprocessing algorithm that constructs a triangulation or
trapzoidization of P? [Hint: Let A(x) denote the area in P to the left of the vertical
line with x-coordinate x. Study the function A(x) and its derivative, and use
prune-&-search.]
(d) Prove or disprove: Any simple polygon can be cut in two equal area subpolygons by a single straight line-segment s whose end points are on the
boundary of P but s does not intersect the exterior of P (Fig. (c)).
L
P
P
P
s
(a)
(b)
(c)
END
Download