59
POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Embed Size (px)

Citation preview

Page 1: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

POLYGON POLYGON

TRIANGULATIONTRIANGULATION THE ART GALERY PROBLEM

SİNEM GETİR2008-2009

COMPUTER GRAPHIC SEMINAR

FEBRUARY 4, 2009

Page 2: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

CONTENTSCONTENTS

Guarding and triangulationsGuarding and triangulations Can we do better?Can we do better? 3-Coloring3-Coloring The art galery theorem The art galery theorem Partitioning a polygon into monotone piecesPartitioning a polygon into monotone pieces Triangulating a Monotone polygon Triangulating a Monotone polygon

Page 3: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

The Art Gallery ProblemThe Art Gallery Problem

camera

How many cameras are needed to guard a gallery and How should they be placed?

Page 4: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Transform to a Geometric ProblemTransform to a Geometric Problem

Floor plan may be sufficient and can be Floor plan may be sufficient and can be approximated as a simple polygon.approximated as a simple polygon.

• A simple polygon is a region enclosed by single closed A simple polygon is a region enclosed by single closed polygonal chain that doesn’t self-intersect polygonal chain that doesn’t self-intersect

A camera’s position corresponds to a point in the A camera’s position corresponds to a point in the polygonpolygon

A camera sees those points in the polygon to A camera sees those points in the polygon to which it can be connected with an open segment which it can be connected with an open segment that lies in the interior of the polygonthat lies in the interior of the polygon• assuming we have omni-cam that sees all directionsassuming we have omni-cam that sees all directions

Page 5: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

55

Guards have a viewport of 360° A polygon is completely guarded, if every point within the polygon is guarded by at least one of the watchmen

Page 6: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Simple Polygon ModelSimple Polygon Model

Model the art gallery as a region bounded by some simple polygon (no self-crossing).

Regions with holes are not allowed.

convex polygonone camera

an arbitrary n-gon (n vertices)

Bad news: finding the minimum number of cameras for a given polygon is NP-hard (exponential time).

Page 7: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Triangulation Triangulation

Let P a simple polygon with n verticesLet P a simple polygon with n vertices We first decompose P into pieces that are We first decompose P into pieces that are

easy to guard, namely triangles.easy to guard, namely triangles. DEFİNİTİON:A decomposition of a polygon DEFİNİTİON:A decomposition of a polygon

into triangles by a maximal set of non-into triangles by a maximal set of non-intersecting diagonals is called a intersecting diagonals is called a triangulation triangulation of the polygon.of the polygon.

Triangulations are usually NOT uniqueTriangulations are usually NOT unique Many applications: visibility, robotics, Many applications: visibility, robotics,

mesh generation, point location etc.mesh generation, point location etc.

Page 8: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

TriangulationTriangulationTo make things easier, we decompose a polygon into pieces that areeasy to guard.

Draw diagonals between pair of vertices.

an open line segment that connects two vertices and lie in the interior of the polygon.

Guard the polygonby placing a camera in every triangle …

Page 9: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

99

• • •

• •

• •

• wv

u• • •

• •

• •

Does every simple polygon admit a triangulation?

If yes, what is the number of triangles?

Does any triangulation lead to the same number of triangles?

THE QUESTION…

Page 10: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Theorem 1 Every simple polygon has a triangulation. Any triangulation of a simple polygon with n vertices consists of exactly n – 2 triangles.

Proof By induction.

Trivial for n = 3.

Assume true for all m < n.

Existence

Let v be the leftmost vertex and u and w its two neighbors.

uw in the interior of P it is a diagonal.

u

v

wP

vw

uv

Otherwise, the triangle determined by u, v, w contains at least one vertex. Let v be the one closest to v. Then vv is a diagonal.

The diagonal splits the polygon into two (which by induction can be triangulated).

Page 11: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Proof Proof

Any diagonal splits P into two simple polygons with k and m vertices, respectively.

# triangles = n – 2

By induction these two subpolygons can be triangulated.

They are decomposed into k – 2 and m – 2 triangles, resp.

Vertices defining the diagonal occur in each subpolygon once.

Other vertices of P each occurs in exactly on one subpolygon.

