Lec 1 Introduction and Convex Hull
-
Upload
mohanraomamdikar -
Category
Documents
-
view
229 -
download
1
Transcript of Lec 1 Introduction and Convex Hull
-
8/3/2019 Lec 1 Introduction and Convex Hull
1/48
IntroductionConvex hulls
Computational Geometry
Lecture 1: Introduction and convex hulls
Computational Geometry Lecture 1: Introduction and Convex Hulls
-
8/3/2019 Lec 1 Introduction and Convex Hull
2/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Geometry: points, lines, ...
Plane (two-dimensional), R2
Space (three-dimensional), R3
Space (higher-dimensional), Rd
A point in the plane, 3-dimensional space, higher-dimensionalspace.p = (px,py), p = (px,py,pz), p = (p1,p2, . . . ,pd)
A line in the plane: y = m x+ c; representation by m and c
A half-plane in the plane: y m x+ c or ym x+ c
Represent vertical lines? Not by m and c . . .
Computational Geometry Lecture 1: Introduction and Convex Hulls
-
8/3/2019 Lec 1 Introduction and Convex Hull
3/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Geometry: line segments
A line segment pq is defined by itstwo endpoints p and q:( px + (1) qx, py + (1)
qy)where 0 1
Line segments are assumed to beclosed = with endpoints, not open
Two line segments intersect if theyhave some point in common. It is aproper intersection if it is exactly oneinterior point of each line segment
Computational Geometry Lecture 1: Introduction and Convex Hulls
-
8/3/2019 Lec 1 Introduction and Convex Hull
4/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Polygons: simple or not
A polygon is a connected region ofthe plane bounded by a sequence ofline segments
simple polygon
polygon with holes
convex polygon
non-simple polygon
The line segments of a polygon arecalled its edges, the endpoints ofthose edges are the vertices
Some abuse: polygon is only
boundary, or interior plus boundary
interior
exterior
Computational Geometry Lecture 1: Introduction and Convex Hulls
G i bj
-
8/3/2019 Lec 1 Introduction and Convex Hull
5/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Other shapes: rectangles, circles, disks
A circle is only the boundary, a diskis the boundary plus the interior
Rectangles, squares, quadrants,slabs, half-lines, wedges, . . .
Computational Geometry Lecture 1: Introduction and Convex Hulls
G t i bj t
-
8/3/2019 Lec 1 Introduction and Convex Hull
6/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Relations: distance, intersection, angle
The distance between two points isusually the Euclidean distance:
(pxqx)2 + (pyqy)2
Another option: the Manhattandistance:
|pxqx|+ |pyqy|
Question: What is the set of pointsat equal Manhattan distance to somepoint?
(px qx)2 + (py qy)2)
|px qx|
|py qy|
Computational Geometry Lecture 1: Introduction and Convex Hulls
Geometric objects
-
8/3/2019 Lec 1 Introduction and Convex Hull
7/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Relations: distance, intersection, angle
The distance between two geometric objects other than points
usually refers to the minimum distance between two points thatare part of these objects
Question: How can the distance between two line segments berealized?
Computational Geometry Lecture 1: Introduction and Convex Hulls
Geometric objects
-
8/3/2019 Lec 1 Introduction and Convex Hull
8/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Relations: distance, intersection, angle
The intersection of two geometricobjects is the set of points (part ofthe plane, space) they have in
common
Question 1: How many intersectionpoints can a line and a circle have?
Question 2: What are the possibleoutcomes of the intersection of arectangle and a quadrant?
Computational Geometry Lecture 1: Introduction and Convex Hulls
Geometric objects
-
8/3/2019 Lec 1 Introduction and Convex Hull
9/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Relations: distance, intersection, angle
Question 3: What is the maximumnumber of intersection points of a
line and a simple polygon with 10vertices (trick question)?
Question 4: What is the maximumnumber of intersection points of aline and a simple polygon boundarywith 10 vertices (still a trickquestion)?
Computational Geometry Lecture 1: Introduction and Convex Hulls
Geometric objects
-
8/3/2019 Lec 1 Introduction and Convex Hull
10/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Description size
A point in the plane can berepresented using two reals
A line in he plane can be representedusing two reals and a Boolean (forexample)
A line segment can be represented bytwo points, so four reals
A circle (or disk) requires three realsto store it (center, radius)
A rectangle requires four reals tostore it
false, m , c
true, . . , c
y = m
x + c
x = c
Computational Geometry Lecture 1: Introduction and Convex Hulls
Geometric objects
-
8/3/2019 Lec 1 Introduction and Convex Hull
11/48
IntroductionConvex hulls
Geometric objectsGeometric relationsCombinatorial complexityComputational geometry
Description size
A simple polygon in the plane can be represented using 2n reals ifit has n vertices (and necessarily, n edges)
A set ofn points requires 2n reals
A set ofn line segments requires 4n reals
A point, line, circle, . . . requires O(1), or constant, storage.
A simple polygon with n vertices requires O(n), or linear, storage
Computational Geometry Lecture 1: Introduction and Convex Hulls
Geometric objects
-
8/3/2019 Lec 1 Introduction and Convex Hull
12/48
IntroductionConvex hulls
jGeometric relationsCombinatorial complexityComputational geometry
Computation time
Any computation (distance, intersection) on two objects ofO(1)description size takes O(1) time!
Question: Suppose that a simple polygon with n vertices is given;the vertices are given in counterclockwise order along theboundary. Give an efficient algorithm to determine all edges thatare intersected by a given line.
How efficient is your algorithm? Why is your algorithm efficient?
Computational Geometry Lecture 1: Introduction and Convex Hulls
Geometric objects
-
8/3/2019 Lec 1 Introduction and Convex Hull
13/48
IntroductionConvex hulls
Geometric relationsCombinatorial complexityComputational geometry
Algorithms, efficiency
Recall from your algorithms and data structures course:
A set ofn real numbers can be sorted in O(n logn) time
A set ofn real numbers can be stored in a data structure that usesO(n) storage and that allows searching, insertion, and deletion inO(logn) time per operation
These are fundamental results in 1-dimensional computationalgeometry!
Computational Geometry Lecture 1: Introduction and Convex Hulls
Geometric objects
-
8/3/2019 Lec 1 Introduction and Convex Hull
14/48
IntroductionConvex hulls
Geometric relationsCombinatorial complexityComputational geometry
Computational geometry scope
In computational geometry, problems on input with more thanconstant description size are the ones of interest
Computational geometry (theory): Study of geometric problems ongeometric data, and how efficient geometric algorithms that solvethem can be
Computational geometry (practice): Study of geometric problems
that arise in various applications and how geometric algorithms canhelp to solve well-defined versions of such problems
Computational Geometry Lecture 1: Introduction and Convex Hulls
I d iGeometric objectsG i l i
-
8/3/2019 Lec 1 Introduction and Convex Hull
15/48
IntroductionConvex hulls
Geometric relationsCombinatorial complexityComputational geometry
Computational geometry theory
Computational geometry (theory):Classify abstract geometric problemsinto classes depending on howefficiently they can be solved
smallest enclosing circle
closest pair
any intersection?
find all intersections
Computational Geometry Lecture 1: Introduction and Convex Hulls
I t d tiGeometric objectsG t i l ti
-
8/3/2019 Lec 1 Introduction and Convex Hull
16/48
IntroductionConvex hulls
Geometric relationsCombinatorial complexityComputational geometry
Computational geometry practice
Application areas that require geometric algorithms are computergraphics, motion planning and robotics, geographic informationsystems, CAD/CAM, statistics, physics simulations, databases,
games, multimedia retrieval, . . .
Computing shadows from virtual light sources
Spatial interpolation from groundwater polution measurements
Computing a collision-free path between obstacles
Computing similarity of two shapes for shape databaseretrieval
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionGeometric objectsGeometric relations
-
8/3/2019 Lec 1 Introduction and Convex Hull
17/48
IntroductionConvex hulls
Geometric relationsCombinatorial complexityComputational geometry
Computational geometry history
Early 70s: First attention for geometric problems from algorithmsresearchers
1976: First PhD thesis in computational geometry (Michael
Shamos)1985: First Annual ACM Symposium on Computational Geometry.Also: first textbook
1996: CGAL: first serious implementation effort for robust
geometric algorithms
1997: First handbook on computational geometry (second one in2000)
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvexityConvex hull
-
8/3/2019 Lec 1 Introduction and Convex Hull
18/48
IntroductionConvex hulls
Convex hullAlgorithm developmentAlgorithm analysis
Convexity
A shape or set is convex if for any
two points that are part of theshape, the whole connecting linesegment is also part of the shape
Question: Which of the following
shapes are convex? Point, linesegment, line, circle, disk, quadrant?
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvexityConvex hull
-
8/3/2019 Lec 1 Introduction and Convex Hull
19/48
IntroductionConvex hulls
Convex hullAlgorithm developmentAlgorithm analysis
Convex hull
For any subset of the plane (set ofpoints, rectangle, simple polygon),its convex hull is the smallest convexset that contains that subset
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvexityConvex hull
-
8/3/2019 Lec 1 Introduction and Convex Hull
20/48
IntroductionConvex hulls
Convex hullAlgorithm developmentAlgorithm analysis
Convex hull problem
Give an algorithm that computes theconvex hull of any given set ofn
points in the plane efficiently
The input has 2n coordinates, soO(n) size
Question: Why cant we expect todo any better than O(n) time?
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvexityConvex hull
-
8/3/2019 Lec 1 Introduction and Convex Hull
21/48
Convex hulls Algorithm developmentAlgorithm analysis
Convex hull problem
Assume the n points are distinct
The output has at least 4 and at most 2n coordinates, so it hasbetween O(1) and O(n) size
The output is a convex polygon so it should be returned as a sortedsequence of the points, counterclockwise along the boundary
Question: Is there any hope of finding an O(n) time algorithm?
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvexityConvex hull
-
8/3/2019 Lec 1 Introduction and Convex Hull
22/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
To develop an algorithm, find usefulproperties, make variousobservations, draw many sketches togain insight
Property: The vertices of the convexhull are always points from the input
Consequently, the edges of theconvex hull connect two points of
the input
Property: The supporting line of anyconvex hull edge has all input pointsto one side
p
q
all points lie left of the di-rected line from p to q, if
the edge from p to q is a
CCW convex hull edge
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvexityConvex hull
-
8/3/2019 Lec 1 Introduction and Convex Hull
23/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
Algorithm SlowConvexHull(P)
Input. A set P of points in the plane.Output. A list L containing the vertices ofCH(P) in clockwise
order.
1. E /0.2. for all ordered pairs (p,q) PP with p not equal to q3. do valid true4. for all points r P not equal to p or q5. do if r lies left of the directed line from p to q
6. then valid false7. if valid then Add the directed edge pq to E8. From the set E of edges construct a list L of vertices of
CH(P), sorted in clockwise order.
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvexityConvex hull
-
8/3/2019 Lec 1 Introduction and Convex Hull
24/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
Question: How must line 5 be interpreted to make the algorithmcorrect?
Question: How efficient is the algorithm?
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionC h ll
ConvexityConvex hullAl i h d l
-
8/3/2019 Lec 1 Introduction and Convex Hull
25/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
Another approach: incremental, from left to right
Lets first compute the upper boundary of the convex hull this way(property: on the upper hull, points appear in x-order)
Main idea: Sort the points from left to right (= by x-coordinate).Then insert the points in this order, and maintain the upper hull so
far
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionC h ll
ConvexityConvex hullAl ith d l t
-
8/3/2019 Lec 1 Introduction and Convex Hull
26/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
Observation: from left toright, there are only right turnson the upper hull
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm development
-
8/3/2019 Lec 1 Introduction and Convex Hull
27/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
Initialize by inserting theleftmost two points
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm development
-
8/3/2019 Lec 1 Introduction and Convex Hull
28/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
If we add the third point therewill be a right turn at theprevious point, so we add it
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm development
-
8/3/2019 Lec 1 Introduction and Convex Hull
29/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
If we add the fourth point weget a left turn at the thirdpoint
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm development
-
8/3/2019 Lec 1 Introduction and Convex Hull
30/48
Convex hulls Algorithm developmentAlgorithm analysis
Developing an algorithm
. . . so we remove the thirdpoint from the upper hullwhen we add the fourth
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm development
-
8/3/2019 Lec 1 Introduction and Convex Hull
31/48
g pAlgorithm analysis
Developing an algorithm
If we add the fifth point we geta left turn at the fourth point
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm development
-
8/3/2019 Lec 1 Introduction and Convex Hull
32/48
g pAlgorithm analysis
Developing an algorithm
. . . so we remove the fourthpoint when we add the fifth
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm development
-
8/3/2019 Lec 1 Introduction and Convex Hull
33/48
Algorithm analysis
Developing an algorithm
If we add the sixth point weget a right turn at the fifthpoint, so we just add it
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm development
-
8/3/2019 Lec 1 Introduction and Convex Hull
34/48
Algorithm analysis
Developing an algorithm
We also just add the seventhpoint
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAl ith l i
-
8/3/2019 Lec 1 Introduction and Convex Hull
35/48
Algorithm analysis
Developing an algorithm
When adding the eight point. . . we must remove theseventh point
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm anal sis
-
8/3/2019 Lec 1 Introduction and Convex Hull
36/48
Algorithm analysis
Developing an algorithm
. . . we must remove theseventh point
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
37/48
Algorithm analysis
Developing an algorithm
. . . and also the sixth point
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
38/48
Algorithm analysis
Developing an algorithm
. . . and also the fifth point
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
39/48
Algorithm analysis
Developing an algorithm
After two more steps we get:
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
40/48
Algorithm analysis
The pseudo-code
Algorithm ConvexHull(P)Input. A set P of points in the plane.Output. A list containing the vertices ofCH(P) in clockwise order.1. Sort the points by x-coordinate, resulting in a sequence
p1, . . . ,pn.
2. Put the points p1 and p2 in a list Lupper, with p1 as the firstpoint.
3. for i 3 to n4. do Append pi to Lupper.
5. while Lupper contains more than two points and thelast three points in Lupper do notmake a right turn
6. do Delete the middle of the last three points fromLupper.
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
41/48
g y
The pseudo-code
Then we do the same for thelower convex hull, from right
to leftWe remove the first and lastpoints of the lower convex hull
. . . and concatenate the two
lists into one
1, 2, 10, 13, 14
p14, p12, p8, p4, p1
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
42/48
Algorithm analysis
Algorithm analysis generally has two components:
proof of correctness
efficiency analysis, proof of running time
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
43/48
Correctness
Are the general observations on which the algorithm is basedcorrect?
Does the algorithm handle degenerate cases correctly?
Here:
Does the sorted order matter if two or more points have thesame x-coordinate?
What happens if there are three or more collinear points, inparticular on the convex hull?
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
44/48
Efficiency
Identify of each line of pseudo-code how much time it takes, if it isexecuted once (note: operations on a constant number ofconstant-size objects take constant time)
Consider the loop-structure and examine how often each line ofpseudo-code is executed
Sometimes there are global arguments why an algorithm is moreefficient than it seems, at first
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
45/48
The pseudo-code
Algorithm ConvexHull(P)Input. A set P of points in the plane.Output. A list containing the vertices ofCH(P) in clockwise order.1. Sort the points by x-coordinate, resulting in a sequence
p1, . . . ,pn.
2. Put the points p1 and p2 in a list Lupper, with p1 as the firstpoint.
3. for i 3 to n4. do Append pi to Lupper.5. while L
uppercontains more than two points and the
last three points in Lupper do notmake a right turn
6. do Delete the middle of the last three points fromLupper.
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
46/48
Efficiency
The sorting step takesO
(n logn
) timeAdding a point takes O(1) time for the adding-part. Removingpoints takes constant time for each removed point. If due to anaddition, k points are removed, the step takes O(1+ k) time
Total time:O(n logn) +
n
i=3
O(1+ ki)
if ki points are removed when adding pi
Since ki = O(n), we get
O(n logn) +n
i=3
O(n) = O(n2)
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
47/48
Efficiency
Global argument: each point can be removed only once from theupper hull
This gives us the fact:
n
i=3
ki n
Hence,
O(n logn) +n
i=3
O(1+ ki) = O(n logn) +O(n) = O(n logn)
Computational Geometry Lecture 1: Introduction and Convex Hulls
IntroductionConvex hulls
ConvexityConvex hullAlgorithm developmentAlgorithm analysis
-
8/3/2019 Lec 1 Introduction and Convex Hull
48/48
Final result
The convex hull of a set ofn points in the plane can be computedin O(n logn) time, and this is optimal
Computational Geometry Lecture 1: Introduction and Convex Hulls