// Calculation Program for displaying a single egg-shaped-curve, 9(Mon.) Jan., 2004
// Equation of the curve: (x*x+y*y)**2=a*(x**3)+(a-b)*x*(y**2), a=4, b=3.2 in this program. In general,  b<=a is necessary.  When b=0, the curve is a circle.
// file name: egg_shaped_curve_1E.c

#include< stdio.h>
#include< math.h>

void main(void)
{
	double x,y,a,b;
	int i,imax,j,m;
	double 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;
	b=2.8;// b=0.7*a

	printf("a=%f\n\n",a);

// Setting of the other parameters
	xmax=a;// maximum value of x
	dx=xmax/4000;// plotting interval of x

	i=0;

// execution of calculation
	for(x=0;x<=xmax;x=x+dx)
	{
		i++;

		xx[i]=x;
		y=sqrt(((a-b-2*x)+sqrt(4*b*x+(a-b)*(a-b)))*x/2);// It becomes the equation of a circle: y=sqrt(a*a/2/2-(x-a/2)*(x-a/2)) when b=0.
		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;i++)
	{
		j++;
		m=imax-j;

		xx[i]=xx[m];
		yy[i]=-yy[m];
	}

// 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