Thus k + m = n + 2.

By induction, the triangulation of P has (k – 2) + (m – 2) = n – 2 triangles.

Page 12: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

A camera on a diagonal guards two triangles.

# cameras can be reduced to roughly n/2.

A vertex is adjacent to many triangles. So placing cameras at vertices can do even better …

Theorem1 shows that any simple polygon with n vertices can be guarded with n-2 cameras.

But placing a camera inside every triangle seems OVERKILL.

Page 13: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

3-Coloring 3-Coloring Idea: Select a set of vertices, such that any triangle has at least one selected vertex.

Assign each vertex a color: pink, green, or yellow.

Any two vertices connected by an edge or a diagonal must be assigned different colors.

Thus the vertices of every trianglewill be in three different colors.

If 3-coloring exists, place cameras at all vertices of the same color.

Choose the smallest color class to place the cameras.

n/3 cameras.

Page 14: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

A 3-Coloring AlgorithmA 3-Coloring AlgorithmA 3-coloring can be found through a graph traversal (such as DFS).

During DFS, maintain the invariant:

All polygon vertices of encounteredtriangles have been colored such thatno adjacent two have the same color.

Start DFS at any node of G.Color the three vertices of the corresponding triangle.

v

u

Suppose node v is visited from u.

Their triangles T(v) and T(u) are adjacent.

Only one vertex of T(v) is not colored. Its color is uniquely determined.

Since G is a tree, the other nodes adjacent to v have not been visited yet.Otherwise there exists a cycle (which contradicts that G is a tree.)

Apply the color to v.

Page 15: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

1515

Art gallery theoremArt gallery theorem

Theorem: For a simple polygon with n vertices, n/3 cameras are occasionally necessary and always sufficient to have every point in the polygon visible from at least one of the cameras.

Can we do better?

Page 16: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

THE WORST CASE SCENARIO…THE WORST CASE SCENARIO…

Page 17: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

A Worst CaseA Worst CaseA triangulated polygon can always be 3-colored.

Any simple polygon can be guarded with n/3 cameras.

a

n/3 prongs

There exists no position at which a camera can oversee two prongs.

n/3 cameras are needed.

The 3-coloring approach is optimal in the worst case.

Page 18: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Solution to the Art Gallery Problem

1. Triangulate a simple polygon with a fast algorithm.

DCEL representation for the simple polygon so we can visit a neighbor from a triangle in constant time.

2. Generate a 3-coloring by DFS (as presented earlier).

3. Take the smallest color class to place the cameras.

Page 19: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

THEOREMTHEOREM

Let Let PP be a simple polygon with n be a simple polygon with n vertices.A set of [n/3] camera vertices.A set of [n/3] camera positions in positions in PP such that any point such that any point inside inside PP is visible from at least is visible from at least one of the cameras can be one of the cameras can be computed in computed in OO(n logn) time.(n logn) time.

Page 20: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

PARTITIONING A POLYGON PARTITIONING A POLYGON INTO MONOTONE PİECESINTO MONOTONE PİECES

We have just seen that a We have just seen that a triangulation of P always exists.the triangulation of P always exists.the proof of that theorem is constructive proof of that theorem is constructive and leads to a recursive triangulation and leads to a recursive triangulation algorithm:algorithm:

Find a diagonal and triuanglate the Find a diagonal and triuanglate the two resulting subpolygons two resulting subpolygons recursively.recursively.

Page 21: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

… … The triangulation algorithm will The triangulation algorithm will take quadratic time in the worst take quadratic time in the worst case.case.

Can we do better?Can we do better?

Page 22: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Convex polygonConvex polygon

Pick one vertex of the Pick one vertex of the

Polygon and draw diagonals Polygon and draw diagonals

From this vertex to all other From this vertex to all other

vertices exceptvertices except

its neighbors.its neighbors.

This takes only linear time.This takes only linear time.

Page 23: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

For a non-convex polygon For a non-convex polygon unfortunately ,it is as difficult to unfortunately ,it is as difficult to partition a polygon into convex partition a polygon into convex pieces as it is to trianglate pieces as it is to trianglate it.Therefore we shall decompose it.Therefore we shall decompose P into P into so-called monotone so-called monotone pieces.pieces.

