Advertisement
SumitParakh

Good Example Of Math in Programming

Sep 16th, 2012
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. #include<graphics.h>
  2. #include<math.h>
  3. #include<conio.h>
  4. #define MAXPTS 15
  5. #define PI 3.14159 /* Define a value for PI */
  6.  
  7. struct PTS {    /* used to get x and y co-ordinates */
  8. int x, y;
  9. };
  10.  
  11. int main()
  12. {
  13.     struct viewporttype vp;
  14.     struct PTS points[MAXPTS];
  15.     int i, j, h, w, xcenter, ycenter,gd=DETECT,gm;
  16.     int radius, angle, step;
  17.     double rads,AspectRatio;
  18.     int xasp, yasp;     /* Used to read the aspect ratio*/
  19.     initgraph(&gd,&gm,"c:\\tc\\bgi");
  20.     getaspectratio(&xasp,&yasp);
  21.     AspectRatio = (double)xasp / (double)yasp;  /* Get correction factor */
  22.     getviewsettings( &vp );
  23.     h = vp.bottom - vp.top;
  24.     w = vp.right - vp.left;
  25.     xcenter = w / 2;    /* Determine the center of circle */
  26.     ycenter = h / 2;
  27.     radius = (h - 30) / (AspectRatio * 2);
  28.     step = 360 / MAXPTS;    /* Determine # of increments */
  29.  
  30.     angle = 0;  /* Begin at zero degrees */
  31.     for( i=0 ; i<MAXPTS ; ++i )
  32.     {                       /* Determine circle intercepts */
  33.         rads = (double)angle * PI / 180.0;      /* Convert angle to radians */
  34.         points[i].x = xcenter + (int)( cos(rads) * radius );
  35.         points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio );
  36.         angle += step;              /* Move to next increment */
  37.     }
  38.  
  39.     circle( xcenter, ycenter, radius ); /* Draw bounding circle */
  40.  
  41.     for( i=0 ; i<MAXPTS ; ++i )
  42.     {                       /* Draw the cords to the circle */
  43.         for( j=i ; j<MAXPTS ; ++j )
  44.         {               /* For each remaining intersect */
  45.             moveto(points[i].x, points[i].y);   /* Move to beginning of cord */
  46.             lineto(points[j].x, points[j].y);   /* Draw the cord */
  47.         }
  48.     }
  49. getch();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement