1
1
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
CG Lecture 1 CG Lecture 1
Convex Hull Algorithms
- 2D
- Basic facts
- Algorithms: Naïve, Gift wrapping, Graham scan, Quick hull,
Divide-and-conquer
- Lower bound
- 3D
- Basic facts
- Algorithms: Gift wrapping, Divide and conquer, incremental
- Convex hulls in higher dimensions
2
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
Convex hull: basic facts Convex hull: basic facts
Problem: give a set of n points P in the plane, compute its convex hull CH(P). Basic facts:
- CH(P) is a convex polygon with complexity O(n).
- Vertices of CH(P) are a subset of the input points P.
Input: Input: p1,…, p13 CH vertices: CH vertices: p1,p2,p11,p12,p13,p9,p3
p9 p3 p1 p11 p2 p12 p13 p8 p4 p5 p7 p10 p6
3
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
Naive algorithm Naive algorithm
Algorithm
- For each pair of points construct its
connecting segment and supporting line.
- Find all the segments whose supporting
lines divide the plane into two halves, such that one half plane contains all the
- ther points.
- Construct the convex hull out of these
segments.
Time complexity
- All pairs:
- Check all points for each pair: O(n)
each, O(n3) total.
2
( 1) ( ) ( ) ( ) 2 2 n n n O O O n ⎛ ⎞ − = = ⎜ ⎟ ⎝ ⎠
No No Yes Yes
4
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
Triangle Area Triangle Area
P2(x2,y2) P3(x3,y3) P1(x1,y1)
2 1 3 1 2 1 3 1 2 1 2 1 3 1 3 1 1 1 2 2 3 3
2 ( ) ( ) sin 1 1 1 Area P P P P P P P P x x y y x x y y x y x y x y α ⋅ = − × − = − ⋅ − − − = − − =
The determinant is twice the area of the triangle whose vertices are the rows of the matrix.
α
5
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
Orientation and point classification Orientation and point classification
- The area sign indicates the orientation of the points.
- Positive area ≡ counterclockwise orientation ≡ left turn.
- Negative area ≡ clockwise orientation ≡ right turn.
- This test can be used to determine whether a given point
is “above” or “below” a given line
1 1 2 2 3 3
1 1 1 2 1 Area x y x y x y =
(x1,y1) (x3,y3) (x2,y2) +
6
Leo Joskowicz, Spring 2005 Leo Joskowicz, Spring 2005
Triangle Area Triangle Area
P2(x2,y2) P3(x3,y3) P1(x1,y1)
2 1 3 1 2 1 3 1 2 1 2 1 3 1 3 1 1 1 2 2 3 3
2 ( ) ( ) sin 1 1 1 Area P P P P P P P P x x y y x x y y x y x y x y α ⋅ = − × − = − ⋅ − − − = − − =
The determinant is twice the area of the triangle whose vertices are the rows of the matrix.
α