Template chull_graham documentation

General description:

The template chull_graham reorders an array of points so that vertices of the convex hull of the points are listed in counter-clockwise order at the beginning of the array. It uses an algorithm by Andrew (IPL, 1979) which is based on an algorithm by Graham (IPL, 1972.)

Algorithm:

parray = array [1:nump] of points

nump = number of points in parray

  1. pmin <- point with min x-coordinate (break ties by min y coordinate);
  2. pmax <- point with max x-coordinate (break ties by max y coordinate);
  3. Reorder the points in parray so that:

  4. /* find vertices of the lower convex hull */

  5. imax <- index of pmax in parray (i.e., pmax = parray[imax]);
  6. Reorder points in parray[2:imax-1] so that they are sorted by increasing x-coordinate (break ties by increasing y-coordinate);
  7. m <- 2;
  8. i <- 3;
  9. while (i <= imax) do
    1. while (m > 1) and (parray[m-1], parray[m], parray[i]) have left orientation or are collinear do
      1. m <- m-1;
    2. m <- m+1;
    3. Switch parray[m] and parray[i];
    4. i <- i+1;


    /* find vertices of the upper convex hull */

  10. imax <- m;
  11. Reorder points in parray[i:nump] so that they are sorted by decreasing x-coordinate (break ties by decreasing y-coordinate);
  12. while (i <= nump) do
    1. while (m > imax) and (parray[m-1], parray[m], parray[i]) have left orientation or are collinear do
      1. m <- m-1;
    2. m <- m+1;
    3. Switch parray[m] and parray[i];
    4. i <- i+1;
  13. while (m >  imax) and (parray[m-1], parray[m], parray[1]) have left orientation or are collinear do
    1. m <- m-1;
    /* final value of m = number of convex hull points */

Template parameters:

Arguments:

Alters:

Requires (preconditions):

Ensures (postconditions):

Calls routines:

Notes:

Version:

Authors & credits:

Created by R. Wenger.
Similar to a C implementation of Andrew's algorithm by K. Clarkson.


Last updated by R. Wenger: 14 May 1999