Page 24: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Monotone polygon Monotone polygon

A A polygonpolygon PP in the plane is called in the plane is called monotonemonotone with respect to a straight with respect to a straight line line LL, if every line orthogonal to , if every line orthogonal to LL intersects intersects PP at most twice. at most twice.

Page 25: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Line sweep(top down)Line sweep(top down) Vertices where the Vertices where the

direction changes direction changes downward<> are called downward<> are called turn vertices.turn vertices.

To have y-monotone To have y-monotone pieces ,we need to get rid pieces ,we need to get rid of turn vertices:of turn vertices:

When we encounter a turn When we encounter a turn vertex,it might be necessary vertex,it might be necessary to introduce a diagonal and to introduce a diagonal and split the polygon into piecessplit the polygon into pieces

We will not add diagonals at We will not add diagonals at all turn verticesall turn vertices

Page 26: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Types of Turn VerticesTypes of Turn Vertices

Start Vertex - its two neighbors lie below it and Start Vertex - its two neighbors lie below it and the interior angle < 180°the interior angle < 180°

End Vertex - its two neighbors lie above it and End Vertex - its two neighbors lie above it and the interior angle < 180°the interior angle < 180°

Split Vertex - its two neighbors lie below it and Split Vertex - its two neighbors lie below it and the interior angle > 180°the interior angle > 180°

Merge Vertex - its two neighbors lie above it and Merge Vertex - its two neighbors lie above it and the interior angle > 180°the interior angle > 180°

If we want to define the different types of turn vertices carefully,we should pay special attention to vertices with equal y-coordinate.We do this by defining the notions of “below” and “above” as follows ; a point p is below another point q if

x x or and , and p is above q if or and p p p p p

y y y y x y y y y x<p q q q q q q

Page 27: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

py y

q

VERTEX ONTOLOGYVERTEX ONTOLOGY

Page 28: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

The split and merge vertices are The split and merge vertices are sources of local non-monotonicity.The sources of local non-monotonicity.The following stronger stament is true.following stronger stament is true.

LEMMA:A polygon is y-monotone if it LEMMA:A polygon is y-monotone if it has no split vertices or merge vertices.has no split vertices or merge vertices.

Page 29: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Adding diagonalsAdding diagonals

* The partition p into y-* The partition p into y-monotone pieces , get rid of monotone pieces , get rid of split and merge vertices split and merge vertices

1.1. Add a diagonal going upward Add a diagonal going upward each split vertex.each split vertex.

2.2. Add a diagonal going Add a diagonal going downward from each merge downward from each merge vertex.vertex.

* Where do the edges go?* Where do the edges go?

Page 30: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

HelpersHelpers

Let helper helper(Let helper helper(eejj) ) be the lowest vertex be the lowest vertex above the sweep-line above the sweep-line

Such that the Such that the horizontal segment horizontal segment connecting the vertex connecting the vertex to to eejj lies inside P lies inside P

Page 31: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Removing Split Vertices Removing Split Vertices

For a split vertex For a split vertex vvii ,let ,let be the edge be the edge immediately to the left immediately to the left of it.of it.

Add a diagonal from Add a diagonal from vvii to helper to helper eej j

Page 32: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Removing merge vertex Removing merge vertex

For a merge vertex For a merge vertex vvii let let eej j be edge immediately to the be edge immediately to the left of itleft of it

vvii becomes helper( becomes helper(eej j ) ones ) ones we reach it we reach it

Whenever the helper(Whenever the helper(eej j ) is ) is replaced by some vertex replaced by some vertex vvmm ,add a diagonal from ,add a diagonal from vvm m to to

vvii If If vvii is never replaced as is never replaced as

helper(helper(eej j ), we can connect it ), we can connect it to the lower endpoint of to the lower endpoint of eej j ....

Page 33: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Removing Split/Merge VerticesRemoving Split/Merge Vertices

