1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
/*Program Name: Bolt Circle Calculator
Programmer: Jason Saville
Date: February 16, 2011
This program will: Accept input from the user, specifically the diameter of the
bolt circle, number of points required, and center location, then calculate
and print the X and Y coordinates of each point. */
#include <stdio.h>
#include <math.h>
#define PI 3.14159
main ()
{
int numpoints, boltdia, refx, refy, loop;
float circrad, increment, firstangle, anglesum, locx, locy, answer, lastangle, spanangle;
printf("Enter the diameter of the bolt circle: ");
scanf("%d", &boltdia);
printf("Enter the number of points required: ");
scanf("%d", &numpoints);
printf("Enter x-coordinate of reference point: ");
scanf("%d", &refx);
printf("Enter y-coordinate of reference point: ");
scanf("%d", &refy);
printf("Enter angle to first point in degrees: ");
scanf("%f", &firstangle);
printf("Is this a full circle? (YES=1, NO=0): ");
scanf("%f", &answer);
if (answer == 0)
{printf("Enter angle to last point: ");
scanf("%f", &lastangle);
spanangle = lastangle - firstangle;
circrad = boltdia / 2;
increment = (spanangle / numpoints);
for (loop=1, anglesum=firstangle; loop<=numpoints, anglesum<=lastangle; anglesum+increment, loop++)
{increment = (360 / numpoints);
locx = (circrad * (cos(anglesum * (PI/180)))) + refx;
locy = (circrad * (sin(anglesum * (PI/180)))) + refy;
printf("At %f degrees, the hole center is at (%f, %f)/n", anglesum, locx, locy);
}
}
for (loop=1, anglesum=firstangle; loop<=numpoints, anglesum<=lastangle; anglesum+increment, loop++)
{locx = circrad * (cos(anglesum * (PI/180)));
locy = circrad * (sin(anglesum * (PI/180)));
printf("At %f degrees, the hole center is at (%f, %f)/n", anglesum, locx, locy);
};
return (0);
}
|