// Calculation Program for displaying five extended-egg-curves, 2008/8/13

// Equation of the curve: x*x*x*x+2*d*x*x*y*y+f*y*y*y*y=a*x*x*x+c*x*y*y+e*y*y

// Costant "c" is a variable parameter

// file name: extended_egg_curve_2a.c

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

void main(void)
{
	double x,y,a,c,d,e,f,dc,cmin,cmax;
	int i,imax,n,nmax,j,m;
	double xmax,dx;
	double xx[2005],yy[10][1005];// Take care of the upper limit of storage memory capacitance.

	FILE *fp;

// Setting of the constants
	a=4;
	d=0.25;
	f=0.5;
	e=0;

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

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

	cmin=-2;
	cmax=2;
	dc=(cmax-cmin)/4;

	i=0;

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

		for(c=cmin;c<=cmax;c=c+dc)
			{
			n++;

			y=sqrt(((c*x+e-2*d*x*x)+sqrt(4*(d*d-f)*x*x*x*x+4*(a*f-c*d)*x*x*x+(c*c-4*d*e)*x*x+2*c*e*x+e*e))/(2*f));// It contains the equation y=sqrt(a*a/2/2-(x-a/2)*(x-a/2)) which is the equation of the circle in the case of d=f=1 and c=a.
			yy[n][i]=y;

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

	imax=i;
	nmax=n;
	j=0;

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

		xx[i]=xx[m];

		for(n=1;n<=nmax;++n)
			{
			yy[n][i]=-yy[n][m];
			}
		}

// writing the calculated coordinates data of the curve into a textfile
	fp=fopen("extended_egg_curve.txt","w");
	if(fp==NULL)
		{
		printf("FILE OPEN ERROR\n");
		}
	else
		{
		for(i=1;i<=2*imax;i++)
			{
			fprintf(fp,"%f,%f,%f,%f,%f,%f\n",xx[i],yy[1][i],yy[2][i],yy[3][i],yy[4][i],yy[5][i]);
			}
		fflush(fp);
		fclose(fp);
		}
	printf("end\n");
}// the end of the program



RETURN