// Program for calculation of an apple shaped surface,Jan. 19, 2011.
// file name: apple_surface.c
#include< stdio.h>
#include< math.h>
void main(void)
{
double a,pi;// a is a constant and pi is the Pi.
double b;// a compression constant towards y direction
double p, q;
// compression coefficients towards x and y directions respectively
double t,dt;
// an intermediate variable and its increment [radian] of Cardioid before the conversion
double R;// radius of Cardioid before the conversion
double fi,fimax,dfi;
// the phase angle in (z, x) plane, its maximum value and its increment [radian]
double tmin,tmax;
// the minimum and maximum values of the intermediate variable t [radian]
int i,imax;
double xx[20001],yy[20001],zz[20001];
// Take care of the upper limit of storage memory capacitance.
FILE *fp;
// setting of the constant
pi=3.14159265;
a=1.0;// 1.0
b=1.2;// 1.0
p=0.15;// 0.15
q=0.08;// 0.08
// setting of the other parameters
tmin=-pi/2;
tmax=pi/2;
dt=(tmax-tmin)/100;// plotting interval of t
fimax=2*pi;
dfi=fimax/36;// plotting interval of fi
// execution of calculation
i=0;
for(t=tmin;t<=tmax+dt;t=t+dt)
{
R=a*(1-sin(t));
for(fi=0;fi<=fimax+dfi;fi=fi+dfi)
{
i++;
zz[i]=(R*cos(t)*exp(-p*(t-pi/2)*(t-pi/2)))*cos(fi);
xx[i]=(R*cos(t)*exp(-p*(t-pi/2)*(t-pi/2)))*sin(fi);
yy[i]=b*R*sin(t)*exp(-q*(t-pi/2)*(t-pi/2));
printf("i=%d,x=%f,y=%f,z=%f\n",i,xx[i],yy[i],zz[i]);
}
}
imax=i;
// writing the calculated coordinates data of the apple shaped surface into a textfile
fp=fopen("apple_surface.txt","w");
if(fp==NULL)
{
printf("FILE OPEN ERROR\n");
}
else
{
for(i=1;i<=imax;i++)
{
fprintf(fp,"%f,%f,%f\n",xx[i],yy[i],zz[i]);
}
fflush(fp);
fclose(fp);
}
printf("end\n");
}// the end of the program
RETURN