vv11 … v … vnn: a counter-clock enumeration of vertices of : a counter-clock enumeration of vertices of PP ee11 … e … enn: a set of edges of : a set of edges of P, where eP, where eii = segment (v = segment (vi i , v, vi+1i+1)) Events are stored in event queue, ordered by y-coord.Events are stored in event queue, ordered by y-coord. If a split vertex, connect it to the lowest vertex (helper of its left If a split vertex, connect it to the lowest vertex (helper of its left

edge) between the edges to its left and rightedge) between the edges to its left and right If a merge vertex, connect it to the highest vertex between the If a merge vertex, connect it to the highest vertex between the

edges to its left and right edges to its left and right Store the edges (and their helpers) of Store the edges (and their helpers) of PP in the leaves of in the leaves of

dynamic binary search tree dynamic binary search tree TT, left-to-right order reflects in order , left-to-right order reflects in order of leaves. Helpers may be replaced. Store only edges that of leaves. Helpers may be replaced. Store only edges that have have PP to their right (or the left edges). to their right (or the left edges).

Page 34: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

THE ALGORITHM…THE ALGORITHM…

Page 35: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

MakeMonotone(P)MakeMonotone(P)

Input: A simple polygon Input: A simple polygon PP stored in a doubly-connected edge list stored in a doubly-connected edge list DD

Output: A partitioning of Output: A partitioning of PP into monotone subpolygons stored in into monotone subpolygons stored in DD

1.1. Construct a priority queue Construct a priority queue QQ on the vertices of on the vertices of PP, using their , using their y-y-coordinates as priority. If two points have the same coordinates as priority. If two points have the same y-y-coordinates, the one with smaller coordinates, the one with smaller xx has higher priority has higher priority

2. Initialize an empty binary search tree 2. Initialize an empty binary search tree TT

3. while 3. while QQ is not empty is not empty

4. 4. do Remove do Remove vvii with the highest priority from with the highest priority from QQ

5. 5. Call the appropriate procedure to handle the vertex, Call the appropriate procedure to handle the vertex,

depending on its typedepending on its type

Page 36: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

HandleStartVertex(VHandleStartVertex(V ii))

1. Insert 1. Insert eeii in in TT and set and set helper(ehelper(eii)) to to vvii

Page 37: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009
Page 38: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

HandleEndVertex(VHandleEndVertex(Vii))

1.1. if if helper(ehelper(ei-1i-1)) is a merge vertex is a merge vertex

2. 2. then Insert diagonal connecting then Insert diagonal connecting vvii to to helper(ehelper(ei-1i-1)) in in DD

3. Delete 3. Delete eei-1i-1 from from TT

Page 39: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009
Page 40: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

HandleSplitVertex(VHandleSplitVertex(V ii))

1. Search in 1. Search in TT to find the edge to find the edge eejj directly left of directly left of vvii

2. Insert diagonal connecting 2. Insert diagonal connecting vvii to to helper(ehelper(ej j )) in in DD

3. 3. helper(ehelper(ej j ) ) vvii

4. Insert 4. Insert eeii in in TT and set and set helper(ehelper(ei i )) to to vvii

Page 41: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009
Page 42: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

HandleMergeVertex(VHandleMergeVertex(V ii))

1. if 1. if helper(ehelper(ei-1i-1)) is a merge vertex is a merge vertex

2. 2. then Insert diagonal connecting then Insert diagonal connecting vvi i to to helper(ehelper(ei-1i-1)) in in DD

3. Delete 3. Delete eei-1i-1 from from TT

4.4. Search in Search in TT to find the edge to find the edge eejj eejj directly left of directly left of vvii

5.5. if if helper(ehelper(ejj)) is a merge vertex is a merge vertex

6. 6. then Insert diagonal connecting then Insert diagonal connecting vvii to to helper(ehelper(ejj)) in in DD

7.7. helper(e helper(ej j ) ) vvii

Page 43: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009
Page 44: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

HandleRegularVertex(VHandleRegularVertex(V ii))

1. if the interior of 1. if the interior of PP lies to the right of lies to the right of vvii

2. 2. then if then if helper(ehelper(ei-1i-1)) is a merge vertex is a merge vertex

3. 3. then Insert diag. connect then Insert diag. connect vvii to to helper(ehelper(ei-1i-1) ) in in DD

4. 4. Delete Delete eei-1i-1 from from T T

