// [このプログラムの目的]1個の卵型曲線を描くこと,2009年10月07日(水)

// a=1, b=0.69, c=0.8 の場合

// file name: egg_shaped_curve_SUUDUKU_4.c

#include< stdio.h>
#include< math.h>

void main(void)
{
	double x,y,a,b,c;
	int i,imax,j,m;
	double xmax,dx;
	double xx[10001],yy[10001];// メモリ不足に注意

	FILE *fp;

//  定数設定
        a=1;
	b=0.69;
        c=0.8;

	printf("a=%f\n\n",a);
	 
//  他のパラメータ設定
	xmax=2*a;// x の最大値
	dx=xmax/2000;// x のプロット間隔

//  計算実行
	i=0;
	for(x=0;x<=xmax+dx/10;x=x+dx)
		{
		i++;

		xx[i]=x;

		if(x>xmax)
		{
			y=0;
		}
		else
		{
			if(x>c)
			{
				y=b*sqrt(1-((x-c)/(c+2*(a-c)))*((x-c)/(c+2*(a-c))));
			}
			else
			{
				if(x< c)
				{
					y=b*sqrt(1-((x-c)/c)*((x-c)/c));
				}
				else
				{
					y=b*sqrt(1-((x-c)/(c+2*(a-c)/2))*((x-c)/(c+2*(a-c)/2)));
				}
			}
		}

		yy[i]=y;

		printf("i=%d,x=%f,y=%f\n",i,x,y);
		}
	imax=i;
	j=0;

// 計算データのテキストファイルへの書き込み
	for(i=imax+1;i<=2*imax;i++)
		{
		j++;
		m=imax-j;

		xx[i]=xx[m];
		yy[i]=-yy[m];
		}

	fp=fopen("egg-shaped curve.txt","w");
	if(fp==NULL)
		{
		printf("FILE OPEN ERROR\n");
		}
	else
		{
		for(i=1;i<=2*imax;i++)
			{
			fprintf(fp,"%f,%f\n",xx[i],yy[i]);
			}
		fflush(fp);
		fclose(fp);
		}
	printf("end\n");
}// the end of the program



~ブラウザの「戻る」で 前に開いたページに戻ります~

~または、下のボタンを押して 本サイトの前ページに戻ります~


戻る

updated: 2009.10.07, edited by N. Yamamoto