/*----------------------------------------*/ /* オイラー法で斜方投射を解く    */ /*----------------------------------------*/ #include #include #include #define g 9.8 /* 重力加速度 */ #define pi 3.141592 /* π */ main(void) { int i,num; double x,y,vx,vy,dt,t; double v0,theta; /* 初速と角度 */ FILE *output_file; output_file=fopen("output.dat","w"); /* 出力ファイルオープン*/ /* ---------------- 初期条件 ----------------- */ x=0.; y=1.7; t=0.; theta = 60./180.*pi; v0 = 100.* 1e3 / 3600. /* 100km/h */; vx = v0 * cos(theta); vy = v0 * sin(theta); dt=1e-3; /* 時間ステップ */ /* -------------- 初期条件終わり ------------- */ /* -------- 時間積分 --------- */ while(y > 0.){ x=x+vx*dt; y=y+vy*dt; vy=vy-g*dt; /* vy は自由落下、vxは一定 */ t=t+dt; /* -------- 出力ルーチン -----------*/ fprintf(output_file,"%f %f %f %f %f \n",(float)t,(float)x,(float)y,(float)vx,(float)vy); } }