Pseudocode
First, define
# Three points are a counter-clockwise turn if ccw > 0, clockwise if # ccw < 0, and collinear if ccw = 0 because ccw is a determinant that # gives the signed area of the triangle formed by p1, p2 and p3. function ccw(p1, p2, p3): return (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x)Then let the result be stored in the array points
.
This pseudocode is adapted from Sedgewick and Wayne's Algorithms, 4th edition.
The check inside the while statement is necessary to avoid the case when all points in the set are collinear.
Read more about this topic: Graham Scan
Related Phrases
Related Words