// Calculation Program for displaying a single heart curve III coversed from a Cardioid, 06 Apr., 2010

// file name: heart_curve_c.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
	double p;// newly introduced constant in addition to the previous method II
	int i,imax;
	double x,y;// coordinates variables obtained likely as in the previous method II
	double xx[10001],yy[10001];// coordinates variables after conversion.  // Take care of the upper limit of storage memory capacitance.

	FILE *fp;

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

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

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

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

		if(x>=0)
		{
			yy[i]=y+p*x;
		}
		else
		{
			yy[i]=y-p*x;
		}

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

	imax=i;

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