home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch4_3 / arcdivid.c
C/C++ Source or Header  |  1995-04-04  |  934b  |  36 lines

  1. /* arcdivide.c - recursive circular arc subdivision (FP version) */
  2.  
  3. #define DMAX 0.5   /* max chordal deviation = 1/2 pixel */
  4.  
  5. #include <math.h>
  6. #include "../ch7-7/GG4D/GGems.h"
  7.  
  8. /* Function prototype for externally defined functions */
  9. void DrawLine(Point2 p0, Point2 p1);
  10.  
  11. void
  12. DrawArc(Point2 p0, Point2 p1, double d)
  13. {
  14.     if (fabs(d) <= DMAX) DrawLine(p0, p1);
  15.     else {
  16.         Vector2 v;
  17.         Point2  pm, pb;
  18.         double  dSub;
  19.         
  20.         v.x = p1.x - p0.x;       /* vector from p0 to p1 */
  21.         v.y = p1.y - p0.y;
  22.         
  23.         pm.x = p0.x + 0.5 * v.x; /* midpoint */
  24.         pm.y = p0.y + 0.5 * v.y;
  25.         
  26.         dSub = d / 4;
  27.         V2Scale(&v, dSub);       /* subdivided vector */
  28.         
  29.         pb.x = pm.x - v.y;       /* bisection point */
  30.         pb.y = pm.y + v.x;
  31.         
  32.         DrawArc(p0, pb, dSub);   /* first half arc */
  33.         DrawArc(pb, p1, dSub);   /* second half arc */
  34.     }
  35. }
  36.