Fact 2.2 (CE2)
Three consecutive vertices
v
i
?
1
; v
i
; v
i
+1
of
P
form an ear of
P
i
1.
v
i
is a convex vertex;
2.
v
i
?
1
2
C
(
v
i
; v
i
+1
; v
i
+2
) and
v
i
+1
2
C
(
v
i
?
2
; v
i
?
1
; v
i
);
3. the closure of the triangle (
v
i
?
1
; v
i
; v
i
+1
) do es not contain any reex vertex of
P
.
We have implemented ear clipping according to b oth CE1 and CE2. Both have a
straightforward implementation that checks Condition (3) by a brute-force scan of all
segments, respectively of all reex vertices. For a
k
-gon with
r
reex vertices, the time
complexity of this check is
O
(
k
) for CE1, and
O
(
r
) for CE2. In Subsection 3.1, we will
discuss heuristics for decreasing the practical complexity of checking Condition (3).
The actual triangulation algorithm works as follows: After classifying the vertices of
P
as convex or reex, we check for every triple of consecutive vertices of
P
whether they
form an ear. Ears are marked and stored. (In Subsection 3.2 we will discuss the storage
and retrieval of ears in more detail.) Then the co de iteratively retrieves one of the stored
ears, clips it, and up dates the information on ears. It is well known that clipping the ear
v
i
?
1
; v
i
; v
i
+1
transforms a
k
-gon into a
k
?
1-gon, for which all previously determined ears
still are valid, except for up to two ears that involve
v
i
. (Since
v
i
got deleted,
v
i
?
2
; v
i
?
1
; v
i
and
v
i
; v
i
+1
; v
i
+2
cannot b e any ears of the new p olygon.) In addition,
v
i
?
2
; v
i
?
1
; v
i
+1
and
v
i
?
1
; v
i
+1
; v
i
+2
could now form ears and have to b e checked. The algorithm iteratively cuts
ears until the original
n
-gon has b een transformed into a 3-gon (i.e., a triangle), and the
last triangle of the triangulation is trivially known.
The correctness of the algorithm is established similar to other published ear-clipping
algorithms, cf. [31, 36]. As analyzed in [31, 47, 36], the worst-case complexity of this
algorithm is
O
(
n
2
) if CE1 is used for determining ears, and
O
(
n
(
r
+ 1)) if CE2 is used.
2.2 Ensuring Consistency
Before the ear-clipping pro cess starts, we sort the vertices of the polygon lexicographically,
rst according to
x
-co ordinates, and second according to
y
-co ordinates. A simple scan
through the array of sorted vertices reveals all true duplicates
2
, which are discarded in the
array. Then, by means of a binary search, every vertex of the p olygon gets assigned its
index in the sorted array of vertices. As a result, vertices that have identical coordinates
have the same index. (If desired by the application, we can now also delete any edge whose
start and end vertices are identical, i.e., zero-length edges.) In the sequel, whenever we
sp eak of the index of a vertex we will refer to its index in this sorted array.
A close insp ection of the computations required by the ear-clipping algorithm reveals
that one basic primitive op eration suces: all we need to do is to check whether some
vertex
v
i
is left of, on, or right of the oriented line through two other vertices
v
j
and
v
k
. As
usual, this primitive is implemented as the evaluation of the sign of a 3
3 determinant.
Care is taken that the evaluations are consistent. We always compute determinants
such that the index of the rst vertex is less than the index of the second vertex, which
in turn is less than the index of the third vertex. If this causes a change of the cyclic
order of the vertices then the sign of the resulting determinant is inverted. (Trivially, the
determinant is zero if any two indices of the vertices are identical.)
2
I.e., vertices which have identical co ordinates.
6