// Calculation Program for displaying single heart curve, 25(Tues.) Dec., 2007

// file name: heart_curve_b1_E.c



#include< stdio.h>

#include< math.h>



void main(void)

{

	double x,y,b;

	int i,imax,j;

	double xmax,dx;

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



	FILE *fp;



// setting of the constant

	b=0.8;



	xmax=1;// the maximum value of x

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



	i=0;



// execution of calculation

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

	{

		i++;



		xx[i]=x;

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

		yy[i]=y;



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

	}



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

	{

		i++;



		xx[i]=x;

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

		yy[i]=y;



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

		}



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

	{

		i++;



		xx[i]=x;

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

		yy[i]=y;



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

	}



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

	{

		i++;



		xx[i]=x;

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

		yy[i]=y;



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

	}



	imax=i;

	j=0;



// writing the calculated coordinates data of the curve 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\n",xx[i],yy[i]);

		}



		fflush(fp);

		fclose(fp);

	}



	printf("end\n");

}// the end of the program





RETURN