Skip to content
Snippets Groups Projects
Commit b275e90e authored by maberet's avatar maberet
Browse files

Merge branch 'main' into qlearn

parents f0095fb1 5b97eba0
No related branches found
No related tags found
No related merge requests found
File added
{
"files.associations": {
"ball.h": "c"
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
ball_t ball;
laGrange_t coefLagrange;
int trajectory[NUMBERPOINT][2];
int trajectoireAntoine[20][2];
void initBall (){
......@@ -47,7 +48,7 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){
float distance= (float)(yDropPoint-canon.y);
printf("test : %f\n", y);
//printf("test : %f\n", y);
trajectory[0][0]=canon.y;
trajectory[0][1]=canon.x;
......@@ -84,4 +85,60 @@ void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){
coefLagrange.b*((float)canon.y + i*step)+
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;
extern laGrange_t coefLagrange;
extern int trajectory[NUMBERPOINT][2];
extern int trajectoireAntoine[20][2];
void initBall();
void laGrange(float *, float *);
float defineAngle(canon_t, int, int);
//void calculationTrajectory(canon_t, int, int, 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
\ No newline at end of file
......@@ -239,22 +239,47 @@ void drawTrajectoireTopView(){
}
void drawTrajectoireSideView(){
canon_t canon_trajectoire_sideview;
/*canon_t canon_trajectoire_sideview;
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,
drawerPointDeChute.y,
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]);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderDrawLine(renderer, trajectory[i][0], trajectory[i][1], trajectory[i+1][0], trajectory[i+1][1]);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
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(){
......
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