home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gems / gemsiii / forfac.c < prev    next >
C/C++ Source or Header  |  1992-03-16  |  2KB  |  58 lines

  1. /**************************************************************************
  2. This program illustrates the calculation of delta form-factors for the cubic tetrahedral algorithm.  The delta form-factor of each shaded cell in Fig. 2 
  3. is computed and displayed.
  4. **************************************************************************/
  5.  
  6. #include <math.h>
  7.  
  8. #define MIN   -2.0        /* Minimum value of a ct coordinate */
  9. #define MAX    1.0        /* Maximum value of a ct coordinate */
  10. #define SUBDIV 8        /* Number of cell subdivisions */
  11.  
  12. /* Calculate the form-factor of a cell centered at (u,v) with area a. */
  13.  
  14. float formFactor(u, v, a)
  15.   float u, v, a;
  16. {
  17.   float    r = u*u + v*v + 1;
  18.   return (a * (u + v + 1) / (M_PI * r*r * sqrt(3.0)));
  19. }
  20.  
  21.  
  22.  
  23.  
  24. main ()
  25. {
  26.   int    left, right, top, bottom,    /* Cell index boundaries */
  27.         row, column;        /* Current cell indices */
  28.  
  29.   float     delta, halfDelta,    /* Cell sizes */
  30.         area, halfArea,        /* Cell areas */
  31.         y, z;            /* Cell center location */
  32.  
  33. /* Initialize index values */
  34.  
  35.   left = 1;  right = SUBDIV;  
  36.   top  = 1;  bottom = (SUBDIV + 1) / 2;
  37.   row  = 1;  column = 1;
  38.  
  39. /* Initialize cell values */
  40.  
  41.   delta = (MAX - MIN) / SUBDIV;  halfDelta = delta / 2.0;
  42.   area  = delta * delta;         halfArea  = area / 2.0;
  43.   y = z = MAX - halfDelta;
  44.  
  45. /* Calculate and display delta form factors */
  46.  
  47.   for (row = top; row <= bottom; row++) {
  48.     for (column = left; column < right; column++) {
  49.       printf("Cell(%0d,%0d) = %f\n", row, column, formFactor(y, z, area));
  50.       y -= delta;
  51.     }
  52.     printf("Cell(%0d,%0d) = %f\n", row, column,
  53.       formFactor(y+halfDelta, z+halfDelta, halfArea));
  54.     left++;  right--;
  55.     y = z -= delta;
  56.   }
  57. }
  58.