// Calculation Program for calculating shape of a flower with the use of a circle (part B), July 4th, 2012
// file name: flower_curve_B.c
#include< stdio.h>
#include< math.h>
void main(void)
{
double a,pi;// "a" is the radius of original circle of petal and pi=3.1415...
double r,z;// "r" and "z"(-π/2 =< z =< π/2)are the moving radius and the phase angle of petal respectively.
double dz;// increment of "z"
double f;// the phase angle of petal made of a sharpened original circle
double p;// phase angle of center circle
double dp;// increment of "p"
int n;// numbers of petals
double alpha;// the sharp angle of the bottom of the petal (The criterion value is "alpha=2*pi/n" in this program.)
float k;// magnification factor of the criterion angle "alpha=2*pi/n" where 0 < k.
double zmin,zmax;// the minimum and the maximum values of phase angle "z" respectively
int i,imax,j;
float c;// the radius of the center circle
double xx[30001],yy[30001];// Take care of the upper limit of storage memory capacitance.
FILE *fp;
// setting of the constants
pi=3.141592;
a=1.;
// setting of the other parameters
printf("Input the numbers of petals. \n n=? ");
scanf("%d",&n);
printf("n=%d\n",n);
alpha=2*pi/n;// the shsarpened angle of the botom of a petal
printf("Input magnification factor of the criterion angle 'alpha=2*pi/n' where 0 < k. \n k= ? ");
scanf("%f",&k);
printf("h=%f\n",k);
alpha=k*alpha;// the magnificated angle of the botom of the petal
printf("Input the radius of the center circle. \n c= ? ");
scanf("%f",&c);
printf("c=%f\n",c);
zmin=-pi/2;
zmax=pi/2;
dz=(zmax-zmin)/200;// plotting interval of z
dp=2*pi/n/20;
// execution of calculation
i=0;
for(j=1;j<=n;j++) // sweep of n numbers of petals
{
for(z=zmin;z<=zmax+dz;z=z+dz) // sweep of phase angle "z" of the each petal
{
i++;
r=2*a*cos(z);
f=-alpha*z/pi+pi/2-2*pi*(j-1)/n;
xx[i]=r*cos(f)+c*cos(-2*pi*(j-1)/n+pi/2);
yy[i]=r*sin(f)+c*sin(-2*pi*(j-1)/n+pi/2);
printf("i=%d,x=%f,y=%f\n",i,xx[i],yy[i]);
}
for(p=2*pi*(j-1)/n;p<2*pi*j/n+dp;p=p+dp)
{
i++;
xx[i]=c*cos(-p+pi/2);
yy[i]=c*sin(-p+pi/2);
printf("i=%d,x=%f,y=%f\n",i,xx[i],yy[i]);
}
}
imax=i;
xx[imax+1]=xx[1];
yy[imax+1]=yy[1];
// writing the calculated coordinates data of the curve into a textfile named "flower_curve_B.txt"
fp=fopen("flower_curve_B.txt","w");
if(fp==NULL)
{
printf("FILE OPEN ERROR\n");
}
else
{
for(i=1;i<=imax+1;i++)
{
fprintf(fp,"%f,%f\n",xx[i],yy[i]);
}
fflush(fp);
fclose(fp);
}
printf("end\n");
}// the end of the program
RETURN