home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-ASM_VI.ARJ / PROGC.ZIP / PROGC090.C < prev    next >
Text File  |  1988-05-26  |  2KB  |  47 lines

  1.  
  2. /************************************************************************/
  3. /* Brute force arc generation                                           */
  4. /************************************************************************/
  5.  
  6. brute_arc(xc,yc,xp,yp,a0,a1,color)
  7. int     xc,yc;                  /* Center of the arc                    */
  8. int     xp,yp;                  /* Any point on full circle             */
  9. int     a0,a1;                  /* Starting and ending angle in degrees */
  10. int     color;                  /* Color of the arc                     */
  11.         {
  12.         #include <math.h>
  13.         #define PI 3.1415926
  14.         float   a,b,f,dx,dy;
  15.         int     xa,ya,xb,yb,alpha,delta;
  16.  
  17.         if (xp - xc == 0 && yp - yc == 0)/* Process degenerate case     */
  18.                 {
  19.                 pixel_write(xc,yc,color);
  20.                 return;
  21.                 }
  22.                                         /* Compute major & minor axis   */
  23.         if (get_scanlines() > 200)      f = 480./350.;
  24.         else                            f = 480./200.;
  25.         dx= xp - xc;
  26.         dy=(yp - yc)*f;
  27.         a = sqrt(dx * dx + dy * dy);
  28.         b  = a/f;
  29.                                         /* Compute first point          */
  30.         xa = xc + a * cos((double)(a0 * PI/180.));
  31.         ya = yc + b * sin((double)(a0 * PI/180.));
  32.         delta = 6 * 180./(PI * a);      /* Force 6 pixels per segment   */
  33.                                         /* Loop over segment on ellipse */
  34.         for (alpha = a0; alpha <= a1; alpha = alpha + delta)
  35.                 {                       /* Compute next point on ellipse*/
  36.                 xb = xc + a * cos(alpha * PI/180.);
  37.                 yb = yc + b * sin(alpha * PI/180.);
  38.                 line (xa, ya, xb, yb, color);   /* Draw to previous pt  */
  39.                 xa = xb;
  40.                 ya = yb;
  41.                 }
  42.                                         /* Do the last segment          */
  43.         xb = xc + a * cos(a1 * PI/180.);
  44.         yb = yc + b * sin(a1 * PI/180.);
  45.         line (xa, ya, xb, yb, color);
  46.         }
  47.