Skip to content
Snippets Groups Projects
Commit 5b97eba0 authored by antoinemeyer5's avatar antoinemeyer5
Browse files

tracer de courber focntionne git add *

parents 7ba67162 d9e783b6
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
ball_t ball; ball_t ball;
laGrange_t coefLagrange; laGrange_t coefLagrange;
int trajectory[NUMBERPOINT][2]; int trajectory[NUMBERPOINT][2];
int trajectoireAntoine[20][2];
void initBall (){ void initBall (){
...@@ -84,4 +85,60 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){ ...@@ -84,4 +85,60 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){
coefLagrange.b*((float)canon.y + i*step)+ coefLagrange.b*((float)canon.y + i*step)+
coefLagrange.a*(powf((float)canon.y + i*step,2))); coefLagrange.a*(powf((float)canon.y + i*step,2)));
} }
} }
\ No newline at end of file
//output of Lagrange interpolation method is obtained in yp
//xp is interpolation point given by user
//xd : x depart
//yd : y depart
//xt : x target
//yt : y target
// DONNE UN POINT
int calculTrajectoireAntoine(float xp, int xd, int yd, int xf, int yf, int xt, int yt){
float x[100], y[100], yp=0, p;
int i,j,n;
n = 3;
x[1] = xd;
x[2] = xf;
x[3] = xt;
y[1] = yd;
y[2] = yf;
y[3] = yt;
/* Implementing Lagrange Interpolation */
for(i=1;i<=n;i++)
{
p=1;
for(j=1;j<=n;j++)
{
if(i!=j)
{
p = p* (xp - x[j])/(x[i] - x[j]);
}
}
yp = yp + p * y[i];
}
printf("Interpolated value at %.3f is %.3f.\n", xp, yp);
return yp;
}
// utilise calculTrajectoireAntoine pour
// calculer une liste de point a tracer
void calculTrajectoireAntoine2(int xd, int yd, int xf, int yf, int xt, int yt){
// on calcule 20 points
int pas_de_temps = (xt-xd)/19;
int i;
for (i=0; i<19; i++){
// x
trajectoireAntoine[i][0] = (int)(xd + i*pas_de_temps);
// y
trajectoireAntoine[i][1] = calculTrajectoireAntoine(trajectoireAntoine[i][0], xd, yd, xf, yf, xt, yt);
}
}
...@@ -31,10 +31,15 @@ extern ball_t ball; ...@@ -31,10 +31,15 @@ extern ball_t ball;
extern laGrange_t coefLagrange; extern laGrange_t coefLagrange;
extern int trajectory[NUMBERPOINT][2]; extern int trajectory[NUMBERPOINT][2];
extern int trajectoireAntoine[20][2];
void initBall(); void initBall();
void laGrange(float *, float *); void laGrange(float *, float *);
float defineAngle(canon_t, int, int); float defineAngle(canon_t, int, int);
//void calculationTrajectory(canon_t, int, int, int, int); //void calculationTrajectory(canon_t, int, int, int, int);
void calculationTrajectory(canon_t, int, int); void calculationTrajectory(canon_t, int, int);
int calculTrajectoireAntoine(float, int, int, int, int, int, int);
void calculTrajectoireAntoine2(int, int, int, int, int, int);
#endif #endif
\ No newline at end of file
...@@ -239,22 +239,47 @@ void drawTrajectoireTopView(){ ...@@ -239,22 +239,47 @@ void drawTrajectoireTopView(){
} }
void drawTrajectoireSideView(){ void drawTrajectoireSideView(){
canon_t canon_trajectoire_sideview; /*canon_t canon_trajectoire_sideview;
canon_trajectoire_sideview.y = drawerTerrainSideView.x + canon.y; canon_trajectoire_sideview.y = drawerTerrainSideView.x + canon.y;
canon_trajectoire_sideview.x = drawerTerrainSideView.y; canon_trajectoire_sideview.x = drawerTerrainSideView.y;*/
drawerPointDeChute.y = terrain.y + terrain.h; /*drawerPointDeChute.y = terrain.y + terrain.h;
calculationTrajectory(canon_trajectoire_sideview, calculationTrajectory(canon_trajectoire_sideview,
drawerPointDeChute.y, drawerPointDeChute.y,
drawerPointDeChute.x drawerPointDeChute.x
); );*/
for(int i=0; i<NUMBERPOINT-1; i++){
//int resultatAntoine = 0;
//resultatAntoine = calculTrajectoireAntoine(75.0, 0, 0, 50, 60, 100, 0);
/*calculTrajectoireAntoine2(0, -200, 50, 60, 100, -200);
printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[5][0], trajectoireAntoine[5][1]);
printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[6][0], trajectoireAntoine[6][1]);
printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[7][0], trajectoireAntoine[7][1]);*/
calculTrajectoireAntoine2(
terrain.x + terrain.w + 50 + canon.y, //x depart
terrain.y + terrain.h, //y depart
terrain.x + terrain.w + 50 + terrain.h/2, //x filet
terrain.y + terrain.h - 100, //y filet
drawerTerrainSideView.x + drawerTerrainSideView.w/2 + point_de_chute.y, // x target
terrain.y + terrain.h); // y target
printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[5][0], trajectoireAntoine[5][1]);
printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[6][0], trajectoireAntoine[6][1]);
printf("trajAntoinX : %d; trajAntoinY : %d\n", trajectoireAntoine[7][0], trajectoireAntoine[7][1]);
for(int i=0; i<18; i++){
//printf("point %d (%d, %d)\n", i, trajectory[i][0], trajectory[i][1]); //printf("point %d (%d, %d)\n", i, trajectory[i][0], trajectory[i][1]);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
SDL_RenderDrawLine(renderer, trajectory[i][0], trajectory[i][1], trajectory[i+1][0], trajectory[i+1][1]); SDL_RenderDrawLine(renderer, trajectoireAntoine[i][0], trajectoireAntoine[i][1], trajectoireAntoine[i+1][0], trajectoireAntoine[i+1][1]);
//SDL_RenderDrawLine(renderer, trajectory[i][0], trajectory[i][1], trajectory[i+1][0], trajectory[i+1][1]);
} }
} }
void drawBall(){ void drawBall(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment