Finds the lowest p0 and p1 as described above. Sort all other points baised on their polar angle Push the first three points in order onto the stack For all other points in order Check the angle between pi and the top two points on the stack If it is a non left hand turn pop the stack
GrahmScan(Q) (1) find p0 and p1 as above (2) sort Q as above. (3) S.push(p0) (4) S.push(p1) (5) S.push(p2) (6) for i = 3 to n do (7) while S.NextToTop() S.Top and pi make a nonleft turn (8) S.Pop() (9) S.Push(pi)