3. What is a Polygon?
• Let v0, v1, v2…, vn-1 be n points in the plane.
• Let e0 = v0v1, e1 = v1v2…, ei = vivi+1…, en-1 = vn-1v0 be n
segments connecting the points.
• These segments bound a polygon if and only if
1. The intersection of each pair of segments adjacent in the
cyclic ordering is the single point shared between them: ei ∩
ei+1 = vi+1, for all i = 0…, n – 1.
2. Nonadjacent segments do not intersect: ei ∩ ej = Ф, for all j
≠ i + 1.
3. None of three consecutive vertices are collinear.
Note that all index arithmetic are modulo n.
3
6. Triangulation of a Polygon
• Definition: The decomposition of a polygon into a set of non
overlapping triangles.
• Example:
6
7. Research Problem
• The basic triangulation algorithm can triangulate a polygon in
O (n4) time and O (n2) space with 100% accuracy.
• Even though more efficient algorithms are available in
literature, they are not 100% accurate due to the use of
floating point arithmetic.
• A simple and 100% accurate triangulation algorithm is
proposed with O (n3) time and O (n) space.
7
9. A Diagonal of a Polygon
• If the intersection of line segment AB with ∂P is exactly the
set {A, B} and the line segment AB is nowhere exterior to the
polygon P then the line segment is called a diagonal of the
polygon.
9
10. Basic Triangulation Algorithm
• Triangulation Theorem: Every polygon P of n vertices may
be partitioned into triangles by the addition of (zero or more)
diagonals.
• The method suggested by triangulation theorem is an O (n4)
algorithm.
• There are nC2 = O (n2) diagonal candidates.
• Testing each diagonal candidate for diagonalhood costs O (n).
• Repeating this O (n3) computation for each of the n – 3
diagonals yields O (n4).
10
11. Triangulation Algorithms
• Naïve approach: O (n4)
• Lennes (1911): O (n2)
• Garey et al. (1978): O (n log n)
• Hertel & Mehlhorn (1983): O (n log r), r reflex
• Chazelle & Incerpi (1984): O (n log s), s sinuosity
• Tarjan & Van Wyk (1988): O (n log log n)
• Clarkson et al. (1989): O (n log* n), randomized
• Toussaint (1990): O (n + nt0), t0 int. triangs.
• Kirkpatrick et al. (1990): O (n log* n), bnded. ints.
• Chazelle (1991): O (n)
• Seidel (1991): O (n log* n), randomized
• Amato et al. (2001): O (n), randomized
11
13. Related Research Paper
K. R. Wijeweera, S. R. Kodituwakku (2016), Accurate, Simple,
and Efficient Triangulation of a Polygon by Ear Removal
with Lowest Memory Consumption, Ceylon Journal of
Science, Volume 45 (Issue 3), pp. 65-76.
13
14. An Ear of a Polygon
• Suppose P, Q, and R be three consecutive vertices of a
polygon.
• If PR is a diagonal then PQR is called an ear of the polygon.
14
15. Representation of the Polygon
• The variable points stores the number of vertices of the
polygon.
• The coordinates of the vertices of the polygon are stored
using two arrays x and y.
• Then (x[i], y[i]) denotes the ith vertex of the polygon where i
= 0, 1…, (points - 1).
15
16. Two Known Theorems
• Theorem 1: Every polygon of n ≥ 4 vertices has at least two
non-overlapping ears.
• Theorem 2: Every triangulation of a polygon P of n vertices
uses n – 3 diagonals and consists of n – 2 triangles.
16
Vertices = 5
Diagonals = 5 – 3 = 2
Triangles = 5 – 2 = 3
17. The Order of Vertices of a Triangle
• The vertices of the triangle: P1 (x1, y1), P2 (x2, y2), P3 (x3, y3).
• Let t = x1 * (y2 – y3) + x2 * (y3 – y1) + x3 * (y1 – y2).
• t = 0 ↔ (P1, P2, P3) are collinear.
• t > 0 ↔ (P1, P2, P3) are in anticlockwise order.
• t < 0 ↔ (P1, P2, P3) are in clockwise order.
17
t > 0 t < 0
18. Identifying the Convex Vertices of the Polygon
• None of three consecutive vertices of the initial polygon are
collinear by the definition of a polygon.
• Therefore, each convex vertex is strictly convex.
• That means, interior angle formed by each convex vertex is
less than π.
• Lemma: The lowest vertex of a polygon is strictly convex.
18
19. Identifying the Convex Vertices of the Polygon…
• There may be several lowest vertices.
• The function lv returns the index of one of those lowest
vertices.
19
20. Identifying the Convex Vertices of the Polygon…
• Let’s consider the polygon given below as an example.
• The function lv returns 0.
20
21. Identifying the Convex Vertices of the Polygon…
• The function ts returns the sign of value t when index of
middle vertex of three consecutive vertices is provided.
• The function isConvex returns 1 if the passed index
corresponds to a convex vertex.
• If ts (v) * ts (lv ()) > 0 then the vertex v and lowest vertex
have the same sign.
• If they have the same sign then vertex v is convex.
21
22. Identifying an Ear of the Polygon
• An ear should always be with a convex vertex.
• The triangles formed by those convex vertices with their two
neighboring vertices are considered.
• If such a triangle does not contain any of the vertices of the
polygon inside it then that triangle should be an ear.
22
23. Identifying an Ear of the Polygon…
• The function isEmpty returns 1 if the triangle formed by
vertex v does not contain any of the vertices of the polygon.
• The function tv returns the sign of value t. This saves lots of
computational cost.
• The keyword CONTINUE is used to avoid own three vertices
of the triangle.
IF ((i == v) OR (i == a) OR (i == b))
{
CONTINUE;
}
23
24. Identifying an Ear of the Polygon…
tsv = tv (v, a, b);
IF ((tsv * tv (v, a, i) ≥ 0) AND (tsv * tv (a, b, i) ≥ 0) AND (tsv *
tv (b, v, i) ≥ 0))
{
RETURN 0;
}
24
25. Pruning an Ear from the Polygon
• Once an ear was found then the algorithm prunes that ear
from the original polygon.
• This is done by function prune.
VOID prune (INTEGER v)
{
INTEGER i;
points = points - 1;
FOR (i = v TO (points - 1))
{
x[i] = x[i + 1];
y[i] = y[i + 1];
}
} 25
26. Pruning an Ear from the Polygon…
• The original polygon.
26
27. Pruning an Ear from the Polygon…
• After pruning one ear.
27
36. Time Complexity
• Let n be the number of vertices in the given polygon.
• It takes O (1) time to check whether a given vertex is convex
if the lowest vertex of the polygon is provided.
• It takes O (n) time to check whether a given convex vertex is
an ear.
• Altogether, it takes O (1) + O (n) = O (n) time to check
whether a given vertex is an ear.
• An ear is found at the end of the vertex array in the worst
case.
• Therefore, it takes O (n) * n = O (n2) time to find an ear in
the worst case.
• The pruning of an ear takes O (n) time and this squeezes to O
(1) when the ear is near at the end of the vertex array.
36
37. Time Complexity…
• Anyway, it takes O (n2) + O (1) = O (n2) time to prune an ear
from a polygon with n vertices.
• There are (n - 3) number of diagonals in the given polygon.
• An ear should be pruned in order to get a diagonal.
• Each step of pruning takes O (n2), O [(n - 1)2]…, O (42) time
complexities.
• Initially, finding the lowest vertex of the polygon takes O (n)
time.
• Therefore, the time complexity of the proposed algorithm is
O (n) + O (n2) + O [(n - 1)2] + O (42) = O (n3).
37
38. Space Complexity
• It takes n memory cells to hold x-coordinates and n memory
cells to hold y-coordinates.
• Altogether, it takes 2n memory cells to hold the input.
• The additional memory for computations is O (1).
• Therefore, the space complexity of the proposed algorithm is
O (n) + O (1) = O (n).
38
39. Accuracy
• The proposed algorithm uses integer arithmetic only for
computations.
• Thus, the precision error is avoided.
• The set of output coordinates is a subset of the set of input
coordinates.
39
40. Comparison
• The basic triangulation algorithm is the only algorithm that
uses integer arithmetic only.
• The other existing algorithms use floating point arithmetic
which leads to the precision error.
• The basic triangulation algorithm takes O (n4) time and O
(n2) space.
• The proposed algorithm uses integer arithmetic only and it is
better than basic triangulation algorithm both in time and
space.
40