// Calculation Program for displaying a single heart curve coversed from a Cardioid_2b_5. 21 Jan., 2012

// file name: heart_curve_2b_5.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 k;// reduction coefficient on Fermi distribution function, pi < k
	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=1.;
	c=0.7;
	d=1.05;
	k=1.05*pi;// restricted condition : pi=3.1415927 < k

// 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=(1-b)*(f-pi/2)+b*pi*log((k-pi/2+f)/(k+pi/2-f))/log((k+pi)/(k-pi))+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_2b_5.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