monotone polygoon

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Brute-Force Triangulation

1. Find a diagonal.
2. Triangulate the two resulting subpolygons recursively.

How to find a diagonal?

w w
leftmost
vertex v
v
u case 2
closest
case 1 to v
u

O(n) time to find a diagonal at every step.


Θ(n 2) time in the worst case.
Triangulating a Convex Polygon

Θ(n) time!

Idea:
monotone
Decompose a simple polygon into convex pieces.
Triangulate the pieces. as difficult
as triangulation
y-monotone Pieces
y-axis
y-monotone if any line perpendicular
highest
vertex to the y-axis has a connected
intersection with the polygon.

Stragegy:
walk always
downward or Partition the polygon into monotone
horizontal pieces and then triangulate.

lowest
vertex
Turn Vertex
Turn vertex is where the walk
from highest vertex to the lowest
vertex switches direction.

At vertex v
♦ Both adjacent edges are below.
v
♦The polygon interior lies above.

Choose a diagonal that goes up.


Five Types of Vertices
Point p = (x, y) is “below” a different point q = (u, v) if
q
y<v or y = v and x > p
q
p u.
Otherwise p is “above” q. 4 types of turn vertices
Start vetex: lies above its two neighbors and
has interior angle < π.

Split vetex: lies above its two neighbors and


has interior angle > π.
End vetex: lies below its two neighbors and
has interior angle < π.

Merge vetex: lies below its two neighbors and


has interior angle > π.

Regular vetex: the remaining vertices (no turn).


What happens if we rotate the polygon by π?
start vertices ⇔ end vertices split vertices ⇔
start vertices ⇔ merge vertices
end vertices
Local Non-Monotonicity
Lemma A polygon is y-monotone if it has no split or
merge vertices.
Proof Suppose the polygon is not y-monotone. We prove that it contains
a split or merge vertex.
split There exists a horizontal line l intersecting the polygon in >1 components,
vertex of which the leftmost is a segment between some vertices
exterior p (left) and q (right).
Start at q, traverse the boundary counterclockwise until
l it crosses the line l again at point r.
p q r

interior r=p interior


Traverse in the
p=r q r′ l
r≠p oppose direction
from q and crosses
The highest vertex during line l again at point r’.
the traversal from q to r The lowest point during this exterior
must be a split vertex. traversal must be a merge vertex. merge vertex
Partitioning into Monotone Pieces
The lemma implies that the polygon will have y-monotone
pieces once its split and merge vertices are removed.

♦ Add a downward diagonal at every merge vertex.

♦ Add an upward diagonal at every split vertex.

Use a downward plane sweep.

No new event point will be created except the vertices.

The event queue is implemented as priority queue (e.g., heap).

The next event found in time O(log n).


Removal of a Split Vertex
vi : split vertex
e j : edge immediately to its left.
ek ek : edge immediately to its right.
h(e i ) v
i
ej h(e i ): lowest vertex above vi
e i-1 ei
and between ej and ek .

or the upper vertex of


edge e j if such vertex does not
helper
exist.

Connect v i to h(e i ).
Removal of a Merge Vertex
Merge vertices can be handled the same way in an upward sweep
as split vertices in a downward sweep.
But why not all in the same sweep?

vi : merge vertex
vi e j : edge immediately to its left.
ej ek : edge immediately to its right.
ek
vm
vm : highest vertex below the
sweep line and between
e j and ek .

v m will replace vi as the helper of ej . Connect vi to v m .


Check if the old helper is a merge vertex and add the diagonal if so.
(The diagonal is always added if the new helper is a split vertex).
In case the helper of ej is not replaced any more, connect to its lower endpoint.
Sweep-Line Status
Implemented as a binary search tree.

Only edges to the left of the polygon interior are stored.

This is because we are only interested in edges to


the left of split and merge vertices.

Edges are stored in the left-to-right order.

With every edge e its helper h(e) is also stored.


DCEL Representation
Construct a doubly-connected edge list to represent the polygon.

n vertices + n edges + 2 faces (initially)

Add in diagonals computed for split and merge vertices.

Edges in the status BST and corresponding ones in DCEL


cross-point each other.

Adding an edge can be done in O(1) time.


