// Calculation Program for displaying single heart curve I coversed from a Cardioid; R=a(1-sin t), x=r cos t and y=r sin t. 16 Feb., 2009
// and conversing the variable t into f as the bottom of the cardioid becomes horned. Finally, usinf x=r*cos(f) and y=r*sin(f).
// file name: heart_curve_a_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 t,dt;// the phase angle [radian] and its increment [radian] of a Cardioid before the conversion respectively
double r,z;// the moving radius and the phase angle [radian] of a Cardioid after some conversion respectively
double f;// the phase angle [radian] of a Cardioid after the final conversion into a horned one
float angle;// the desired angle [degree] for the horned Cardioid
float nb;// compression rate [percent] in the vertical direction
double alpha;// the unit conversion of the variable "angle" from "degree" to "radian"
double b;// the compression coefficient in the vertical direction
double tmin,tmax;// the minimum and maximum values of the phase angle "t" respectively
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;
// setting of the other parameters
printf("Input of the desired angle [degree] for the horned Cardioid (positive integer less than 180 degree); alpha [degree] = ? ");
scanf("%f",&angle);
printf("\n");
alpha=pi*angle/180;
printf("Input of the compression rate [percent] in the vertical direction (suitable at between 30 and 100); b [percent] = ? ");
scanf("%f",&nb);
printf("\n");
b=1.0*nb/100;
tmin=-pi/2;
tmax=3*pi/2;
dt=(tmax-tmin)/4000;// plotting interval of the phase angle "t" before conversion
// execution of calculation
i=0;
for(t=tmin;t<= tmax+dt;t=t+dt)
{
i++;
if(t>(3*pi/2-dt) && t<(3*pi/2+dt))
{
r=0.;
z=-pi/2;
}
else
{
if(t>(-pi/2-dt) && t<(-pi/2+dt))
{
r=0.;
z=pi/2;
}
else
{
r=a*sqrt((5-3*sin(t))*(1+sin(t)));
z=asin(a*(1-sin(t))*cos(t)/r);
}
}
f=-alpha*z/pi+pi/2;
xx[i]=r*cos(f);
yy[i]=b*r*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_a.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