Fundamentals of computational geometry
FUNDAMENTALS OF COMPUTATIONAL
GEOMETRYM. Ramanathan
STTP CAD 2011
Fundamentals of computational geometry
The Art Gallery Problem
camera
How many cameras are needed to guard a gallery and How should they be placed?
STTP CAD 2011
Fundamentals of computational geometry
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 :
STTP CAD 2011
Fundamentals of computational geometry
Simple 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).STTP CAD 2011
Fundamentals of computational geometry
There are no holes in a simple polygon.
Simple polygon
Nonsimple polygons
STTP CAD 2011
Fundamentals of computational geometry
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.
STTP CAD 2011
Fundamentals of computational geometry
This 12-vertex polygon
needs 4 guards to cover it
This 12-vertex polygon needs
3 guards to cover it.
STTP CAD 2011
Fundamentals of computational geometry
- 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
STTP CAD 2011
Fundamentals of computational geometry
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
STTP CAD 2011
Fundamentals of computational geometry
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
STTP CAD 2011
Fundamentals of computational geometry
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.
STTP CAD 2011
Fundamentals of computational geometry
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!).
STTP CAD 2011
Fundamentals of computational geometry
n=14
Interesting, both
triangulations have
same number of
diagonals!
Notice that number of
diagonals equals n-3.
STTP CAD 2011
Fundamentals of computational geometry
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.
STTP CAD 2011
Fundamentals of computational geometry
5
4
5
6
3
5
The coloring of a
triangulation graph
is unique!
Assigning color to
first vertex enforces
the rest color
assignments.
STTP CAD 2011
Fundamentals of computational geometry
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.
STTP CAD 2011
Fundamentals of computational geometry
Art-gallery Problem in 3DAn example of a polyhedron with interior points not visible from any vertex.
STTP CAD 2011
Fundamentals of computational geometry
Schönhardt Polyhedron
Schönhardt polyhedron is the smallest non-convex polyhedron which cannot be triangulated into tetrahedra without adding new vertices.
STTP CAD 2011
Fundamentals of computational geometry
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
STTP CAD 2011
Fundamentals of computational geometry
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.
STTP CAD 2011
Fundamentals of computational geometry
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) 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
STTP CAD 2011
Fundamentals of computational geometry
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!
1
1 10For any convex polygon:
n
i i i iiP x y x y
2A
STTP CAD 2011
Fundamentals of computational geometry
What happens for non-convex
quadrilateral ?
v2
0 1 2 0 3 2
3
1 10
0
, , , ,
.
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
STTP CAD 2011
Fundamentals of computational geometry
We’d like to obtain the area of a general simple polygon in
terms of its vertices only.
0 1 1
1 1
1 1 10 0
1
1 10
Let the vertices , , , , ,
be labled counterclockwise, defining a polygon ,
and let be an arbitrary point. Then
, ,
n i i i
n n
i i i i i ii i
n
i 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
STTP CAD 2011
Fundamentals of computational geometry
CONVEX HULLS IN TWO DIMENSIONS
Definitions Basic algorithms
Gift Wrapping (algorithm of Jarvis)Graham scan
Divide and conquer
STTP CAD 2011
Fundamentals of computational geometry
Convexity
A set S is convex if x S and y S implies the segment xy S
x y
STTP CAD 2011
Fundamentals of computational geometry
Definitions of Convex Hull
Convex Hull of a finite set of points S in the plane is the smallest convex polygon P that encloses S which means that there is no other polygon P’ such that S P’ P
Intersection of all convex sets containing the points in S
STTP CAD 2011
Fundamentals of computational geometry
The convex hull of a set of points S in the plane is the union of all the triangles determined by points in S
Informal definition: Convex hull of a set of points in plane is the shape taken by a rubber band stretched around the nails pounded into the plane at each point
Now we define the convex hull problem:- The problem is to construct the boundary of a convex hull in two dimensions given a finite set S of n points- Four outputs can be distinguished for the above problem:
1. all the points on the hull, in arbitrary order;
2. the extreme points, in arbitrary order;3. all the points on the hull, in boundary
traversal order;4. the extreme points, in boundary
traversal order;
STTP CAD 2011
Fundamentals of computational geometry
Extreme Points
The extreme points of a set S of points in the plane are the vertices of the convex hull at which the interior angle is less than π
Also a point is extreme iff there exists a line through that point that other wise does not touch the convex hull
STTP CAD 2011
Fundamentals of computational geometry
Algorithms to find Extreme Points
A] Using Non Extreme Points Identifying non extreme points implies
identifying extreme points A point is non extreme iff it is inside some
(closed) triangle whose vertices are the points of the set and is not itself a corner of that triangle. Thus given a triangle:
If a point is interior to triangle it is non extreme Corners of the triangle might be extreme
Thus as the output we will get the extreme points in some arbitrary order.
STTP CAD 2011
Fundamentals of computational geometry
Algorithm: Interior Points
for each i do
for each j ≠ i do for each k ≠ i ≠ j do
for each l ≠ k ≠ i ≠ j do
if pl Δ(pi ,pj , pk)then pl is nonextreme
• There are four nested loops in this algorithm
• Hence the order is O(n4)
• For each of the n3 triangles, the test for extremeness costs n
• It is important to find a faster algorithm
STTP CAD 2011
Fundamentals of computational geometry
B] Extreme Edges
An edge is extreme if every point of S is on or to one side of the line determined by the edge
If we treat the edge as directed and let the left side of edge be inside then – the directed edge is not extreme if there is some point that is not left of it or on it
The output of this algorithm will be all the points on the convex hull in arbitrary order
STTP CAD 2011
Fundamentals of computational geometry
Algorithm: Extreme Edges
for each i do
for each j ≠ i do for each k ≠ i ≠ j do if pk is not left or on (pi ,pj)
then (pi ,pj) is not extreme
• There are three nested loops in this algorithm
• Hence the order is O(n3)
• For each of the n2 pair of points, the test for extremeness costs n
• The vertices that are extreme can now be found
STTP CAD 2011
Fundamentals of computational geometry
C] Gift Wrapping (a more realistic hull algorithm)
A minor variation of Extreme Edge algorithm can accelerate it by factor n as well as output the points in order
The idea is to use one extreme edge as an anchor for finding the next
Suppose the algorithm found an extreme edge whose unlinked endpoint is x
θ
y
x
e
• For each y of set S we compute the angle θ
• The point that yields the smallest θ must determine an extreme edge
• The output of this algorithm is all the points on the hull in boundary traversal order
STTP CAD 2011
Fundamentals of computational geometry
Idea: Think of wrapping a gift. Put the paper in contact with the gift and continue to wrap around from one surface to the next until you get all the way around.
STTP CAD 2011
Fundamentals of computational geometry
Algorithm: Gift Wrapping
Find the lowest point (smallest y coordinate)Let i0 be its index, and set i ← i0
repeat for each j ≠ i do
compute counterclockwise angle θ from previous hull edgeLet k be the index of the point with the smallest θOutput (pi ,pk) as a hull edgei ← k
until i = i0
• We use the lowest point as the anchor
• The order is O(n2)
• The cost is O(n) for each hull edge
• The point set is wrapped by a string that bends the that bends with
minimum angle from previous to next hull edge
STTP CAD 2011
Fundamentals of computational geometry
Jarvis March - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Jarvis March - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Jarvis March - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Jarvis March - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Jarvis March - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Jarvis March - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Jarvis March - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p11
p12
p10
p9
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p11
p12
p10
p9
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p11
p12
p10
p9
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p11
p12
p10
p9
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p11
p12
p10
p9
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p11
p12
p10
p9
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p11
p12
p10
p9
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Graham Scan - Example
p0
p1
p3
p2
p4
p5
p6
p7
p8
p9
p11
p12
p10
STTP CAD 2011
Fundamentals of computational geometry
Convex Hull - Divide and Conquer
Algorithm: Find a point with a median x
coordinate (time: O(n)) Compute the convex hull of
each half (recursive execution) Combine the two convex hulls
by finding common tangents.Can be done in O(n)
)(2
2)( nOn
TnT
Complexity: O(nlogn)
STTP CAD 2011
Fundamentals of computational geometry
Voronoi Diagram
STTP CAD 2011
Fundamentals of computational geometry
Formal Definition
P A set of n distinct points in the plane.
VD(P) a subdivision of the plane into n cells such that
each cell contains exactly one site, if a point q lies in a cell containing pi then d(q, pi ) < d(q, pj ) for all pi P, j i.
In other words, given a set P of points in 2D, VD(P) is a partition of the plane into n convex regions {R1, R2, …, Rn}, each (Ri) containing exactly one member (pi) in P such that for each point in Ri, its nearest member in P is pi
STTP CAD 2011
Fundamentals of computational geometry
Voronoi diagram (illustration)
P1 P2
B(P
1,P
2)
P1
P2
P3B(P1,P3)
B(P1,P2)
B(P2,
P3)
Remember that VD is notdefined for just points but for any set e.g. curves, surfaces etc. Moreover, the definition is applicable for any dimension.
STTP CAD 2011
Fundamentals of computational geometry
Characteristics of the Voronoi Diagram
Each vertex (corner) of VD(P) has degree 3
The circle through the three points defines a vertex of the Voronoi diagram, and it does not contain any other point
The locus of the center of a largest empty circles passing through only a pair of points pi, pj P defines an edge
The locus of the center of largest empty circles passing through only one points in P defines a cell
The Voronoi region of a point is unbounded if and only if the point is a vertex of the convex hull of the point set.
Assumption: No 4 points are co-circular.
STTP CAD 2011
Fundamentals of computational geometry
Use of Voronoi Diagram
Search for nearest neighbour
Input: A fixed (static) set P of n points in the plane, and a query point p
Output: Nearest neighbour of p in P
Solution• Construct the Voronoi diagram
for P in time O(n log n)
• Solve the point location problem in O(log n) time.
STTP CAD 2011
Fundamentals of computational geometry
Use of Voronoi Diagram (contd.)
Closest pair of points: Inspect all the edges list of Vor(P) and determine the minimally separated pair
Largest empty circle: Each Voronoi vertex represents the center of a maximal emptycircle. Find one having maximum radius.
Computing Euclidian Minimum Spanning Tree: Compute dual of the Voronoi diagram, and applyKruskal’s algorithm for computing the minimum Spanning tree.
STTP CAD 2011
Fundamentals of computational geometry
Furthest Point Voronoi Diagram
V-1(pi) : the set of point of the plane farther from pi than from any other site
Vor-1(P) : the partition of the plane formed by the farthest point Voronoi regions, their edges, and vertices
STTP CAD 2011
Fundamentals of computational geometry
Order-2 Voronoi diagram
V(pi,pj) : the set of points of the plane closer to each of pi and pj
than to any other site
Property The order-2 Voronoi regions are convex
STTP CAD 2011
Fundamentals of computational geometry
Voronoi diagram of weighted points
S Set of points in 2D
w(p) weight attached with the point p S
dw(x,p) = de(x,p)/w(p) weighted distance of a point x from p S
Weighted Voronoi diagram WVD(S) the subdivision of the plane such that
region(p) = {x : dw(x,p) < dw(x,q) q S
Thus, a point having large weight will cover bigger space
STTP CAD 2011
Fundamentals of computational geometry
Voronoi diagram for line segments
Voronoi edges: These are formed with line segments and/or parabolic arcs.
Straight line edges are part of either the perpendicular bisector of two segment end-points or the angular bisector or two segments.
Curve edges consist of points equidistant from a segment end-point and a segment’s interior.
STTP CAD 2011
Fundamentals of computational geometry
Nearest site proximity partitioning of the plane
Voronoi Diagram & Delaunay Triangulation
STTP CAD 2011
Fundamentals of computational geometry
Voronoi Diagram & Delaunay Triangulation
STTP CAD 2011
Fundamentals of computational geometry
Skeleton – Medial Axis
The medial axis (MA), or skeleton of the set D, is defined as the locus of points inside which lie at the centers of all closed discs (or balls in 3-D) which are maximal in D.
STTP CAD 2011
Fundamentals of computational geometry
Exercises Art-gallery problem for
orthogonal polygon
STTP CAD 2011
smallest circle that completely encloses a set of points
Relation between MA and VD for a) convex and b) non-convex polygons.
Fundamentals of computational geometry
Web resources and books
www.cs.iastate.edu/~cs518/handouts/art-gallery.ppt www.tcs.tifr.res.in/~
igga/lectureslides/vor-July-08-2009.ppt in2.csie.ncu.edu.tw/~jrjiang/alg2008/Voronoi.ppt www.cse.ttu.edu.tw/~jmchen/compg/slides/voro-apps.
ppt www.cse.yorku.ca/~andy/courses/4101/Slides/CG-
Intro.pptx Joseph O’Rourke, Computational Geometry in C,
Second edition, Cambridge university press, 1998
Joseph O’Rourke, Art Gallery theorems and algorithms, Oxford university press, 1987
STTP CAD 2011