5. 5. Insert Insert eeii in in T T and set and set helper(ehelper(eii)) to to vvii

6.6. else Search in else Search in TT to find the edge to find the edge eejj directly left of directly left of vvii

5.5. if if helper(ehelper(ejj)) is a merge vertex is a merge vertex

6. 6. then Insert diag. connect then Insert diag. connect vvii to to helper(ehelper(ejj)) in in DD

7.7. helper(ehelper(ej j ) ) vvii

Page 45: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009
Page 46: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Partitioning Algorithm AnalysisPartitioning Algorithm Analysis

Construct priority queue: Construct priority queue: O(n)O(n) Initialize T: Initialize T: O(1)O(1) Handle an event: Handle an event: O(log n)O(log n)

• one operation onone operation on Q Q:: O(logn) O(logn)

• at most 1 query, 1 insertion & 1 deletion onat most 1 query, 1 insertion & 1 deletion on T T:: O(logn) O(logn)

• insert at most 2 diagonals intoinsert at most 2 diagonals into D D:: O(1) O(1)

Total run time:Total run time: O(n log n) O(n log n) Storage: Storage: O(n)O(n)

Page 47: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

An attempt was made to triangulate the following polygon, this An attempt was made to triangulate the following polygon, this time with respect to the horizontal, can you guess why the time with respect to the horizontal, can you guess why the

triangulation wasn't successful?triangulation wasn't successful?

Monotonic triangulation that failed because the polygon is not monotonicMonotonic triangulation that failed because the polygon is not monotonic

Page 48: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

After a slight modification to the polygon (After a slight modification to the polygon ( it doesn't look like a donkey it doesn't look like a donkey anymoreanymore), the polygon now looks like this and can be triangulated ), the polygon now looks like this and can be triangulated

using the concept.using the concept.

A successful monotonic triangulation of the modified polygon

Page 49: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

LEMMALEMMA

Algorithm MAKE MONOTONE Algorithm MAKE MONOTONE adds set of non-intersecting adds set of non-intersecting diagonals that partitions P diagonals that partitions P into monotone subpolygons.into monotone subpolygons.

Page 50: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Proof:Proof:

We shall prove for the segment added We shall prove for the segment added in HANDLE-SPLİT-VERTEX ; the proof in HANDLE-SPLİT-VERTEX ; the proof for the segments added in HANDLE-for the segments added in HANDLE-END-VERTEX,HANDLE-REGULAR-END-VERTEX,HANDLE-REGULAR-VERTEX,and HANDLE-MERGE-VERTEX VERTEX,and HANDLE-MERGE-VERTEX is similar.is similar.

We assume that no two vertices have We assume that no two vertices have the same y-coordinate.the same y-coordinate.

Page 51: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Consider a segment Consider a segment vvmmvvii that is added by HANDLE- that is added by HANDLE-SPLİT-VERTEX when SPLİT-VERTEX when vvii is reached. is reached.

Let Let eejj be the edge to the left of be the edge to the left of vvii and let and let Be the edge to right of Be the edge to right of vvii .Thus helper( .Thus helper(eejj)= )= vvmm

When we reach When we reach vvii . . We first argue that We first argue that vvmmvvii does not intersect an edge does not intersect an edge

of P.of P. To see this, consider the quadrilateral To see this, consider the quadrilateral

Q bounded by the horizantel lines through Q bounded by the horizantel lines through vvmm and and vvii, and by , and by eejj and and eekk.There are no vertices of P inside .There are no vertices of P inside Q, otherwise Q, otherwise vvmm would not be the helper of would not be the helper of eej .j .

Page 52: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

It is supposed that there would be an edge It is supposed that there would be an edge of P intersecting of P intersecting vvmmvvii.Since the edge cannot .Since the edge cannot have an endpoint inside Q and polygon have an endpoint inside Q and polygon edges do not intersect each other, it would edges do not intersect each other, it would have to intersect the horizontal segment have to intersect the horizontal segment connecting connecting vvmm to to eejj or the horizontel or the horizontel segment connecting segment connecting vvii to to eejj .Both are .Both are impossible, since for both impossible, since for both vvmm and and vvii, the , the edge edge eejj lies immediately to the left.Hence, lies immediately to the left.Hence, no edge of P can intersect no edge of P can intersect vvmmvvi.i.

