Template chull_2pass documentation

General description:

The template chull_2pass 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 is a variation of an algorithm by Andrew (IPL, 1979) which is based on an algorithm by Graham (IPL, 1972.)  This variation, by de Berg, van Kreveld, Overmars, Schwarzkopf (Computational Geometry, 1997,) makes two passes
over the set of points, one to construct the lower hull and another one to construct the upper hull.

Algorithm:

parray = array [1:nump] of points

nump = number of points in parray

    /* find vertices of the lower convex hull */
  1. Reorder points in parray[1:nump] so that they are sorted by increasing x-coordinate (break ties by increasing y-coordinate);
  2. m <- 2;
  3. i <- 3;
  4. 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 */

  5. imax <- m;
  6. Reorder points in parray[i:nump] so that they are sorted by decreasing x-coordinate (break ties by decreasing y-coordinate);
  7. 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;
  8. 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:

Version:

Authors & credits:

Created by R. Wenger.


Last updated by R. Wenger: 14 May 1999