//  Calculation Program for displaying a single egg curve. (egg shaped curve VI), 11 (Wed.) Nov., 2009



// file name: egg6.c



#include< stdio.h>

#include< math.h>



void main(void)

{

	double x,y,z,a,b,c,d,k1,k2,k3;

	int i,imax,j,m;

	double xmin,xmax,dx;

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



	FILE *fp;



// Setting of the constants

	a=4.02;// a=4.02

	b=1;// b=1

	c=1.6;// c=1.535

	d=0.7;// d=0.7

	k1=0.0000001;// k1=0.0000001

	k2=1;// k2=1

	k3=0.957;// 0.957



// Setting of the other parameters

	// xmin and xmax are the x cordinates points which the closed curve cross the x-axis (xmin < xmax).

	dx=0.0001;

	for(x=0;;x=x-dx)

	{

		xmin=x;

		z=log(k1*exp(a*a)+k3*exp(d*x)-k2*exp(b*b*x*x));

		if(z<0)

		{

			xmin=xmin+dx;

			break;

		}

	}



	for(x=0;;x=x+dx)

	{

		xmax=x;

		z=log(k1*exp(a*a)+k3*exp(d*x)-k2*exp(b*b*x*x));

		if(z<0)

		{

			xmax=xmax-dx;

			break;

		}

	}



	dx=(xmax-xmin)/2000;// plotting interval of x



// execution of calculation

	i=0;

	for(x=xmin;x<=xmax;x=x+dx)

	{

		i++;



		xx[i]=x;



		y=sqrt(log(k1*exp(a*a)+k3*exp(d*x)-k2*exp(b*b*x*x)))/c;

		yy[i]=y;

		printf("i=%d,x=%f,y=%f\n",i,x,y);

	}

	imax=i;

	j=0;



	for(i=imax+1;i<=2*imax-1;i++)

	{

		j++;

		m=imax-j;



		xx[i]=xx[m];

		x=xx[i];

		yy[i]=-yy[m];

	}

	xx[2*imax]=xx[1];

	yy[2*imax]=yy[1];



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

	fp=fopen("egg-shaped curve.txt","w");

	if(fp==NULL)

	{

		printf("FILE OPEN ERROR\n");

	}

	else

	{

		for(i=1;i<=2*imax;i++)

		{

			fprintf(fp,"%f,%f\n",xx[i],yy[i]);

		}

		fflush(fp);

		fclose(fp);

	}

	printf("end\n");

}// the end of the program





RETURN