computational geometry - bowdoin collegeltoma/teaching/cs3250-compgeom/... · •given a simple...

129
Computational Geometry [csci 3250] Laura Toma Bowdoin College

Upload: others

Post on 17-Mar-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computational Geometry [csci 3250]

Laura Toma

Bowdoin College

Page 2: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Polygon Triangulation

Page 3: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

The problem: Triangulate a given polygon.

(output a set of diagonals that partition the polygon into triangles).

Polygon Triangulation

Page 4: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

The problem: Triangulate a given polygon.

(output a set of diagonals that partition the polygon into triangles).

Polygon Triangulation

Page 5: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

• Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely within the interior of the polygon.

• Theorem: Any simple polygon with n>3 vertices contains (at least) a diagonal.

• Theorem: Any polygon can be triangulated.

• A set of 3 consecutive vertices vi-1, vi, vi+1 defines an ear if vi-1vi+1 is a diagonal.

• Theorem: Any polygon has at least two ears.

Known Results

Page 6: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

• Triangulation by identifying ears

• Idea: Find an ear, output the diagonal, delete the ear tip, repeat. • Analysis:

• checking whether a vertex is ear tip or not: O(n) • finding an ear O(n) • overall O(n3)

• Can be improved to O(n2) • Idea: When you remove a ear tip from the polygon, only the

adjacent vertices might change their ear status

First steps

Page 7: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Towards an O(n lg n) Polygon Triangulation Algorithm

Partition into monotone polygons

Triangulate monotone polygons

polygon P

Page 8: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone chains

A polygonal chain is x-monotone if any line perpendicular to x-axis intersects it in one point (one connected component).

Page 9: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone chains

A polygonal chain is x-monotone if any line perpendicular to x-axis intersects it in one point (one connected component).

one point one connected component

Page 10: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone chains

Not x-monotone

Page 11: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone chains

not x-monotonex-monotone

• Let u and v be the points on the chain with min/max x-coordinate.

• The vertices on the boundary of an x-monotone chain, going from u to v, are in x-order.

u

v

Page 12: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone chains

not x-monotonex-monotone

As you travel along this chain, your x-coordinate is staying the same or increasing

Page 13: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone chains

A polygonal chain is y-monotone if any line perpendicular to y-axis intersects it in one point (one connected component).

y-monotone not y-monotone

Page 14: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone chains

A polygonal chain is L-monotone if any line perpendicular to line L intersects it in one point (one connected component).

y-monotone not L-monotone

L

Page 15: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone polygons

A polygon is x-monotone if its boundary can be split into two x-monotone chains.

Page 16: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone polygons

xmin xmaxThe vertices on each chain are sorted w.r.t. x-axis.

A polygon is x-monotone if its boundary can be split into two x-monotone chains.

Page 17: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone polygons

x-monotone y-monotone

Page 18: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone Mountains

A polygon is an x-monotone mountain if it is monotone and one of the two chains is a single segment.

Page 19: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone Mountains

xmin xmax

A polygon is an x-monotone mountain if it is monotone and one of the two chains is a single segment.

Both endpoints have to be convex.

Page 20: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Class work: come up with an algorithm and analyze it.

Page 21: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 22: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 23: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Yes!

Page 24: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 25: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 26: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

NO!

Page 27: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 28: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 29: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Yes!

Page 30: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 31: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Yes!

Page 32: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 33: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 34: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 35: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

No!

Page 36: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 37: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 38: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 39: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 40: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 41: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 42: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 43: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 44: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 45: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 46: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 47: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 48: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 49: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 50: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 51: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 52: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 53: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 54: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 55: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Page 56: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Monotone mountains are easy to triangulate!

Analysis: O(n) time

Page 57: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Triangulating Monotone Polygons

Similar idea, O(n) time

Page 58: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Towards an O(n lg n) Polygon Triangulation Algorithm

Partition into monotone polygons

Triangulate monotone polygons

polygon P

?

Page 59: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

How can we partition a polygon in monotone pieces?

Page 60: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Intuition

x-monotone not x-monotone

What makes a polygon not monotone?

Page 61: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Intuition

x-monotone not x-monotone

