1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define g 9.81
#define mu 1.12
#define GM 2250.
void nouvelle_position(double *xn, double *yn, double x,double y, double vx, double vy, double dt)
{
*xn = x + vx*dt;
*yn = y + vy*dt;
}
void acceleration_pesanteur( double *ax , double *ay)
{
*ax= 0;
*ay= -g;
}
void nouvelle_vitesse( double *vxn, double *vyn, double ax, double ay, double vx,double vy, double dt)
{
*vxn = vx + ax*dt;
*vyn = vy + ay*dt;
}
int main (void)
{
double alpha;
double x,y,x0,v0,vx,vy,t,dt,ax,ay;
double x_new,y_new,vx_new,vy_new,axr,ayr;
char nom_fichier[100]="trajectoire.txt";
FILE *fichier;
/* Initialisation */
x0 = -10.;
x=x0;
t= 0.;
dt = 0.05;
v0 = 15.;
printf("angle alpha (en degres) ?\n");
scanf("%lf",&alpha);
alpha = alpha*M_PI/180.;
vx = v0 * cos(alpha);
vy = v0 * sin(alpha);
printf("ordonnée y ? ");
scanf("%lf",&y);
fichier=fopen(nom_fichier,"w");
if (fichier == NULL)
{
printf("Impossible d'ouvrir %s en mode écriture\n",nom_fichier);
exit(1);
}
fprintf(fichier," %lf %lf\n",x,y);
while ( y_new > 0)
{
nouvelle_position(&x_new,&y_new,x,y,vx,vy,dt);
x = x_new;
y = y_new;
printf ("%lf",y);
acceleration_pesanteur(&ax , &ay);
axr=ax;
ayr=ay;
nouvelle_vitesse(&vx_new ,&vy_new,vx,vy,axr,ayr,dt);
fprintf (fichier," %lf %lf\n ",x,y);
t = t + dt ;
}
printf("temps final = %lf s\n",t);
return 0;
} |