The Algorithm
MakeMonotone(P)
Input: A simple polygon P stored in DCEL D.
Output: A partitioning of P into monotone subpolygons stored in D.
1. Q ← priority queue storing vertices of P
2. T ← ∅ // initialize the status as a binary search tree.
3. i ← 0
4. while Q ≠ ∅
5. do v i ← the highest priority vertex from Q // removal from Q
6. case v i of
7. start vertex: HandleStartVertex(vi )
8. end vertex: HandleEndVertex(vi )
9. split vertex: HandleSplitVertx(vi )
10. merge vertex: HandleMergeVertex(vi )
11. regular vertex: HandleRegularVertex(vi )
12. i←i+1
Handling Start & End Vertices
insert into T HandleStartVertex(v i )
1. T ← T ∪ { ei }
v5 v3
e5 v4 2. h(e i ) ← vi // set the
v6 e4 e3 helper
e6 e2 v1
v7 v2
v9 HandleEndVertex(v i )
v 8 e7 e1
e8 e15 1. if h(ei –1) is a merge vertex
v 14
e14 2. then insert the diagonal
e9
v 12 connecting vi to h(ei –1)
v 10 v 15
e10 e e13 in D
11
e12 3. T ← T – { ei -1 }
v 11
v 13
Handling Split Vertex
HandleSplitVertex(vi )
1. Search in T to find e j directly left of v i
v5 v3 2. insert the diagonal connect vi to h(e j )
e5 v4 into D
v6 e4 e3 3. h(e j ) ← v i
e6 e2 v1 4. T ← T + { ei }
v7 v2 5. h(ei ) ← vi
v9
v 8 e7 e1
e8 v 14 e15
e14
e9
v 12 v 15
v 10 e10 e
11 e13
e12
v 11
v 13
Handling Merge Vertex (1)
HandleMergeVertex(vi )
1. if h(ei –1) is a merge vertex
v5 v3 2. then insert the diagonal
e5 v4
v6 e4 e3 connecting vi to h(ei –1)
e6 v1 in D
e2
3. T ← T – { ei -1 }
v7 v2
v9 4. Search in T to find the edge e j
v 8 e7 e1
e8 e15 directly left of v i .
v 14
e14 5. if h(e j ) is a merge vertex
e9
v 12 then insert the diagonal
v 10 v 15
e10 e e13 connecting vi to h(ej )
11
e12 in D
v 11 6. h(e j ) ← v i
v 13
Handling Merge Vertex (2)
HandleMergeVertex(vi )
1. if h(ei –1) is a merge vertex
2. then insert the diagonal
connecting vi to h(ei –1)
ei–1 in D
3. T ← T – { ei -1 }
ej h(e j )
h(ei –1 ) 4. Search in T to find the edge e j
vi directly left of v i .
5. if h(e j ) is a merge vertex
then insert the diagonal
connecting vi to h(ej )
in D
6. h(e j ) ← v i
Handling Regular Vertices (1)
HandleRegularVertex(v i )
1. if the polygon interior lies to the right
of v i
v5 v3 2. then if h(e i –1) is a merge vertex
e5 v4
v6 e4 e3 3. then insert the diagonal
e6 v1 connecting vi to h(ei –1 )
e2
in D
v7 v2
v9 4. T ← T – { e i -1 }
v 8 e7 e1
e8 e15 5. T ← T + { ei }
v 14
e14 6. h(ei ) ← v i
e9
v 12 7. else search in T to find the edge e j
v 10 v 15
e10 e e13 directly left of vi .
11
e12 8. if h(ej ) is a merge vertex
v 11 then insert the diagonal
v 13 connecting v i to h(ej )
in D
9. h(e j ) ← vi
Handling Regular Vertices (2)
HandleRegularVertex(v i )
1. if the polygon interior lies to the right
of v i
2. then if h(e i –1) is a merge vertex
3. then insert the diagonal
connecting vi to h(ei –1 )
in D
ej 4. T ← T – { e i -1 }
vi 5. T ← T + { ei }
h(e j ) 6. h(ei ) ← v i
7. else search in T to find the edge e j
directly left of vi .
8. if h(ej ) is a merge vertex
then insert the diagonal
connecting v i to h(ej )
in D
9. h(e j ) ← vi
Correctness
Theorem The algorithm adds a set of non-intersecting
diagonals that partitions the polygon into
monotone pieces.

Proof The pieces that result from the partitioning contain no split
or merge vertices. Hence they are monotone by an
earlier
lemma.
We need only prove that the added segments are diagonals
that intersect neither the polygon edges nor each other.

Establish the above claim for the handling of each of the


five type of vertices during the sweep. (Read the textbook
on how to do this for the case of a split vertex.)
Running Time on Partitioning
MakeMonotone(P)
Input: A simple polygon P stored in DCEL D.
Output: A partitioning of P into monotone subpolygons stored in D.
1. Q ← priority queue storing vertices of P // O(n)
2. T ← ∅
3. i ← 0
4. while Q ≠ ∅
5. do v i ← the highest priority vertex from Q // O(log n)
6. case v i of
7. start vertex: HandleStartVertex(vi ) // O(log n) each case
8. end vertex: HandleEndVertex(vi ) // queries and updates
9. split vertex: HandleSplitVertx(vi ) // in O(log n) time and
10. merge vertex: HandleMergeVertex(vi ) // insertion of a diagonal
11. regular vertex: HanleRegularVertex(v i )// in O(1) time.
12. i←i+1

Total time: O(n log n) Total storage: O(n)

You might also like