Template chull_check documentation

General description:

The template chull_check receives as input two arrays of points, varray and parray.  It returns 1 if varray contains the extremal vertices listed in counter-clockwise order of the convex hull of all the points in varray and parray.   Otherwise, it returns 0.

Algorithm:

The algorithm is divided into two parts.  The first part, chull_check_ext, checks that points in an array varray are the extremal vertices of their convex hull listed in counter-clockwise order.  The second part, chull_check_int, checks that points in an array parray are in the interior or on the boundary of the convex hull of the points in array varray.  The second part has a precondition that points in array varray are the extremal vertices of their convex hull listed in counter-clockwise order.

varray = array [1:numv] of points
parray = array [1:nump] of points

numv = number of points in varray
nump = number of points in parray

chull_check(parray, nump, varray, numv)

  1. if (chull_check_ext(varray, numv) == 0) return(0);
  2. if (chull_check_cont(varray, numv, parray, nump) == 0) return(0);
  3. return(1);
chull_check_ext(varray, numv)
  1. if (numv < 2), then return(1);
  2. if (numv == 2), then
    1. if (varray[1] == varray[2]), then return(0);     /* identical points */
    2. else return(1);
  3. for i = 1 to (numv-2) do
    1. if (varray[i], varray[i+1], varray[i+2]) have right orientation or are collinear, then return(0);
  4. if (varray[numv], varray[1], varray[2]) have right orientation or are collinear, then, return(0);
  5. if (varray[numv-1], varray[numv], varray[1]) have right orientation or are collinear, then return(0);
  6. for i = 2 to (numv-1) do
    1. if (varray[1], varray[i], varray[i+1]) have right orientation or are collinear, then return(0);
  7. return(1);
chull_check_cont(varray, numv, parray, nump)
/* Precondition: points in varray[1..numv] are extremal vertices of their convex hull listed in counter-clockwise order */
  1. if (nump == 0), then return(1);
  2. if (numv > 2), then
    1. for i = 1 to nump do
      1. if (varray[1], varray[2], parray[i]) have right orientation, then return(0);
      2. j <- index of first vertex in varray[3,numv] such that (varray[1], varray[j], parray[i]) have right orientation or are collinear (or j <- numv+1 if there is no such j);
      3. if (j == numv+1), then return(0);   /* (varray[1], varray[numv], parray[i]) have left orientation */
      4. if (varray[j-1], varray[j], parray[i]) have right orientation, then return(0);
  3. else if (numv == 0), then return(0);
  4. else if (numv == 1) then
    1. for i = 1 to nump do
      1. if (parray[i] != varray[1]), then return(0):
  5. else    /* (numv == 2) */
    1. for i = 1 to nump do
      1. if the x-coordinate of parray[i] does not lie on or between the x-coodinates of varray[1] and varray[2], then return(0);
      2. if (varray[1], varray[2], parray[i]) are not collinear, then return(0);
  6. return(1);    /* passed all checks */

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