// Calculation Program for displaying a spiral curve on an egg surface, 19 Jan., 2011

// in the case that a=1.0, b=0.7, c=20.0



// file name: egg_spiral.c



#include< stdio.h>

#include< math.h>



void main(void)

{

	double z,a,b,c,d;

	int i,imax,j;

	double pi; // pi=Pi

	double zmax,dz;

	double xx[10001],yy[10001],zz[10001];



	FILE *fp;



// Setting of the constants

        a=1.0; // one of parameters in egg equation

	b=0.7; // one of parameters in egg equation

	c=10.0; // adjustment coefficient for number of revolution of spiral 

	d=0.95; // rate of reduction to make sure that trigonometric function "tan" is not divergent

	pi=3.1415927;

	 

// Setting of the other parameters

	zmax=a;// the maximum value of z

	dz=zmax/4000;// plotting interval of z



// execution of calculation

	i=0;

	for(z=0;z<=zmax;z=z+dz)

		{

		i++;



		xx[i]=(sqrt(((a-b-2*z)+sqrt(4*b*z+(a-b)*(a-b)))*z/2))*cos(c*tan(pi*(z-a/2)*d/a));

		yy[i]=(sqrt(((a-b-2*z)+sqrt(4*b*z+(a-b)*(a-b)))*z/2))*sin(c*tan(pi*(z-a/2)*d/a));

		zz[i]=z;



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

		}

	imax=i;

	j=0;



	// writing the calculated coordinates data of the curve into a textfile

	fp=fopen("egg_spiral.txt","w");

	if(fp==NULL)

		{

		printf("FILE OPEN ERROR\n");

		}

	else

		{

		for(i=1;i<=imax;i++)

			{

			fprintf(fp,"%f,%f,%f\n",xx[i],yy[i],zz[i]);

			}

		fflush(fp);

		fclose(fp);

		}

	printf("end\n");

}// the end of the program





RETURN