// Calculation Program for calculation of
// an apple shaped curve,Mar. 29, 2010.

// file name: apple.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 constant

	double p, q;// constants

	double t,dt;
// an intermediate variable and its increment

	double R;// an intermediate variable

	double tmin,tmax;
// the minimum and maximum values 
// of the intermediate variable t

	int i,imax;

	double xx[10001],yy[10001];
// Take care of the upper limit 
// of storage memory capacitance.

	FILE *fp;

// setting of the constant

	pi=3.14159265;
	a=1.0;
	b=1.2;
	p=0.15;
	q=0.08;

// setting of the other parameters

	tmin=-pi/2;
	tmax=3*pi/2;
	dt=(tmax-tmin)/4000;
// plotting interval of t

// execution of calculation
	i=0;
	for(t=tmin;t<=tmax+dt;t=t+dt)
		{
		i++;
		R=a*(1-sin(t));
xx[i]=R*cos(t)*exp(-p*(t-pi/2)*(t-pi/2));
yy[i]=b*R*sin(t)*exp(-q*(t-pi/2)*(t-pi/2));

printf("i=%d,x=%f,y=%f\n",i,xx[i],yy[i]);
		}
	imax=i;

// writing the calculated coordinates data of
// the apple shaped curve into a textfile

	fp=fopen("apple.txt","w");

	if(fp==NULL)
		{
		printf("FILE OPEN ERROR\n");
		}
	else
		{
		for(i=1;i<=imax;i++)
			{
fprintf(fp,"%f,%f\n",xx[i],yy[i]);
			}
		fflush(fp);
		fclose(fp);
		}
	printf("end\n");

}// the end of the program



RETURN