What makes a polygon not monotone?

Page 62: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Intuition

x-monotone not x-monotone

What makes a polygon not monotone?

Cusp: a reflex vertex v such that the vertices before and after are both smaller or both larger than v (in terms of x-coords).

Page 63: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Intuition

• Theorem: If a polygon has no cusps, then it’s monotone. • Proof: maybe later..

x-monotone not x-monotone

Cusp: a reflex vertex v such that the vertices before and after are both smaller or both larger than v (in terms of x-coords).

Page 64: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

We’ll get rid of cusps using a trapezoidalization of P.

Page 65: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

Compute a trapezoidalization (trapezoid partition) of the polygon.

Page 66: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Compute a trapezoidalization (trapezoid partition) of the polygon. - if polygon is above vertex, shoot vertical ray up until reaches boundary - if polygon is below vertex, shoot down - if polygon is above and below vertex, shoot both up and down

Trapezoid partitions

Page 67: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Compute a trapezoidalization (trapezoid partition) of the polygon. - if polygon is above vertex, shoot vertical ray up until reaches boundary - if polygon is below vertex, shoot down - if polygon is above and below vertex, shoot both up and down

Trapezoid partitions

Page 68: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• Each polygon in the partition is a trapezoid: • It has one or two threads as sides. • If it has two, then they must both hit the same edge above, and the same

edge below. • At most one thread through each vertex => O(n) threads => O(n) trapezoids

Page 69: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• Each trapezoid has precisely two vertices of the polygon, one on the left and one on the right. They can be on the top, bottom or middle of the trapezoid.

Page 70: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• Each trapezoid has precisely two vertices of the polygon, one on the left and one on the right. They can be on the top, bottom or middle of the trapezoid.

Page 71: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• Each trapezoid has precisely two vertices of the polygon, one on the left and one on the right. They can be on the top, bottom or middle of the trapezoid.

Page 72: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• Each trapezoid has precisely two vertices of the polygon, one on the left and one on the right. They can be on the top, bottom or middle of the trapezoid.

Page 73: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• In each trapezoid: if its two vertices are not on the same edge, they define a diagonal.

Page 74: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• In each trapezoid: if its two vertices are not on the same edge, they define a diagonal.

Page 75: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• In each trapezoid: if its two vertices are not on the same edge, they define a diagonal.

Page 76: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• In each trapezoid: if its two vertices are not on the same edge, they define a diagonal.

Page 77: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• In each trapezoid: if its two vertices are not on the same edge, they define a diagonal.

Page 78: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• In each trapezoid: if its two vertices are not on the same edge, they define a diagonal.

Page 79: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• In each trapezoid: if its two vertices are not on the same edge, they define a diagonal.

Page 80: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Trapezoid partitions

• In each trapezoid: if its two vertices are not on the same edge, they define a diagonal.

Page 81: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

We’ll use the trapezoid partition of P to get rid of cusps and split it into monotone polygons

Page 82: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

Page 83: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

Page 84: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

Page 85: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

3. For each cusp vertex, add diagonal in trapezoid before/after the cusp

Page 86: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

3. For each cusp vertex, add diagonal in trapezoid before/after the cusp

Page 87: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

3. For each cusp vertex, add diagonal in trapezoid before/after the cusp

Page 88: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

Page 89: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

3. For each cusp vertex, add diagonal in trapezoid before/after the cusp

Page 90: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

3. For each cusp vertex, add diagonal in trapezoid before/after the cusp

Page 91: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

Page 92: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

3. For each cusp vertex, add diagonal in trapezoid before/after the cusp

This creates a partition of P.

The resulting polygons have no cusps and thus are monotone (by theorem).

Page 93: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

• Another example

Page 94: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

• Another example

1. Compute a trapezoid partition of P

Page 95: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

1. Compute a trapezoid partition of P

2. Identify cusp vertices

Page 96: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

1. Compute a trapezoid partition of P

2. Identify cusp vertices

3. Add obvious diagonal before/after each cusp

Removing cusps

Page 97: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

This partitions the polygon into monotone pieces.

Removing cusps

Page 98: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Removing cusps

