Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and...
Transcript of Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and...
![Page 1: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/1.jpg)
Computational Geometry
Lecture 1: Introduction and convex hulls
Computational Geometry Lecture 1: Introduction and Convex Hulls1
![Page 2: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/2.jpg)
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 y≥ m · x+ c
Represent vertical lines? Not by m and c . . .
Computational Geometry Lecture 1: Introduction and Convex Hulls2
![Page 3: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/3.jpg)
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 Hulls3
![Page 4: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/4.jpg)
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 onlyboundary, or interior plus boundary
interior
exterior
Computational Geometry Lecture 1: Introduction and Convex Hulls4
![Page 5: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/5.jpg)
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 Hulls5
![Page 6: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/6.jpg)
Relations: distance, intersection, angle
The distance between two points isgenerally the Euclidean distance:√
(px−qx)2 +(py−qy)2
Another option: the Manhattandistance:
|px−qx|+ |py−qy|
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 Hulls6
![Page 7: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/7.jpg)
Relations: distance, intersection, angle
The distance between two geometric objects other than pointsusually 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 Hulls7
![Page 8: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/8.jpg)
Relations: distance, intersection, angle
The intersection of two geometricobjects is the set of points (part ofthe plane, space) they have incommon
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 Hulls8
![Page 9: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/9.jpg)
Relations: distance, intersection, angle
Question 3: What is the maximumnumber of intersection points of aline and a simple polygon with 10vertices (trick question)?
Computational Geometry Lecture 1: Introduction and Convex Hulls9
![Page 10: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/10.jpg)
Relations: distance, intersection, angle
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 Hulls10
![Page 11: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/11.jpg)
Relations: distance, intersection, angle
Question 5: What is the maximumnumber of edges of a simple polygonboundary with 10 vertices that a linecan intersect?
Computational Geometry Lecture 1: Introduction and Convex Hulls11
![Page 12: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/12.jpg)
Description size
A point in the plane can berepresented using two reals
A line in the plane can berepresented using two reals and aBoolean (for example)
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 Hulls12
![Page 13: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/13.jpg)
Description size
A simple polygon in the plane can be represented using 2n reals ifit has n vertices (and necessarily, n edges)
A set of n points requires 2n reals
A set of n 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 Hulls13
![Page 14: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/14.jpg)
Computation time
Any computation (distance, intersection) on two objects of O(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 Hulls14
![Page 15: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/15.jpg)
Algorithms, efficiency
Recall from your algorithms and data structures course:
A set of n real numbers can be sorted in O(n logn) time
A set of n 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 Hulls15
![Page 16: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/16.jpg)
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 problemsthat arise in various applications and how geometric algorithms canhelp to solve well-defined versions of such problems
Computational Geometry Lecture 1: Introduction and Convex Hulls16
![Page 17: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/17.jpg)
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 Hulls17
![Page 18: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/18.jpg)
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 pollutionmeasurements
Computing a collision-free path between obstacles
Computing similarity of two shapes for shape databaseretrieval
Computational Geometry Lecture 1: Introduction and Convex Hulls18
![Page 19: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/19.jpg)
Computational geometry history
Early 70s: First attention for geometric problems from algorithmsresearchers
1976: First PhD thesis in computational geometry (MichaelShamos)
1985: First Annual ACM Symposium on Computational Geometry.Also: first textbook
1996: CGAL: first serious implementation effort for robustgeometric algorithms
1997: First handbook on computational geometry (second one in2000)
Computational Geometry Lecture 1: Introduction and Convex Hulls19
![Page 20: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/20.jpg)
Convexity
A shape or set is convex if for anytwo points that are part of theshape, the whole connecting linesegment is also part of the shape
Question: Which of the followingshapes are convex? Point, linesegment, line, circle, disk, quadrant?
Computational Geometry Lecture 1: Introduction and Convex Hulls20
![Page 21: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/21.jpg)
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 Hulls21
![Page 22: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/22.jpg)
Convex hull problem
Give an algorithm that computes theconvex hull of any given set of npoints in the plane efficiently
The input has 2n coordinates, soO(n) size
Question: Why can’t we expect todo any better than O(n) time?
Computational Geometry Lecture 1: Introduction and Convex Hulls22
![Page 23: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/23.jpg)
Convex hull problem
Assume the n points are distinct
The output has at least 4 and at most 2n coordinates, so it hassize between O(1) and O(n)
The output is a convex polygon so it should be returned as asorted sequence of the points, clockwise (CW) along the boundary
Question: Is there any hope of finding an O(n) time algorithm?
Computational Geometry Lecture 1: Introduction and Convex Hulls23
![Page 24: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/24.jpg)
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 ofthe input
Property: The supporting line of anyconvex hull edge has all input pointsto one side
p q
all points lie right of thedirected line from p to q,if the edge from p to q isa CW convex hull edge
Computational Geometry Lecture 1: Introduction and Convex Hulls24
![Page 25: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/25.jpg)
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 ofthe input
Property: The supporting line of anyconvex hull edge has all input pointsto one side
p
q
all points lie right of thedirected line from p to q,if the edge from p to q isa CW convex hull edge
Computational Geometry Lecture 1: Introduction and Convex Hulls25
![Page 26: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/26.jpg)
Developing an algorithm
Algorithm SlowConvexHull(P)Input. A set P of points in the plane.Output. A list L containing the vertices of CH(P) in clockwise
order.1. E← /0.2. for all ordered pairs (p,q) ∈ P×P 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 q6. 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 Hulls26
![Page 27: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/27.jpg)
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 Hulls27
![Page 28: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/28.jpg)
Developing an algorithm
Another approach: incremental, from left to right
Let’s 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 sofar
Computational Geometry Lecture 1: Introduction and Convex Hulls28
![Page 29: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/29.jpg)
Developing an algorithm
Observation: from left toright, there are only right turnson the upper hull
Computational Geometry Lecture 1: Introduction and Convex Hulls29
![Page 30: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/30.jpg)
Developing an algorithm
Initialize by inserting theleftmost two points
Computational Geometry Lecture 1: Introduction and Convex Hulls30
![Page 31: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/31.jpg)
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 Hulls31
![Page 32: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/32.jpg)
Developing an algorithm
If we add the fourth point weget a left turn at the thirdpoint
Computational Geometry Lecture 1: Introduction and Convex Hulls32
![Page 33: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/33.jpg)
Developing an algorithm
. . . so we remove the thirdpoint from the upper hullwhen we add the fourth
Computational Geometry Lecture 1: Introduction and Convex Hulls33
![Page 34: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/34.jpg)
Developing an algorithm
If we add the fifth point we geta left turn at the fourth point
Computational Geometry Lecture 1: Introduction and Convex Hulls34
![Page 35: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/35.jpg)
Developing an algorithm
. . . so we remove the fourthpoint when we add the fifth
Computational Geometry Lecture 1: Introduction and Convex Hulls35
![Page 36: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/36.jpg)
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 Hulls36
![Page 37: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/37.jpg)
Developing an algorithm
We also just add the seventhpoint
Computational Geometry Lecture 1: Introduction and Convex Hulls37
![Page 38: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/38.jpg)
Developing an algorithm
When adding the eight point. . . we must remove theseventh point
Computational Geometry Lecture 1: Introduction and Convex Hulls38
![Page 39: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/39.jpg)
Developing an algorithm
. . . we must remove theseventh point
Computational Geometry Lecture 1: Introduction and Convex Hulls39
![Page 40: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/40.jpg)
Developing an algorithm
. . . and also the sixth point
Computational Geometry Lecture 1: Introduction and Convex Hulls40
![Page 41: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/41.jpg)
Developing an algorithm
. . . and also the fifth point
Computational Geometry Lecture 1: Introduction and Convex Hulls41
![Page 42: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/42.jpg)
Developing an algorithm
After two more steps we get:
Computational Geometry Lecture 1: Introduction and Convex Hulls42
![Page 43: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/43.jpg)
The pseudo-code
Algorithm ConvexHull(P)Input. A set P of points in the plane.Output. A list containing the vertices of CH(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 first
point.3. for i← 3 to n4. do Append pi to Lupper.5. while Lupper contains 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 Hulls43
![Page 44: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/44.jpg)
The pseudo-code
Then we do the same for thelower convex hull, from rightto left
We remove the first and lastpoints of the lower convex hull
. . . and concatenate the twolists into one
p1, p2, p10, p13, p14
p14, p12, p8, p4, p1
Computational Geometry Lecture 1: Introduction and Convex Hulls44
![Page 45: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/45.jpg)
Algorithm analysis
Algorithm analysis generally has two components:
proof of correctness
efficiency analysis, proof of running time
Computational Geometry Lecture 1: Introduction and Convex Hulls45
![Page 46: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/46.jpg)
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 Hulls46
![Page 47: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/47.jpg)
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 Hulls47
![Page 48: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/48.jpg)
The pseudo-code
Algorithm ConvexHull(P)Input. A set P of points in the plane.Output. A list containing the vertices of CH(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 first
point.3. for i← 3 to n4. do Append pi to Lupper.5. while Lupper contains 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 Hulls48
![Page 49: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/49.jpg)
Efficiency
The sorting step takes O(n logn) time
Adding 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 Hulls49
![Page 50: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/50.jpg)
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 Hulls50
![Page 51: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/51.jpg)
Final result
The convex hull of a set of n points in the plane can be computedin O(n logn) time, and this is optimal
Computational Geometry Lecture 1: Introduction and Convex Hulls51
![Page 52: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/52.jpg)
Other approaches: divide-and-conquer
Divide-and-conquer: split thepoint set in two halves, computethe convex hulls recursively, andmerge
A merge involves finding “extremevertices” in every direction
Computational Geometry Lecture 1: Introduction and Convex Hulls52
![Page 53: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/53.jpg)
Other approaches: divide-and-conquer
Alternatively: split the point setin two halves on x-coordinate,compute the convex hullsrecursively, and merge
A merge now comes down tofinding two common tangent lines
Computational Geometry Lecture 1: Introduction and Convex Hulls53
![Page 54: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/54.jpg)
Convex hulls in 3D
For a 3-dimensional point set, theconvex hull is a convexpolyhedron
It has vertices (0-dim.), edges(1-dim.), and facets (2-dim.) inits boundary, and a 3-dimensionalinterior
The boundary is a planar graph,so it has O(n) vertices, edges andfacets
Computational Geometry Lecture 1: Introduction and Convex Hulls54
![Page 55: Lecture 1: Introduction and Convex Hulls · 4 Computational Geometry Lecture 1: Introduction and Convex Hulls. Other shapes: rectangles, circles, disks A circle is only the boundary,](https://reader033.fdocuments.in/reader033/viewer/2022060416/5f13d1048a53bd75a63ba940/html5/thumbnails/55.jpg)
Convex hulls in 4D
For a 4-dimensional point set, the convex hull is a convexpolyhedron
It has vertices (0-dim.), edges (1-dim.), 2-facets (2-dim.), and3-facets (3-dim.) in its boundary, and a 4-dimensional interior
Its boundary can have Θ(n2) facets in the worst case!
Computational Geometry Lecture 1: Introduction and Convex Hulls55