convex hulls (2d)misha/spring16/06.pdfconvex hull (2d) naΓ―ve algorithm (π3): for each directed...
TRANSCRIPT
![Page 1: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/1.jpg)
Convex Hulls (2D)
OβRourke, Chapter 3
![Page 2: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/2.jpg)
Announcements
β’ We are live on Piazza:
http://piazza.com/jhu/spring2016/600459
β’ Code-base was updated last Wednesday
(Fixes a bug where π¦-values are read in as zero)
![Page 3: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/3.jpg)
Outline
β’ Convex Hulls
β’ Algorithms NaΓ―ve Implementation(s)
Gift Wrapping
Quick Hull
Grahamβs Algorithm
Lower bound complexity
![Page 4: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/4.jpg)
Convexity
A set π is convex if for any two points π, π β π the
line segment ππ β π.
p
q
Not convex
SS
Convex?
![Page 5: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/5.jpg)
Convexity
A set π is convex if it is the intersection of (possibly
infinitely many) half-spaces.
p
q
Not convex
SS
Convex?
![Page 6: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/6.jpg)
Convexity
Given points π1, β¦ , ππ β βπ, a point π β βπ is a
convex combination of the points if π can be
expressed as the linear sum:
π =
π=1
π
πΌπ β ππ
with πΌπ β₯ 0 and πΌ1 + β― + πΌπ = 1.
![Page 7: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/7.jpg)
Convex Hull
The convex hull of a set of points π β βπ,
denoted β(π), is the: set of all convex combinations of points in π,
set of all convex combinations of π + 1 points in π,
intersection of all convex sets πΆ w/ π β πΆ,
intersection of all half-spaces π» w/ π β π»,
smallest convex polygon containing π.β(π)
π1
ππ
![Page 8: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/8.jpg)
Convex Hull
Note:
If π β π β β2 and π is a vertex of the convex
hull then π must be a convex vertex.
Otherwise, we could create
a line segment with vertices
inside of the hull but which
isnβt strictly interior.
π
![Page 9: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/9.jpg)
Convex Hull
Claim:
If π β β2 is a polygon whose vertices are all
convex, then π is convex.
![Page 10: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/10.jpg)
Convex Hull
Proof (by induction):
Otherwise, we could add a diagonal.
β By induction, each half is convex.
![Page 11: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/11.jpg)
Convex Hull
Proof (by induction):
Otherwise, we could add a diagonal.
β If π is not convex there must be a segment
between the two parts that exits π.Choose π1 and π2 above/below the diagonal.
Evolve the segment to π1π2.
Since π1 and π2 are above/below,
π1π2 crosses the diagonal and
is entirely inside π.π1
π2
![Page 12: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/12.jpg)
Convex Hull
Proof (by induction):
Otherwise, we could add a diagonal.
β If π is not convex there must be a segment
between the two parts that exits π.Choose π1 and π2 above/below the diagonal.
Evolve the segment to π1π2.
Since π1 and π2 are above/below,
π1π2 crosses the diagonal and
is entirely inside π.
The last point at which the
evolving segment is not fully
inside must be a reflex vertex.
π1
π2
![Page 13: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/13.jpg)
Convex Hull
The extreme points of a set of points π β β2
are the points which are on the convex hull
and have interior angle strictly less than π.
β(π)π1
ππ
![Page 14: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/14.jpg)
Convex Hull
Goal:
Given a set of points S = π1, β¦ , ππ β βπ,
compute the convex hull β(π) efficiently.
β’ Do we want all points on the hull or just the
extreme ones?
β’ Do the output vertices need
to be sorted or is the set of
(extreme) vertices sufficient?
β(π)π1
ππ
![Page 15: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/15.jpg)
Convex Hull
Goal:
Given a set of points S = π1, β¦ , ππ β βπ,
compute the convex hull β(π) efficiently.
β’ Do we want all points on the hull or just the
extreme ones?
β’ Do the output vertices need
to be sorted or is the set of
(extreme) vertices sufficient?
β(π)π1
ππ
We will focus on the ordered output
of the extreme points on the hull.
![Page 16: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/16.jpg)
Convex Hull (2D)
Note:
We can find a hull vertex in linear time by
finding the vertex that is extremal w.r.t. to
some direction.
![Page 17: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/17.jpg)
Outline
β’ Convex Hulls
β’ Algorithms NaΓ―ve Implementation(s)
Gift Wrapping
Quick Hull
Grahamβs Algorithm
Lower bound complexity
![Page 18: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/18.jpg)
Convex Hull (2D)
NaΓ―ve Algorithm:
For each directed edge π β π Γ π, check if the
half-space to the right of π is empty of points
(and there are no
points on the line
outside the segment).
If the rest of the
points are on one
side, the segment
is on the hull
Otherwise the segment
is not on the hull
![Page 19: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/19.jpg)
Convex Hull (2D)
NaΓ―ve Algorithm π(π3):For each directed edge π β π Γ π, check if
half-space to the right of π is empty of points
(and there are no
points on the line
outside the segment).
Note:
The output is the set
of (unordered) extreme
points on the hull.
![Page 20: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/20.jpg)
Convex Hull (2D)
NaΓ―ve Algorithm π(π3):For each directed edge π β π Γ π, check if
half-space to the right of π is empty of points
(and there are no
points on the line
outside the segment).
Note:
The output is the set
of (unordered) extreme
points on the hull.If we want the ordered points, we can stitch the edges
together in β€ π(π2) time in a post-processing step.
![Page 21: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/21.jpg)
Convex Hull (2D)
NaΓ―ve Algorithm++:
Grow the hull by starting at a hull vertex and
searching for the next edge on the hull by
trying all possible edges and testing if they
are on the hull.
![Page 22: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/22.jpg)
Convex Hull (2D)
NaΓ―ve Algorithm++ π(π2β)*:
Grow the hull by starting at a hull vertex and
searching for the next edge on the hull by
trying all possible edges and testing if they
are on the hull.
Note:
By explicitly forcing the
output to be sorted, we
end up with a faster
algorithm.*β is the number of points on the hull.
![Page 23: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/23.jpg)
Convex Hull (2D)
NaΓ―ve Algorithm++ π(π2β)*:
Grow the hull by starting at a hull vertex and
searching for the next edge on the hull by
trying all possible edges and testing if they
are on the hull.
Note:
By explicitly forcing the
output to be sorted, we
end up with a faster
algorithm.This implementation is output sensitive.*β is the number of points on the hull.
![Page 24: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/24.jpg)
Outline
β’ Convex Hulls
β’ Algorithms NaΓ―ve Implementation(s)
Gift Wrapping
Quick Hull
Grahamβs Algorithm
Lower bound complexity
![Page 25: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/25.jpg)
Convex Hull (2D)
Note:
The next edge on the hull is the one making
the largest angle. (If two points make the
same angle, ignore the closer one.)
Gift Wrapping:
Grow by finding the edge
making the largest angle.
![Page 26: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/26.jpg)
Convex Hull (2D)
Note:
The next edge on the hull is the one making
the largest angle. (If two points make the
same angle, ignore the closer one.)
Gift Wrapping π(πβ):Grow by finding the edge
making the largest angle.
![Page 27: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/27.jpg)
Convex Hull (2D)
Note:
The next edge on the hull is the one making
the largest angle. (If two points make the
same angle, ignore the closer one.)
Gift Wrapping π(πβ):Grow by finding the edge
making the largest angle.A similar approach makes it possible to find
a hull edge in linear time.
![Page 28: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/28.jpg)
Outline
β’ Convex Hulls
β’ Algorithms NaΓ―ve Implementation(s)
Gift Wrapping
Quick Hull
Grahamβs Algorithm
Lower bound complexity
![Page 29: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/29.jpg)
Convex Hull (2D)
Observation:
Given a hull edge (π, π), we can find the point
π furthest from the edge in linear time.
1. The point π is on the hull.
2. The triangle Ξπππpartitions the input
into three regions:I. Points inside Ξπππ.
II. Points to the right of ππ.
III. Points to the right of ππ.
π
π
π
![Page 30: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/30.jpg)
Convex Hull (2D)
Observation:
Given a hull edge (π, π), we can find the point
π furthest from the edge in linear time.
β Divide-and-conquer: Discard points inside Ξπππ
Separately compute the
half-hulls to the right of
ππ and the right of ππ.
Merge the two hulls.
π
π
π
![Page 31: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/31.jpg)
Convex Hull (2D)
Observation:
Given a hull edge (π, π), we can find the point
π furthest from the edge in linear time.
β Divide-and-conquer: Discard points inside Ξπππ
Separately compute the
half-hulls to the right of
ππ and the right of ππ.
Merge the two hulls.
π
π
π
We donβt require ππ to be a hull edge.
As long as itβs a hull diagonal merging is easy.
![Page 32: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/32.jpg)
Convex Hull (2D)
QuickHull( π β β2 ) (π, π) β HorizontalExtrema( π )
π΄ β RightOf( π , ππ )
π΅ β RightOf( π , ππ )
ππ΄ β QuickHalfHull( π΄ , ππ )
ππ΅ β QuickHalfHull( π΅ , ππ ) return π βͺ ππ΄ βͺ π βͺ ππ΅
![Page 33: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/33.jpg)
Convex Hull (2D)
QuickHull( π β β2 ) (π, π) β HorizontalExtrema( πΊ )
π΄ β RightOf( π , ππ )
π΅ β RightOf( π , ππ )
ππ΄ β QuickHalfHull( π΄ , ππ )
ππ΅ β QuickHalfHull( π΅ , ππ ) return π βͺ ππ΄ βͺ π βͺ ππ΅
ππ
![Page 34: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/34.jpg)
Convex Hull (2D)
QuickHull( π β β2 ) (π, π) β HorizontalExtrema( π )
π¨ β RightOf( πΊ , ππ )
π© β RightOf( πΊ , ππ )
ππ΄ β QuickHalfHull( π΄ , ππ )
ππ΅ β QuickHalfHull( π΅ , ππ ) return π βͺ ππ΄ βͺ π βͺ ππ΅
π΄
π΅
ππ
![Page 35: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/35.jpg)
Convex Hull (2D)
QuickHull( π β β2 ) (π, π) β HorizontalExtrema( π )
π΄ β RightOf( π , ππ )
π΅ β RightOf( π , ππ )
πΈπ¨ β QuickHalfHull( π¨ , ππ )
πΈπ© β QuickHalfHull( π© , ππ ) return π βͺ ππ΄ βͺ π βͺ ππ΅
ππ΅
ππ΄
ππ
![Page 36: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/36.jpg)
Convex Hull (2D)
QuickHull( π β β2 ) (π, π) β HorizontalExtrema( π )
π΄ β RightOf( π , ππ )
π΅ β RightOf( π , ππ )
ππ΄ β QuickHalfHull( π΄ , ππ )
ππ΅ β QuickHalfHull( π΅ , ππ ) return π βͺ πΈπ¨ βͺ π βͺ πΈπ©
![Page 37: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/37.jpg)
ππ
Convex Hull (2D)
(Recursion Level 0)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( π , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
![Page 38: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/38.jpg)
π
ππ
Convex Hull (2D)
(Recursion Level 0)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( πΊ , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
![Page 39: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/39.jpg)
π
ππ
Convex Hull (2D)
(Recursion Level 0)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β
else
Β» π β Furthest( π , ππ )Β» π¨ β RightOf( πΊ , ππ )
Β» π© β RightOf( πΊ , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
π΅π΄
![Page 40: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/40.jpg)
π
π
π
Convex Hull (2D)
(Recursion Level 0)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( π , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» πΈπ¨ β QuickHalfHull( π¨ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
π΄
![Page 41: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/41.jpg)
π
π
Convex Hull (2D)
(Recursion Level 1)
QuickHalfHull( π β β2, ππ β π Γ π ) if( πΊ == β ) return β else
Β» π β Furthest( π , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
![Page 42: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/42.jpg)
π
ππ
Convex Hull (2D)
(Recursion Level 0)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( π , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» πΈπ© β QuickHalfHull( π© , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
π΅ππ΄
![Page 43: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/43.jpg)
π
π
π
Convex Hull (2D)
(Recursion Level 1)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( πΊ , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
![Page 44: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/44.jpg)
π
π
π
Convex Hull (2D)
(Recursion Level 1)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( π , ππ )Β» π¨ β RightOf( πΊ , ππ )
Β» π© β RightOf( πΊ , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
π΅
π΄
![Page 45: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/45.jpg)
π
π
π
Convex Hull (2D)
(Recursion Level 1)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( π , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» πΈπ¨ β QuickHalfHull( π¨ , ππ )
Β» πΈπ© β QuickHalfHull( π© , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
ππ΅
ππ΄
![Page 46: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/46.jpg)
π
π
π
Convex Hull (2D)
(Recursion Level 1)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( π , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return πΈπ¨ βͺ π βͺ πΈπ©
![Page 47: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/47.jpg)
π
ππ
Convex Hull (2D)
(Recursion Level 0)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( π , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» πΈπ¨ β QuickHalfHull( π¨ , ππ )
Β» πΈπ© β QuickHalfHull( π© , ππ )Β» return ππ΄ βͺ π βͺ ππ΅
ππ΅ππ΄
![Page 48: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/48.jpg)
π
ππ
Convex Hull (2D)
(Recursion Level 0)
QuickHalfHull( π β β2, ππ β π Γ π ) if( π == β ) return β else
Β» π β Furthest( π , ππ )Β» π΄ β RightOf( π , ππ )
Β» π΅ β RightOf( π , ππ )Β» ππ΄ β QuickHalfHull( π΄ , ππ )
Β» ππ΅ β QuickHalfHull( π΅ , ππ )Β» return πΈπ¨ βͺ π βͺ πΈπ©
![Page 49: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/49.jpg)
Convex Hull (2D)
QuickHull Complexity:
Like QuickSort: In the worst case, the complexity can be π(π2).
![Page 50: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/50.jpg)
Convex Hull (2D)
QuickHull Complexity:
Like QuickSort: In the worst case, the complexity can be π(π2).
![Page 51: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/51.jpg)
Convex Hull (2D)
QuickHull Complexity:
Like QuickSort: In the worst case, the complexity can be π(π2).
![Page 52: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/52.jpg)
Convex Hull (2D)
QuickHull Complexity:
Like QuickSort: In the worst case, the complexity can be π(π2).
![Page 53: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/53.jpg)
Convex Hull (2D)
QuickHull Complexity:
Like QuickSort: In the worst case, the complexity can be π(π2).
![Page 54: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/54.jpg)
Convex Hull (2D)
QuickHull Complexity:
Like QuickSort: In the worst case, the complexity can be π(π2). In practice it is π π log π .
The implementation is output sensitive.
Does it extend to higher dimensions?
![Page 55: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/55.jpg)
Outline
β’ Convex Hulls
β’ Algorithms NaΓ―ve Implementation(s)
Gift Wrapping
Quick Hull
Grahamβs Algorithm
Lower bound complexity
![Page 56: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/56.jpg)
Convex Hull (2D)
Grahamβs Observation:
If π β β2 is a convex polygon and π β π is a point in
the interior of the polygon, then the angle of the line
segments between π and the ordered vertices of πis monotonic.
π
π
![Page 57: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/57.jpg)
Convex Hull (2D)
Grahamβs Observation:
WLOG assume π and π£π lie on a vertical line with πbelow π£π.
Since the polygon is convex, π is to the left of π£ππ£π+1.
β π£π+1 is to the left of the vertical.
Since the polygon is convex, π is to the left of π£πβ1π£π.
β π£πβ1 is to the right of the vertical.
β The angles β ππ£πβ1, β ππ£π, β ππ£π+1
increase monotonically.
π
π£πβ1
π£π
π£π+1
![Page 58: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/58.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β PointInHull( π ) π» β SortByAngle( π , π ) while( RemoveReflexVertex( π» ) ){ } return π»
![Page 59: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/59.jpg)
GrahamScan( π β β2 ) π β PointInHull( π ) π» β SortByAngle( π , π ) while( RemoveReflexVertex( π» ) ){ } return π»
Note:
At every iteration, the vertices of π» are sorted by
angle relative to π.
β Hull vertices can never be removed because the
angle between the previous and next vertex is
always convex.
Convex Hull (2D)
π
π£πβ1
π£π+1
π£π
![Page 60: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/60.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β PointInHull( π ) π» β SortByAngle( π , π ) while( RemoveReflexVertex( π» ) ){ } return π»
Correctness:
The output polygon has only convex vertices.
β Itβs convex.
β π» β β(π).
All hull vertices are in π».
β β π β π».
![Page 61: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/61.jpg)
Convex Hull (2D)
GrahamScan( π β β2 )
![Page 62: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/62.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π
![Page 63: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/63.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} )
π1
2
34
5
6
78
9
10
![Page 64: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/64.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π
π1
π2
π3
π4
π6
π7
π5
![Page 65: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/65.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
π2
π3
π4
π6
π7
π5
π
π1
Note:
Since π is bottom-(right)-most,
vertices are sorted by angle in
0, π , and non-extreme points
are removed, ππ1 is on the hull.
![Page 66: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/66.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β» if( Left( ππ , LastEdge( πΈ ) )β Push( ππ , πΈ )β π β π + π
Β»elseβ Pop( π )
π3
π4
π6
π7
π5
π2
π
π1
![Page 67: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/67.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β» if( Left( ππ , LastEdge( πΈ ) )β Push( ππ , πΈ )β π β π + π
Β»elseβ Pop( π )
π3
π4
π6
π7
π5
π
π1
π2
![Page 68: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/68.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β»if( Left( ππ , LastEdge( π ) )β Push( ππ , π )β π β π + 1
Β»elseβ Pop( πΈ )
π4
π6
π7
π5
π2
π
π1
π3
![Page 69: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/69.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β» if( Left( ππ , LastEdge( πΈ ) )β Push( ππ , πΈ )β π β π + π
Β»elseβ Pop( π )
π4
π6
π7
π5
π
π3
π2
π1
![Page 70: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/70.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β» if( Left( ππ , LastEdge( πΈ ) )β Push( ππ , πΈ )β π β π + π
Β»elseβ Pop( π )
π6
π7
π5
π
π2
π1
π4
π3
![Page 71: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/71.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β»if( Left( ππ , LastEdge( π ) )β Push( ππ , π )β π β π + 1
Β»elseβ Pop( πΈ )
π6
π7
π5
π
π2
π1
π4
π3
![Page 72: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/72.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β» if( Left( ππ , LastEdge( πΈ ) )β Push( ππ , πΈ )β π β π + π
Β»elseβ Pop( π )
π7
π5
π
π2
π1
π4
π3
π6
![Page 73: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/73.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β» if( Left( ππ , LastEdge( πΈ ) )β Push( ππ , πΈ )β π β π + π
Β»elseβ Pop( π )
π6
π7
π
π2
π1
π5
π4
π3
![Page 74: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/74.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β»if( Left( ππ , LastEdge( π ) )β Push( ππ , π )β π β π + 1
Β»elseβ Pop( π )
π6
π7
π
π2
π1
π5
π4
π3
![Page 75: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/75.jpg)
Convex Hull (2D)
GrahamScan( π β β2 ) π β BottommostRightmost( π )
π β SortByAngleAndLength( π , π β {π} ) if( angle(ππ) == angle(ππ+1) ): π β π β ππ
π β 2
π β π, π1
while( π < π )
Β»if( Left( ππ , LastEdge( π ) )β Push( ππ , π )β π β π + 1
Β»elseβ Pop( π )
π(π)
π(π log π)
π(π)
π(π)
![Page 76: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/76.jpg)
Outline
β’ Convex Hulls
β’ Algorithms NaΓ―ve Implementation(s)
Gift Wrapping
Quick Hull
Grahamβs Algorithm
Lower bound complexity
![Page 77: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/77.jpg)
Lower Bound Complexity
Recall:
Sorting π numbers has lower bound complexity
π π log π .
Approach:
We will show that computing the 2D hull has the
same complexity by reducing sorting to the problem
of computing the convex hull.
![Page 78: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/78.jpg)
Lower Bound Complexity
Sorting β Convex Hull Reduction (Shamos):
Given a set of points π₯π β β:
Choose a function π(π₯) w/ πβ²β² π₯ > 0
Lift the points onto the curve
Compute the convex hull
Return the points on the
lower hull, starting w/
the left-most.
π₯4π₯5π₯3π₯2 π₯2 π₯0
π¦ = π(π₯)
![Page 79: Convex Hulls (2D)misha/Spring16/06.pdfConvex Hull (2D) NaΓ―ve Algorithm (π3): For each directed edge βπΓπ, check if half-space to the right of is empty of points (and there](https://reader035.vdocuments.site/reader035/viewer/2022081607/5ec72257f4da254080258a30/html5/thumbnails/79.jpg)
Lower Bound Complexity
Sorting β Convex Hull Reduction (Shamos):
Given a set of points π₯π β β:
Choose a function π(π₯) w/ πβ²β² π₯ > 0
Lift the points onto the curve
Compute the convex hull
Return the points on the
lower hull, starting w/
the left-most.
π₯4π₯5π₯3π₯2 π₯2 π₯0
π¦ = π(π₯)The reduction assumes that the hull
vertices are output in order.