Page 53: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Since there are no Since there are no vertices of P inside vertices of P inside Q, and any Q, and any previously added previously added diagonal must diagonal must have both of ihave both of itsts endpoints above endpoints above vvii

it can can not it can can not intersect intersect vvmmvvi.i.

Page 54: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Triangulating a Monotone Polygon Triangulating a Monotone Polygon

The main idea behind the algorithm is quite The main idea behind the algorithm is quite simple. First the vertices are sorted with respect simple. First the vertices are sorted with respect to the line of monotonicity, which in the first case to the line of monotonicity, which in the first case is the y-axis (which involves sorting the vertices is the y-axis (which involves sorting the vertices by their y-coordinate), and in the second case it is by their y-coordinate), and in the second case it is the x-axis. Sorting becomes more complex when the x-axis. Sorting becomes more complex when the line of monotonicity is neither the x nor the y-the line of monotonicity is neither the x nor the y-axis, yet it is not impossible. However, finding the axis, yet it is not impossible. However, finding the line of monotonicity can be quite difficult to line of monotonicity can be quite difficult to implement. This issue requires more effort and it implement. This issue requires more effort and it lies beyond the scope of this report. After sorting lies beyond the scope of this report. After sorting the vertices from top to bottom, the triangles are the vertices from top to bottom, the triangles are cut off from the top. cut off from the top.

Page 55: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009
Page 56: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Triangulation Algorithm AnalysisTriangulation Algorithm Analysis

A strictly y-montone polygon with A strictly y-montone polygon with nn vertices can be triangulated in linear timevertices can be triangulated in linear time

A simple polygon with A simple polygon with nn vertices can be vertices can be triangulated in triangulated in O(n log n)O(n log n) time with an time with an algorithm that uses algorithm that uses O(n)O(n) storage storage

A planar subdivision with A planar subdivision with nn vertices can be vertices can be triangulated in triangulated in O(n log n)O(n log n) time with an time with an algorithm that uses algorithm that uses O(n)O(n) storage storage

Page 57: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

Triangulation HistoryTriangulation History 1. 1. A really naive algorithm is O(n*4): check allA really naive algorithm is O(n*4): check allnn**2 choices for a diagonal, each in O(n)2 choices for a diagonal, each in O(n)time. Repeat this n ¡ 1 times.time. Repeat this n ¡ 1 times. 2. A better naive algorithm is O(n*2); find an2. A better naive algorithm is O(n*2); find anear in O(n) time; then recurse. ear in O(n) time; then recurse. 3. First non-trivial algorithm: O(n log n)3. First non-trivial algorithm: O(n log n)[GJPT-78][GJPT-78] 4. A long series of papers and algorithms in4. A long series of papers and algorithms in80s until Chazelle produced an optimal80s until Chazelle produced an optimalO(n) algorithm in 1991.O(n) algorithm in 1991. 5. Linear time algorithm insanely5. Linear time algorithm insanelycomplicated; there are randomized,complicated; there are randomized,expected linear time that are moreexpected linear time that are moreaccessible.accessible. 6. We content ourselves with O(n log n)6. We content ourselves with O(n log n)

Page 58: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

MORE…MORE…

Computational Geometry-algorithms Computational Geometry-algorithms and applications and applications

http://www.me.cmu.edu/faculty1/shihttp://www.me.cmu.edu/faculty1/shimada/cg97/bader/index.htmlmada/cg97/bader/index.html

http://cgm.cs.mcgill.ca/~godfried/http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Thierry/teaching/cg-projects/97/Thierry/thierry507webprj/artgallery.htmlthierry507webprj/artgallery.html

Page 59: POLYGON TRIANGULATION POLYGON TRIANGULATION THE ART GALERY PROBLEM SİNEM GETİR 2008-2009 COMPUTER GRAPHIC SEMINAR FEBRUARY 4, 2009

DANKE SCHÖN…DANKE SCHÖN…

TEŞEKKÜRLER…TEŞEKKÜRLER…