Graham Scan Algorithm

Primal Algorithm

The input is a set of points, Q.

1. Pick a point P with minimum x coordinate from the set Q. If there are several then pick the one with smallest y coordinate.

2. Sort all the other points angularly around the vertex P.


Please enable Java for an interactive construction (with Cinderella).


Please enable Java for an interactive construction (with Cinderella).


3. Initially form an edge with the point of the minimum slope. If there are several points with such slope then choose the point which has the smallest y-coordinate.

Please enable Java for an interactive construction (with Cinderella).


4. At step i, vi from the set of points Q is inserted. If the angle v(i)v(i-1)u is convex (or if it is a right turn), then v(i-1) is discarded as an interior point and uv(i) is added as an edge of the convex hull.


Please enable Java for an interactive construction (with Cinderella).


5. Stop when you have reached the point of maximum x coordinate or if there are several such points, then stop when you have reached the point with the smallest y coordinate. Else jump to 4.

Please enable Java for an interactive construction (with Cinderella).


6. Output is the set of convex hull points in counter clockwise order.

NEXT


Beenish Chaudry
Last modified: Tue Apr 4 03:36:19 EDT 2000