// Calculation Program for displaying a single heart curve coversed from a Cardioid_2b_2; R=a(1-sin t), x=r cos t and y=r sin t. 26 Dec., 2011
// file name: heart_curve_2b_2.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 from one piriod interval (2*pi) into reduced piriod one of the variable in sinusoidal function
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.35;// suitable at between 1.3 and 2.0
c=0.7;// It must be in 0 < c <1 and is suitable at between 0.5 and 0.8.
d=1.05;// suitable at between 0.7 and 1.5
k=0.97;// 0 < k <= 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=(1-b)*(f-pi/2)+2*b*asin((f-pi/2)*sin(pi*k/2)/pi)/k+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_2.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