Special case: 2-Dimensional space
Graham's Scan
- First choose a trivial point that it must be in convex hull (leftmost and lowest).
- sort all the other points in polar angle order, getting .
- let (reversed order).
- let .
- while do the following:
If or is convex, then let , and .
If not, .
- then is a convex hull
Implementation Issue:
Polar angle sort may cause dividing by , or two points with the same tangent.
Optimizing: Monotone Chain
Divide the question into upper convex hull and lower convex hull,
and there are points at infinitely low and infinitely high respectively.
Then we don't really need to do polar angle sort, what we need is just sort by coordinate.
Implementation