This partitions the polygon into monotone pieces.

Page 99: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

x

This partitions the polygon into monotone pieces.

Removing cusps

Page 100: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Partition P into monotone polygons

x

1. Compute a trapezoid partition of P

2. Identify cusp vertices

3. Add obvious diagonal before/after each cusp

Page 101: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

An O(n lg n) Polygon Triangulation Algorithm

trapezoid partitionpolygon P output

cusps diagonals

Triangulate monotone polygons

O(n) O(n)

Page 102: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

An O(n lg n) Polygon Triangulation Algorithm

trapezoid partitionpolygon P output

cusps diagonals

Triangulate monotone polygons

O(n) O(n)

Given a trapezoid partition of P, we can triangulate it in O(n) time.

Page 103: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

An O(n lg n) Polygon Triangulation Algorithm

trapezoid partitionpolygon P output

cusps diagonals

Triangulate monotone polygons

O(n) O(n)

Given a trapezoid partition of P, we can triangulate it in O(n) time.

Actually there’s even a simpler way to do this.

Page 104: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

An O(n lg n) Polygon Triangulation Algorithm

trapezoid partitionpolygon P output

cusps diagonals

Triangulate monotone polygons

Triangulate monotone mountains

output all diagonals

Page 105: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Generating monotone mountains

Page 106: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

1. Compute a trapezoid partition of P

Generating monotone mountains

Page 107: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

1. Compute a trapezoid partition of P

Generating monotone mountains

Page 108: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

1. Compute a trapezoid partition of P

2. Output all diagonals.

Generating monotone mountains

Page 109: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

1. Compute a trapezoid partition of P

2. Output all diagonals.

Generating monotone mountains

Page 110: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

1. Compute a trapezoid partition of P

2. Output all diagonals.

The diagonals partition the polygon into monotone mountains.

Generating monotone mountains

Page 111: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

1. Compute a trapezoid partition of P

2. Output all diagonals.

The diagonals partition the polygon into monotone mountains.

Generating monotone mountains

Page 112: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

1. Compute a trapezoid partition of P

2. Output all diagonals.

The diagonals partition the polygon into monotone mountains.

Generating monotone mountains

Page 113: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Generating monotone mountains

Proof: • Each polygon is monotone • One of the chains must be a segment (because if it had another point, that

point would generate a diagonal)

Claim: The diagonals partition the polygon into monotone mountains.

Page 114: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

An O(n lg n) Polygon Triangulation Algorithm

trapezoid partitionpolygon P output

cusps diagonals

Triangulate monotone polygons

Triangulate monotone mountains

output all diagonals

O(n) O(n)

O(n) O(n)

Given a trapezoid partition of P, we can triangulate it in O(n) time.

Page 115: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

An O(n lg n) Polygon Triangulation Algorithm

trapezoid partitionpolygon P output

cusps diagonals

Triangulate monotone polygons

Triangulate monotone mountains

output all diagonals

O(n) O(n)

O(n) O(n)

so how do we get the trapezoid partition?

Page 116: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Given a polygon P, how do we compute a trapezoid partition?

Page 117: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

Page 118: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 119: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 120: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 121: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 122: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 123: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 124: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 125: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 126: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep

Page 127: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Plane sweep • Events: polygon vertices • Status structure: edges that intersect current sweep line, in y-order • Events:

How do you determine the trapezoids?

Page 128: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

Computing the trapezoid partition in O(n lg n)

• Algorithm

Page 129: Computational Geometry - Bowdoin Collegeltoma/teaching/cs3250-CompGeom/... · •Given a simple polygon P, a diagonal is a segment between 2 non-adjacent vertices that lies entirely

History of Polygon Triangulation

• Early algorithms: O(n4), O(n3), O(n2)

• First pseudo-linear algorithm: O(n lg n)

• … Many papers with improved bounds

• Until finally Bernard Chazelle (Princeton) gave an O(n) algorithm in 1991 • https://www.cs.princeton.edu/~chazelle/pubs/polygon-triang.pdf • Ridiculously complicated! • O(1) people actually understand it (and I’m not one of them)

• There is a randomized algorithm that runs in O(n) expected