// Calculation Program for displaying a single heart curve VIII coversed from a Cardioid, Apr. 21, 2010
// file name: heart_curve_h.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,t,dt;// the moving radius of distorted Cardioid, 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
float c;// coefficient of the conversion from a Cardioid to a heart curve
float p;// newly introduced constant for modification of heart curve
double tmin,tmax;// the minimum and maximum values of the phase angle "t" respectively
int i,imax;
double x,y;// coordinates variables before one step of completion
double xx[10001],yy[10001];// Take care of the upper limit of storage memory capacitance.
FILE *fp;
// setting of the constants
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;
printf("coefficient of the conversion from a Cardioid to a heart curve (suitable at between 0 and 0.5); c = ? ");
scanf("%f",&c);
printf("\n");
printf("newly introduced constant (suitable at between 0 and 0.5); p = ? ");
scanf("%f",&p);
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*(1-sin(t))*(1+c*sin(t));
r=sqrt(R*R+(2*a*(1-c))*(2*a*(1-c))+2*(2*a*(1-c))*R*sin(t));
z=asin(R*cos(t)/r);
}
}
f=-alpha*z/pi+pi/2;
x=r*cos(f);
xx[i]=x;
y=b*r*sin(f);
if(x>=0)
{
yy[i]=y+p*sqrt(x);
}
else
{
yy[i]=y+p*sqrt(-x);
}
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_h.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