Title: Lecture 10 Convex Hull
1Lecture 10 - Convex Hull
- Convex Hull definitions and examples
- Bezier curves have the convex hull property
- Determining a convex hull
- Gift-wrapping
- Divide-and-conquer
- Incremental construction algorithm
2Convex Hull
- The ever-present structure in computational
geometry -Used to construct other
structures -Useful in many applications robot
motion planning, shape analysis etc. - one of the
early success stories in computational geometry
that sparked interest among Computer Scientists
by the invention of O(nlogn) algorithm rather
than a O(n3) algorithm.
3Convex hullsPreliminaries and definitions
Intuitive definition Given a set S P0, P1,
..., Pn-1 of n points in the plane, the convex
hull H(S) is the smallest convex polygon in the
plane that contains all of the points of S.
Imagine nails pounded halfway into the plane at
the points of S. The convex hull corresponds to a
rubber band stretched around them.
4Convex hullsPreliminaries and definitions
Convex polygon A polygon is convex iff for any
two points in the polygon (interior ? boundary)
the segment connecting the points is entirely
within the polygon.
not convex
5Convex hullsPreliminaries and definitions
Vertices A polygon vertex is convex if its
interior angle ??????????? It is reflex if its
interior angle gt ?????????
reflex A reflex vertexdent
convex
In a convex polygon, all the vertices are
convex. In other words, any polygon with a reflex
vertex is not convex.
6Convex hullsPreliminaries and definitions
Convex hull, definition The convex hull H(S) is
the smallest convex set that contains S. A
convex hull cannot have a dent.
7Convex hullsPreliminaries and definitions
The convex hull property of a Bezier curve The
convex hull can also be defined as the set of all
convex combinations of the points P0, P1, , Pn
of S
Think of the n1 points as the control points of
a degree n Bezier curve. Since the control points
satisfy the property above, it follows that a
Bezier curve is entirely contained in the convex
hull of its control points. The convex hull
property of Bezier curves also follows from the
fact that each point on the curve results from
tweening two points that themselves are tweens,
and the tweening of two points forms a convex
combination of them.
8Convex hullsPreliminaries and definitions
- Examples of convex hulls in 2D
- The plane R2
- The half-plane in R2 defined by xgt0
- Circular disks
- Triangles
- Examples of convex hulls in 3D
- The space R3
- Half-spaces
- Spheres
- Tetrahedra
- Lines, rays, line segments, triangles, ellipsoids
9Convex hullsSimple Cases
Computing the convex hull of a single point is
trivial just return that point Computing the
convex hull of two points return the line
segment Computing the convex hull of three points
return the triangle formed by the three points.
Test if the three points are collinear. Need to
determine the computing ordering of the three
points
V
ltV, V1, V2gt CCW
V2
V1
ltV, V1, V2gt CW
10Convex hullsGift-wrapping algorithm (Jarviss
March)
- Resembles selection sort repeatedly find the
item that goes in the next slot - Concept
- Theorem. The line segment l defined by two
points is an edge - of the convex hull iff all other points of the
set lie on - the line defined by l or to one side of it.
- Compute the lowest point L (whose y-coordinate is
smallest) this must be a convex hull vertex -
O(n) - Then pivot a horizontal ray around point L until
it first hits some other point P the segment LP
is an edge of the convex hull - The next point R is selected as the points that
beats all the other points at CCW orientation,
i.e. for any other point R we have ltL, P, RgtCCW - Continue this way until returning to point L
- The process of pivoting the ray around each point
is the selection part of the algorithm to select
the point that follows L on the hull boundary,
seek for point P such that no point lies to the
right of ray LP - The points are examined in turn and the algorithm
keeps track of the rightmost candidate
encountered so far - Examine only those points not yet known to lie on
the convex hull boundary
11Convex hullsGift-wrapping algorithm (Jarviss
March)
12Convex hullsGift-wrapping algorithm (Jarviss
March)
- Efficiency
- Pivoting around the ith point O(n)
- If h points are in the convex hull - O(hn)
- Worst-case running time is O(n2) when all n
points entered by the user are vertices of the
convex hull - In the best case, h3 and get O(n)
- This algorithm is an output-sensitive algorithm
the smaller the output, the faster the algorithm
13Convex hullsDivide and conquer
- Resembles quicksort
- Choose a pivot point P
- Partition the input points into two sets L and
R, containing the points to the left of P
including P itself, and to the right of P, by
comparing x-coordinates - Recursively compute the convex hulls of L and R
- Merge the two sub-hulls into the final output
- Implementation
- To partition the points, sort them by
x-coordinate and take the pivot to be the median
(the median of 2n1 numbers is the (n1)st number
in the list) - No two points may lie on the same vertical (so
that we do not have two or more points with the
median x-coordinate value - Have three base cases if the hull contains one
point, two points, or three points
14Convex hullsDivide and conquer
- Merging
- Want to find a line that touches both sub-hulls
below and a line that touches both sub-hulls
above -
- A naïve algorithm check every possible
combination of one vertex from the left subhull
and one vertex from the right subhull this is
done in O(n2) - Preparata Hong algorithm takes O(n) it is
assumed that the left subhull is ordered CW with
the rightmost point first and the right subhull
is ordered CCW with the leftmost point first
15Convex hullsDivide and conquer
while the line connecting (curr left) and (curr
right) is not lower tangent to both L and
R while the line connecting (curr left) and
(curr right) is not lower tangent to L (curr
left) (next (curr left)) end while while the
line connecting (curr left) and (curr right)
is not lower tangent to R (curr right) (next
(curr right)) end while end while return the
line connecting (curr left) and (curr right) as
the lower tangent Start over with the rightmost
point in L, the leftmost point in R while the
line connecting (curr left) and (curr right)
is not upper tangent to both L and R while the
line connecting (curr left) and (curr right)
is not upper tangent to L end while curr
left) (prev (curr left)) while the line
connecting (curr left) and (curr right) is not
upper tangent to R (curr right) (prev (curr
right)) end while end while return the line
connecting (curr left) and (curr right) as the
upper tangent
16Convex hullsDivide and conquer
- Segment T is lower tangent to a subhull vertex
means both vertices adjacent to that vertex are
above T - Line A is lower tangent to the hull of the set of
points - Line B is not
- Line C is upper tangent to the hull
- Show animation
17Convex hullsDivide and conquer
- Efficiency
- Merging the two subhulls takes O(n) time in the
worst case - Total running time is given by the recurrence
- T(n) O(n) T(k) T(n-k),
- where k number of points in R
- If we use a naïve deterministic algorithm to
determine the pivot P worst case is O(n2) - If we pick the pivot P randomly average case is
O(nlogn)
18Convex hullsIncremental Construction
- Concept
- Given a set of points S V0, V1, , Vn-1, each
point is inserted into an existing convex hull of
the previous points - The algorithm has information about the
relationship between the next input V and the
current convex hull H - If V is inside the hull H, then the algorithm
does nothing - If V is outside the hull H, then the algorithm
merges V into H - incrementalHull(n, V0, V1, ..., Vn-1)
- ConvexPolygon hull V0
- for i 1 to n-1, i
- if (pointInConvexPolygon(Vi, hull))
- continue
- mergeVi into hull
- return hull
- How do we merge V into H? find tangents emanating
from V
19Convex hullsIncremental Construction
- Implementation
- First sort the points so that the next input
point is outside the current hull get running
time O(nlogn) for the algorithm - The first point will be the initial hull
- A flag, type, is maintained that indicates
whether the current hull is a single point
(Point), a line segment (Linear), or a convex
polygon with positive area (Planar) - incrementalHull(n, V0, V1, ..., Vn-1)
- sort(n, V)
- removeDuplicates(n, V)
- type Point
- ConvexPlygon hull0 V0
- for i 1 to n-1, i
- case Point typeLinear hull1Vi break
- case Linear MergeLinear(Vi, hull, type)
break - case Planar MergePlanar(vi, hull) break
- return hull
- If the current hull has one point, the uniqueness
of the points implies that Vi is different from
the one already in the hull and thus the point is
added to the hull and the flag type is changed
accordingly - If the current hull is a line segment (has two
points), the function MergeLinear determines
whether or not the current input point is on the
same line as the line segment. If input is on the
same line, the hull is updated and remains a line - If input point is not on the same line, the
current hull and input point form a triangle. The
triangle is stored as current hull and 1) the
type flag is changed accordingly 2) store the
hull as a set of CCW ordered points
20Convex hullsIncremental Construction
- Once the first triangle, if any, is created by
MergeLinear, the last inserted point that led to
the triangle is stored in hull0 - Use this point to search for the tangent points
formed by the next input point and the current
hull - MergePlanar finds the upper tangent point and the
lower tangent point need two loops - The loops bodies test for visibility
ltV,A,Bgt is CW ltA, Bgt is visible from V
ltV,A,Bgt is CCW ltA, Bgt is not visible from V