Convex Hull - 2024
Convex Hull - 2024
P x y P x y
concave convex
The convex hull problem
concave polygon: convex polygon:
3
Convex Hull
Quick Hull Approach
1.Find the point with the minimum x-coordinate, min-x, and another point
with the maximum x-coordinate, max-x.
2.Join these two points with a line L to divide the shape into two parts.
3.For a part, we find the point P furthest from the line. Join the points min-x
and max-x with P to form a triangle. We are sure they are not part of the
convex hull inside the triangle since they are already encapsulated within it.
• This step further divides the problem into two sub-problems and thus is recursive.
The first sub-problem has a new line from points min-x and P. The second sub-
problem has a line from points P and max-x. Repeat step 3 on the sub-problems until
there is no point remaining. Then, we can add the points to be part of the convex hull.
Geometric Primitives
q=(x3,y3)
• Find determinant of
• If determinant is
positive(negative) then q is
to the left(right) of <p1,p2>
• If 0, they are collinear
Check if a point inside a triangle formed by
p1, p2, p3 in clockwise order
p2=(x2,y2)
p3=(x3,y3)
p1=(x1,y1)
• Definition:
Signed area of • Area of a triangle,positive, if the vertices
triangle are listed counterclockwise, or negative
of that area, if the vertices are listed
clockwise
• Value = ½(|determinant|)
• Finding farthest point=|det|
QuickHull
Algorithm
FindHull (Sk, P1, P2)
{
// Find points on convex hull from the set Sk of points
// that are on the right side of the oriented line from P1 to P2
If Sk has no point,
then return.
From the given set of points in Sk, find farthest point (maximum distance
from line PQ), say Pmax, from segment PQ
Add point Pmax to convex hull at the location between P1 and P2
Three points P1, P2, and Pmax partition the remaining points of Sk into 3
subsets: S0, S1, and S2
where S0 are points inside triangle P1 Pmax P2, S1are points on the left side
of the oriented line from P1 to Pmax, and S2 are points on the right side of
the oriented line from P2 to Pmax .
FindHull(S1, P1, Pmax)
FindHull(S2, Pmax, P2)
}
Efficiency of QuickHull algorithm
• Finding point farthest away from line P1P2 can be done in linear time
• This gives same efficiency as quicksort:
• Worst case: Θ( n2)
• Average case: Θ( n log n)
Pmax
P2
P1