// Calculation Program for displaying a single heart curve II coversed from a Cardioid; R=a(1-sin t), x=r cos t and y=r sin t. 11 Feb., 2009

// file name: heart_curve_b_E.c

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

void main(void)
{
	double a,pi;// a is the constant of the original Cardioid, pi is the pi
	double r,f,df;// the moving radius, the phase angle [radian] and its increment [radian] of a Cardioid after a conversion respectively
	double t;// the phase angle [radian] before the conversion
	double fmin,fmax;// the minimum and maximum values of the phase angle "f" respectively
	double b,c;// coefficients of the conversion from a Cardioid to a heart curve
	double d;// the ratio of expansion and contraction in the vertical direction
	int i,imax;
	double xx[10001],yy[10001];// Take care of the upper limit of storage memory capacitance.

	FILE *fp;

// setting of the constant
	pi=3.14159265;
	a=1;

	b=2.;// suitable at between 1.3 and 2.5
	c=0.3;// It must be in 0 < c <1 and about 0.5 is suitable.
	d=0.7;// suitable at between 0.5 and 1.5

// setting of the other parameters
	fmin=-pi/2;
	fmax=3*pi/2;
	df=(fmax-fmin)/4000;// plotting interval of the phase angle "f"

// execution of calculation
	i=0;
	for(f=fmin;f<= fmax;f=f+df)
		{
		i++;

		t=b*sqrt(f+pi/2)-b*sqrt(3*pi/2-f)+(1-b*sqrt(2/pi))*f+b*sqrt(pi/2);
		r=a*(1-sin(t));

		xx[i]=r*(1+c*sin(f))*cos(f);
		yy[i]=d*r*(1+c*sin(f))*sin(f);

		printf("i=%d,x=%f,y=%f\n",i,xx[i],yy[i]);
		}
	imax=i;

// writing the calculated coordinates data of the curve into a textfile
	fp=fopen("heart_curve_b.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