Angle(p1, p2, p3)
to compute the angle between these three points.
IsNonLeftTurn(p1, p2, p3)
to return true if $\overrightarrow{p_1p_2} $ to $\overrightarrow{p_2p_3}$ is a non left turn.
GRAHAM_SCAN(P)
- Let
lowest
be the left most lowest point in P.- Let right = (p.x+10, p.y)
- For each p in P
- p.angle = Angle(right, lowest, p)
- End For
- Scan P remove the closest points with duplicate angles.
- Sort P by p.angle
- S.push(P[0]) // lowest
- S.push(P[1])
- S.push(P[2])
- For i = 3 to P.size do
- While IsNonLeftTurn(S[top-1], S[top], P[i])
- S.pop()
- End While
- S.push(P[i])
- End For
- return S.
lowest
must be on the hull, and is placed on the stack