// Calculation Program for displaying an egg surface (Itou's), 21(Fri.) Jan, 2011

// in the case that a=1.0, b=0.78



// file name: egg_surface_Itou.c



#include< stdio.h>

#include< math.h>



void main(void)

{

	double x,y,z,a,b,pi;

	double t,dt;

	double fi,dfi;

	int i,imax;

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



	FILE *fp;



// Setting of the constants

	pi=3.1415927;

    a=1.0; // recommended value: a=1.0

	b=0.78;	// recommended value: b=0.78



	printf("a=%f\n\n",a);

	 

// Setting of the other parameters

	dt=pi/200;// plotting interval of x



// execution of calculation

	i=0;

	for(t=0;t<=pi;t=t+dt)

	{

		dfi=2*pi/(1+179*sin(t)); // plotting interval of fi



		for(fi=0;fi<=2*pi;fi=fi+dfi)

		{

			i++;



			x=a*cos(t);

			y=b*cos(t/4)*sin(t)*cos(fi);

			z=b*cos(t/4)*sin(t)*sin(fi);



			xx[i]=x;

			yy[i]=y;

			zz[i]=z;



			printf("i=%d,x=%f,y=%f,z=%f\n",i,x,y,z);

		}

	}

	imax=i;



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

	fp=fopen("egg_surface.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