Feb 2011 1
Polygon Triangulation
Shmuel Wimer
Bar Ilan Univ., School of Engineering
Feb 2011 2
Definitions
0 1 1 1, , , , vertices of an -vertex polygon.n nv v v v n
0 0 1 1 1 1 0
1 1
Edges , , , , are
bounding a polygon by a simple closed curve iff:
, 0, , 1, and , 1.
i i i n n
i i i i j
e v v e v v e v v
e e v i n e e j i
Every simple closed plane
curve divides the plane into two components.
Jordan Curve theorem :
Feb 2011 3
There are no holes in a simple polygon.
Simple polygon
Nonsimple polygons
Feb 2011 4
The Art Gallery Problem
How many stationary guards are needed to guard a room?
Guards are located at fixed points and have 2π range of
visibility. A guard cannot see through walls.
Given a polygon , a point can see a point ( is visible
from ) iff [ , ] .
P x y y
x x y P
A set of guards covers a polygon if every point of the
polygon is visible to some guard.
Problem: Find the max over all n-vertex polygons of the
min number of guards needed to cover the polygons.
Feb 2011 5
This 12-vertex polygon
needs 4 guards to cover it
This 12-vertex polygon
needs 3 guards to cover it.
Feb 2011 6
- smallest number of guards needed to cover .
min | : covers | .S
g P P
g P S S P
- maximum of over all -vertex polygons.
max .n
n
nP
G n g P n
G n g P
G nWhat is ?
A trivial lower bound:
A trivial upper bound:
1G n
.
Put a guard at each vertex.
G n n
Feb 2011 7
What is 3 ?G 3 1.G
What is 4 ?G
4 1. Put a guard on internal diagonal.G
5 1. Put a guard at overlap of triangles.G
Feb 2011 8
Hexagons may require two guards, 6 2.G
3 ?G n n Is the conjecture true
A shape with prongs, 3 , is covered by guards.k n k k
12, 4
4
n k
g P
Feb 2011 9
3G n n Proving
First Proof of sufficiency is due to Chvátal in 1975 (very
complex). We’ll present a simple, four-step proof by Fisk
from 1978.
Necessity follows from the prong’s example.
1. Triangulation of polygon.
2. 3-coloring of triangulation graph.
3. Placing guards at a single color guarantees cover.
4. “Pigeon-hole principle”: placing n objects in k holes,
one at least contains no more than └n/k┘ objects.
Feb 2011 10
Diagonals and Triangulation
A diagonal of a polygon is a line segment connecting two
visible vertices.
[ , ] is a diagonal of iff:
[ , ] , and ( , ) \ .
a b P
a b P a b a b P P
Diagonals [ , ] and [ , ] are called noncrossing if
( , ) ( , ) .
a b c d
a b c d
Triangulation: the partition of a polygon by maximal non
crossing diagonals into triangles (not unique!).
Feb 2011 11
n=14
Interesting, both
triangulations have
same number of
diagonals!
Notice that number
of diagonals equals
n-3.
Feb 2011 12
3-Coloring
G(V,E) is a graph defined on a triangulated polygon P.
E consists of P’s edges and the triangulation diagonals,
while V consists of P’s vertices.
k-coloring is an assignment of k colors to the vertices
of V such that no adjacent vertices have same color.
We’ll show later that a triangulation graph is 3-colorable.
Feb 2011 13
5
4
5
6
3
5
The coloring of a
triangulation
graph is unique!
Assigning color to
first vertex
enforces the rest
color assignments.
Feb 2011 14
Guards Placement
It is sufficient to place guards at one color only (say red).
This follows since every triangle must have 3 distinct
colors at its corners, hence one must be red. Therefore
every triangle is covered.
But the triangles cover the entire polygon P.
Pigeon-hole principle: There must be one color whose
number of assigned vertices doesn’t exceed └n/3┘.
3n Conclusion : guards are sufficient.
Feb 2011 15
Triangulation Theory
Need to prove that every polygon can be triangulated.
Though intuitive, proof is not trivial.
Lemma: Every polygon must have at least one strictly
convex vertex.
Proof: Let the vertices be
counterclockwise ordered.
Traversing the boundary, a
convex vertex corresponds
to a left turn.v L
Feb 2011 16
Pick the lowest vertex (pick the rightmost If there are few).
L is a line passing through v.
The edge following v must lie above L. ■
Lemma: Every polygon of n≥4 vertices has a diagonal.
Proof: There exists a strictly convex vertex v. Let a and b
be vertices adjacent to v.
If [a,b] is a diagonal we are done. So assume it is either
exterior or intersecting with the boundary of P.
Feb 2011 17
v
ab
L
x
must contain at
least one vertex of .
avb
P
Let be the closest
vertex to , measured
orthogonal to the line
passing through .
x
v
ab
The interior of cannot contain any point of .cvd P
dc
Therefore [ , ] , , hence a diagonal. x v P x v ■
Feb 2011 18
Theorem: Every n-vertex polygon P can be triangulated.
Proof: By induction on n.
If n=3 P is a triangle.
Let n≥4. By lemma, P has a
diagonal d which divides P into
two polygons P1 and P2, having
n1<n and n2<n vertices, resp.
P1 and P2 can be triangulated by
induction hypothesis. ■
d
Feb 2011 19
Question: Are all triangulations have the same
number of diagonals and triangles?
Lemma: Every triangulation of an n-vertex polygon P
has n-3 diagonals and n-2 triangles.
Proof: By induction on n.
For n=3 the claims are trivially true.
For n≥4, divide P by a diagonal d into P1 and P2, having
n1<n and n2<n vertices, resp.
n1+n2 = n+2 since the end vertices of d are duplicated.
Feb 2011 20
It follows from the induction hypothesis that the claims
hold for n1-vertex and n2-vertex polygons.
The total number of diagonals (n1-3)+(n2-3)+1=n-3,
where +1 stands for counting d.
The number of resulting triangles is (n1-2)+(n2-2)=n-2.■
Corollary: The sum of internal angles in an n-vertex
polygon is (n-2)π.
Proof: Polygon is covered by n-2 triangles, whose
corners are placed at polygon’s vertices.
Feb 2011 21
Triangulation Dual
An arc exists between two vertices iff the corresponding
triangles are adjacent.
A vertex is placed in every triangle.
Feb 2011 22
Lemma: The dual T of a triangulation of a simple
polygon P is a tree whose vertex degree is 3 at most.
Proof: Degree claim follows immediately from the fact
that a triangle has three sides at most to share.
Assume in contrary that T is not a tree. It then must
have a closed cycle C, completely contained in P.
C must enclose a vertex of P, which is the end point
of a diagonal crossing C.
Feb 2011 23
P must therefore have a hole, thus contradicting its
simplicity. ■
CBorder vertices
Completely in P
Feb 2011 24
Vertices of degree 1 are leaves of T. Vertices of degree
2 lie on T’s paths. Vertices of degree 3 are branches.
When rooted at a vertex of degree 1 or 2, T is a binary.
Definition: Three successive vertices a, b, c of a polygon
form an ear if ac is a diagonal, while ab and bc are not.
Theorem: A polygon with n≥4 has two nonoverlapping
ears at least.
Proof: A leaf of the dual tree T implies an ear. T has
n-2 ≥2 vertices, at least 2 of which are leaves. ■
Feb 2011 25
3-Coloring Theorem
Theorem: The triangulation graph of a simple n-vertex
polygon P is 3-colorable.
Proof: By induction on n.
P has an ear. Ear removal obtains an (n-1)-vertex
polygon, which by induction hypothesis is 3-colorable.
The end vertices of the ear’s base (diagonal) are adjacent
vertices of P and thus have two distinct colors. The tip of
the ear is then colored with the third color. ■
Feb 2011 26
We are done!
Feb 2011 27
Area of Polygons
3Let , , , and ,
, be two vectors. The
area of the parrallelogram
defined by and is .
a b c b a
c a
Α
B
Α B Α B
R
a b
c
A
B
Determinant
notation:.
y z z y xx y z
x y z z x x z y
x y z x y y x z
A B A B
A A A A B A B
B B B A B A B
uu u u
u
u
Feb 2011 28
2In 0, so the area of a triangle is:
1
21
21
.2
z z
x y y x
x x y y y y x x
x y y x y x x y x y y x
A B T
T A B A B
b a c a b a c a
a b a b a c a c b c b c
R
A
Area of polygons can be found by triangulation and
calculation of triangles areas.
We’d like to obtain a closed-form formula, independent
of triangulation.
Feb 2011 29
0 1 2 0 2 3 0 2 1, , , , , ,n nP v v v v v v v v v A A A A
A(P)’s expression depends on triangulation.
We’ll consider first quadrilaterals and show its area is
independent of triangulation.
0v 6v
5v
4v3v
2v
1v
7v
P
Feb 2011 30
d
ba
c
Q
d
ba
c
Q
, , , , , , , ,Q a b c a c d d a b d b c A A A A A
x y y x y x x y x y y x
x y y x y x x y x y y x
Q a b a b a c a c b c b c
a c a c a d a d c d c d
2A
Diagonal related terms are canceled out!
11 10
For any convex polygon: n
i i i iiP x y x y
2A
Feb 2011 31
What happens for non-convex
quadrilateral ?
v2
0 1 2 0 3 2
31 10
0 2
, , , ,
.
The terms involving cancel out.
i i i ii
A Q A v v v A v v v
x y x y
v v
v3
v1
v0
Let be a triangle whose vertices are
counterclockwise oriented, and a point in the plane,
then , , , , , , .
T abc
p
T p a b p b c p c a
Lemma :
A A A A
Q
Feb 2011 32
We’d like to obtain the area of a general simple polygon
in terms of its vertices only.
0 1 1
1 11 1 10 0
11 10
Let the vertices , , , , ,
be labled counterclockwise, defining a polygon ,
and let be an arbitrary point. Then
, ,
n i i i
n ni i i i i ii i
ni i ii
v v v v x y
P
p
P p v v x y x y
x x y y
Theorem :
A A
.i
T
a
b
c
p
Feb 2011 33
p
P is a polygon and p an arbitrary
point (internal or external). p’s
vertices are cyclically ordered
counterclockwise.
We can traverse the edges
along the border and consider
the triangles viewed from p.
The areas of rectangles counterclockwise oriented are
added while the clockwise ones are subtracted. This is
integration along the border (Green’s Theorem).
Feb 2011 34
2 1 0 1
By induction on . The case 3 was
shown before. has an ear. Assume w.l.o.g it is
, , , and obtain by \ .n n n
n n
P
E v v v P P E
Proof :
21 10
2 1 1 0 0 2
By induction hypothesis , , ,
and by lemma
, , , , , , .
nn i ii
n n n n
P p v v
E p v v p v v p v v
A A
A A A A
1
0 2 2 0
Since , and
, , , , , the theorem follows.
n
n n
P P E
p v v p v v
A A A
A A
Feb 2011 35
11 10
1
The proof of is obtained by
expanding the determinant expression of ' area
and canceling out the terms of and common
edge.
ni i i ii
n
x y x y
E s
E P
■
Feb 2011 36
Triangulation Complexity
There are 3 2 diagonal candidates.n n
4This is repeated 3 times, yielding total time.n O n
4
Implementing triangulation as in the existence theorem
requires time.O n
Cheking validity of a diagonal requires intersection test
against all edges and previously defined diagonals, which
takes time.O n
Feb 2011 37
Run time is reduced to O(n2) (Lennes, 1911) as follows.
Pick the leftmost vertex v of P and connect its two
neighbors u and w. Checking whether uw is a diagonal
takes O(n). If it is, the rest is (n-1)-vertex polygon.
If uw is not a diagonal, get x, the farthest vertex from uw
inside Δuvw. This takes O(n) time. vx is a diagonal dividing
P into P1 and P2, having n total number of vertices.
Recursive application of the above procedure consumes
total O(n2) time.
Can we do better?
Feb 2011 38
There is a type of polygons whose triangulation takes
linear time, called monotone.
Definition: P is monotone w.r.t to a line l if P intersects
with any line l’ perpendicular to l in a single segment, a
point or it doesn’t intersect.
ll’
l’
l’
l’
monotone
l’
l’
l’
l’
not monotone
Feb 2011 39
P
We’ll partition P into y-monotone pieces.
start vertex
end vertex
merge vertex
split vertex
regular vertex
On horizontal edge the
left vertex is considered
above the right one.
Feb 2011 40
Lemma: A polygon is y-monotone if it has neither split
vertices nor merge vertices.
Proof: If P is not monotone, there must exist a line l
intersecting P in more than a single segment. Let [p,q] be
its leftmost sub segment.
Follow the boundary of P starting
at q, where P is on the left. At
some point r we must cross l.
If r ≠ p then the highest vertex must be a split one.
P
p q r l
split vertex
Feb 2011 41
If r = p we follow the boundary
from q in opposite direction.
At some point r’ we must
cross l. r’ ≠ p as otherwise
it contradicts that P is not
monotone.
This implies that the lowest
encountered vertex must be
a merge one. ■
P
p r q r l
merge vertex
Feb 2011 42
P
Getting Rid of Split and Merge Vertices
Sort P’s vertices from top to
bottom. It takes O(nlogn)
time.
Apply scan line from top to
bottom to encounter vertices.
Diagonals are introduced at split and merge vertices.
Feb 2011 43
P
Scan line intersection with P’s boundary is stored in a left to right ordered balanced binary tree.
Insertion into and deletion from a tree takes O(logn) time. Neighbor query takes O(1) time.
Total time consumed by scanning is O(nlogn) time.
Feb 2011 44
At a split point we get the nearest left and right edges in O(1) time.
The last upper vertex is also stored (can be the top end of right or left edge).
This data suffices to decide on diagonal in O(1) time.P
It takes O(nlogn) time to split
P into monotone polygons.
Merge vertices are handled
similarly.
Feb 2011 45
The added diagonals are non intersecting
and partition into monotone polygons.P
Lemma :
The resulting partitions contain neither split
nor merge vertices, hence are monotone polygons.
Proof :
To see that the added diagonals are valid, we'll show
that an added segment niether intersects 's edges nor
previously added diagonals.
P
We'll consider a split vertex. Merge vertex is similar.
Feb 2011 46
iv
mv
je ke
Q
When was added it
couldn't intersect 's edge.m iv v
P
If it intersects, there are two cases. If an end vertex
of 's edge is inside it contradics is nearest to .m iP Q v v
Otherwise, the edge must cross , contrudiction to
and being the nearest left and right 's edges.j k i
Q
e e v
Feb 2011 47
Finally, a previously added diagonal must have its
end vertices above . We've showed that cannot
have any vertex of , hence intersection with
is impossible.
i
m i
v Q
P v v
■
Theorem: An n-vertex simple polygon can be partitioned
into y-monotone polygons in O(nlogn) time and O(n)
storage.
Feb 2011 48
P
1
3
2
4
5
6
7
89
1011
Triangulating y-Monotone Polygon (Sketch)
's vertices are sorted in
descending .
P
y
's boundary is traversed with
one leg on and one leg on
, by poping and pushing
vertices from
right
a st .
left
ack
P
Diagonals insertions are decided
according to stack's top status.
Feb 2011 49
Theorem: Strictly y-monotone n-vertex polygon can be
triangulated in linear time.
Theorem: (Gary et. al. 1978) A simple n-vertex polygon
can be triangulated in O(nlogn) time and O(n) storage.
The problem has been studied extensively between
1978 and 1991, when in 1991 Chazelle presented an
O(n) time complexity algorithm.