home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / defs / circle.def < prev    next >
Text File  |  1989-11-09  |  4KB  |  125 lines

  1.  
  2.  
  3. /* Module:    Circle.def
  4.  * Purpose:    Define the coordinates for evenly spaced points on 1/8th of
  5.  *        a unit circle centered at 0,0.
  6.  * Note:    Used to draw circles and ellipses by scaling and symmetrically
  7.  *        adding or subtracting on each axis (circles have 8 fold
  8.  *        symmetry, ellipse code used has only 4 way symmetry).
  9.  * Note:    Sizes must be multiples of 8
  10.  * Note:    48 is an adequate number for decent looking circles, 64 may
  11.  *        be desired for ellipses as the far ends get jaggy with 48.
  12.  * Note:    Code to generate these lists is at end of this file
  13.  */
  14.  
  15. static double Circle48X[12] = {
  16.   -0.06540312923014, -0.19509032201613, -0.32143946530316, -0.44228869021900,
  17.   -0.55557023301960, -0.65934581510007, -0.75183980747898, -0.83146961230255,
  18.   -0.89687274153269, -0.94693012949511, -0.98078528040323, -0.99785892323860
  19. };
  20. static double Circle48Y[12] = {
  21.   -0.99785892323860, -0.98078528040323, -0.94693012949511, -0.89687274153269,
  22.   -0.83146961230255, -0.75183980747898, -0.65934581510007, -0.55557023301960,
  23.   -0.44228869021900, -0.32143946530316, -0.19509032201613, -0.06540312923014
  24. };
  25.  
  26. static double Circle64X[16] = {
  27.   -0.04906767432742, -0.14673047445536, -0.24298017990326, -0.33688985339222,
  28.   -0.42755509343028, -0.51410274419322, -0.59569930449243, -0.67155895484702,
  29.   -0.74095112535496, -0.80320753148064, -0.85772861000027, -0.90398929312344,
  30.   -0.94154406518302, -0.97003125319454, -0.98917650996478, -0.99879545620517
  31. };
  32. static double Circle64Y[16] = {
  33.   -0.99879545620517, -0.98917650996478, -0.97003125319454, -0.94154406518302,
  34.   -0.90398929312344, -0.85772861000027, -0.80320753148064, -0.74095112535496,
  35.   -0.67155895484702, -0.59569930449243, -0.51410274419322, -0.42755509343028,
  36.   -0.33688985339222, -0.24298017990326, -0.14673047445536, -0.04906767432742
  37. };
  38.  
  39. #ifdef NOTNEEDED /* %% not yet needed */
  40. static double Circle80X[20] = {
  41.   -0.03925981575907, -0.11753739745784, -0.19509032201613, -0.27144044986507,
  42.   -0.34611705707749, -0.41865973753743, -0.48862124149695, -0.55557023301960,
  43.   -0.61909394930983, -0.67880074553294, -0.73432250943569, -0.78531693088074,
  44.   -0.83146961230255, -0.87249600707280, -0.90814317382508, -0.93819133592248,
  45.   -0.96245523645365, -0.98078528040323, -0.99306845695493, -0.99922903624072
  46. };
  47. static double Circle80Y[20] = {
  48.   -0.99922903624072, -0.99306845695493, -0.98078528040323, -0.96245523645365,
  49.   -0.93819133592248, -0.90814317382508, -0.87249600707280, -0.83146961230255,
  50.   -0.78531693088074, -0.73432250943569, -0.67880074553294, -0.61909394930983,
  51.   -0.55557023301960, -0.48862124149695, -0.41865973753743, -0.34611705707749,
  52.   -0.27144044986507, -0.19509032201613, -0.11753739745784, -0.03925981575907
  53. };
  54. #endif
  55.  
  56. #ifdef GENERATING_CODE
  57.  
  58. #include <math.h>
  59.  
  60. main(argc, argv)
  61.   int argc;
  62.   char **argv;
  63. {
  64.   double circleX[64], circleY[64];
  65.   int circle_pts, cnt;
  66.   int i, j;
  67.  
  68.   if( argc >= 2 )
  69.     circle_pts = atoi(argv[1]);
  70.   init_circle(circle_pts, circleX, circleY);
  71.   cnt = circle_pts / 4;
  72.  
  73.   (void)printf("static double Circle%dX[%d] = {\n", circle_pts, cnt);
  74.   disp_array(circleX, cnt);
  75.   (void)printf("static double Circle%dY[%d] = {\n", circle_pts, cnt);
  76.   disp_array(circleY, cnt);
  77. }
  78.  
  79. /*
  80.  * Subroutine:    disp_array
  81.  * Purpose:    print out an array in four columns, and with " };"
  82.  */
  83. void disp_array ( arr, cnt )
  84.      double *arr;
  85.      int cnt;
  86. {
  87.   int i, j;
  88.   i=0;
  89.   while( i < cnt ) {
  90.     (void)printf("  %.14f", arr[i]);
  91.     i++;
  92.     for( j=1; (i<cnt) && (j<4); j++ ) {
  93.       (void)printf(", %.14f", arr[i]);
  94.       i++;
  95.     }
  96.     if( i < (cnt - 1) )
  97.       (void)printf(",\n");
  98.   }
  99.   (void)printf("\n};\n");
  100. }
  101.  
  102. /*
  103.  * Subroutine:    init_circle
  104.  * Purpose:    Initialize values of unit circle
  105.  */
  106. void init_circle ( pts, circleX, circleY )
  107.      int pts;
  108.      double *circleX, *circleY;
  109. {
  110.   int subsample;
  111.   int i;
  112.   double inc, angle;
  113.  
  114.   /* SET COORDS FOR 1/8 OF A UNIT CIRCLE (MULTIPLIES GIVE ALL ELSE)  */
  115.   subsample = pts / 4;
  116.   inc = (2.0 * M_PI) / pts;
  117.   angle = inc/2.0;
  118.   for(i=0; i <= subsample; i++) {
  119.     circleX[i] = -sin (angle);
  120.     circleY[i] = -cos (angle);
  121.     angle += inc;
  122.   }
  123. }
  124. #endif
  125.