// Calculation Program for displaying five species of heart curves, 25(Tues.) Dec., 2007

// Equation of the curve: x*x+(y-bx)**2=1 at x>0, x*x+(y+bx)**2=1 at x<0, where b>0.

// file name: heart_curve_a2_E.c



#include< stdio.h>

#include< math.h>



void main(void)

{

	double x,y,b,db,bmax;

	int i,imax,n,nmax,j;

	double xmax,dx;

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



	FILE *fp;



// setting of the constant

	xmax=1;// the maximum value of x

	dx=xmax/200;// plotting interval of x

	bmax=1;

	db=bmax/5;



	i=0;



// execution of calculation

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

	{

		i++;

		n=0;



		xx[i]=x;



		for(b=0;b<=bmax;b=b+db)

		{

			n++;



			y=sqrt(1-x*x)+b*x;

			yy[n][i]=y;



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

		}

	}



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

	{

		i++;

		n=0;



		xx[i]=x;



		for(b=0;b<=bmax;b=b+db)

		{

			n++;



			y=-sqrt(1-x*x)+b*x;

			yy[n][i]=y;



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

		}

	}



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

	{

		i++;

		n=0;



		xx[i]=x;



		for(b=0;b<=bmax;b=b+db)

		{

			n++;



			y=-sqrt(1-x*x)-b*x;

			yy[n][i]=y;



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

		}

	}



	for(x=-xmax;x<=0;x=x+dx)

	{

		i++;

		n=0;



		xx[i]=x;



		for(b=0;b<=bmax;b=b+db)

		{

			n++;



			y=sqrt(1-x*x)-b*x;

			yy[n][i]=y;



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

		}

	}



	imax=i;

	nmax=n;

	j=0;



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

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



	if(fp==NULL)

	{

		printf("FILE OPEN ERROR\n");

	}

	else

	{

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

		{

			fprintf(fp,"%f,%f,%f,%f,%f,%f,%f\n",xx[i],yy[1][i],yy[2][i],yy[3][i],yy[4][i],yy[5][i],yy[6][i]);

		}



		fflush(fp);

		fclose(fp);

	}



	printf("end\n");

}// the end of the program





RETURN