Skip to content
Snippets Groups Projects
Commit 80a23832 authored by antoinemeyer5's avatar antoinemeyer5
Browse files

tentatives reparations courbes

parent 74e0488f
Branches
No related tags found
No related merge requests found
#include "ball.h"
ball_t ball;
ball_t ball;
laGrange_t coefLagrange;
int trajectory[NUMBERPOINT][2];
void initBall(){
void initBall (){
}
void laGrange (float beta[3],float Z[3]){ // y , x
printf("x canon : %f, x chute : %f, x filet : %f\n", Z[0], Z[1], Z[2]);
printf("y canon : %f, y chute : %f, y filet : %f\n", beta[0], beta[1], beta[2]);
beta[0] =-beta[0];
beta[1] =-beta[1];
beta[2] =-beta[2];
coefLagrange.a= Z[0]/((beta[0]-beta[1])*(beta[0]-beta[2]))
+Z[1]/((beta[1]-beta[0])*(beta[1]-beta[2]))
+Z[2]/((beta[2]-beta[0])*(beta[2]-beta[1]));
coefLagrange.b= -(Z[0]*(beta[1]+beta[2]))/((beta[0]-beta[1])*(beta[0]-beta[2]))
-(Z[1]*(beta[0]+beta[2]))/((beta[1]-beta[0])*(beta[1]-beta[2]))
-(Z[2]*(beta[0]+beta[1]))/((beta[2]-beta[0])*(beta[2]-beta[1]));
coefLagrange.c= (Z[0]*beta[1]*beta[2])/((beta[0]-beta[1])*(beta[0]-beta[2]))
+(Z[1]*beta[0]*beta[2])/((beta[1]-beta[0])*(beta[1]-beta[2]))
+(Z[2]*beta[0]*beta[1])/((beta[2]-beta[0])*(beta[2]-beta[1]));
}
float defineAngle (canon_t canon, int xDropPoint, int yDropPoint){
float distance;
float angleSin;
distance= sqrtf( powf((float)(xDropPoint-canon.x),2)+powf((float)(yDropPoint-canon.y),2));
angleSin = asinf(distance/(xDropPoint-canon.x));
return angleSin;
}
void calculationTrajectory(canon_t canon, int xDropPoint, int yDropPoint){
int i;
float setUp[2][3];
float distance= (float)(yDropPoint-canon.y);
trajectory[0][0]=canon.y;
trajectory[0][1]=canon.x;
trajectory[NUMBERPOINT-1][0]=yDropPoint;
trajectory[NUMBERPOINT-1][1]=xDropPoint;
setUp[1][0]=(float)canon.y;
setUp[0][0]=canon.x;
setUp[1][1]=(float)yDropPoint;
setUp[0][1]=xDropPoint;
//setUp[0][2]=(13.40/2);// distance du filet dans le repère de frappe
//filet X
//terrain.w = 5.20 * zoom;
// setUp[0][2] = terrain.x + terrain.w + 50 + (13.40 * zoom)/2 -2;
setUp[0][2] = 50 + 5.20 * 40 + 50 + (13.40 * 40)/2 - 2;
//setUp[0][2] = 0;
//filet Y
// drawerTerrainSideView.y - 1,55 * zoom
// drawerTerrainSideView.y = terrain.y + terrain.h;
//terrain.h = 13.40 * zoom
//setUp[1][2] = 1.55*40; /// hauteur du filet
setUp[1][2] = 50 + 13.40 * 40 - 3.55 * 40;
//setUp[1][2] = 0;
laGrange(setUp[1],setUp[0]); //laGrange(y, x);
printf("coef a:%f; coef b:%f; coef c:%f\n", coefLagrange.a, coefLagrange.b, coefLagrange.c);
float step= distance / (NUMBERPOINT-1);
for (i=1; i<NUMBERPOINT-1; i++){
trajectory[i][0]=(int)((float)canon.y + i*step);
trajectory[i][1]=(int)(coefLagrange.c+
coefLagrange.b*((float)canon.y + i*step)+
coefLagrange.a*(powf((float)canon.y + i*step,2)));
}
}
\ No newline at end of file
#ifndef BALL_H
#define BALL_H
typedef struct ball{
int x;
int y;
} ball_t;
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <math.h>
#include "canon.h"
#define NUMBERPOINT 300
typedef enum {
false,true
}booleen_t;
typedef struct ball {
int x;
int y;
int z;
float angle;
float speed;
}ball_t;
typedef struct laGrange{
float a;
float b;
float c;
}laGrange_t;
extern ball_t ball;
extern laGrange_t coefLagrange;
extern int trajectory[NUMBERPOINT][2];
void initBall();
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);
#endif
\ No newline at end of file
#endif
\ No newline at end of file
......@@ -238,6 +238,25 @@ void drawTrajectoireTopView(){
SDL_RenderDrawLine(renderer, terrain.x+canon.x, terrain.y+canon.y, drawerPointDeChute.x, drawerPointDeChute.y);
}
void drawTrajectoireSideView(){
canon_t canon_trajectoire_sideview;
canon_trajectoire_sideview.y = drawerTerrainSideView.x + canon.y;
canon_trajectoire_sideview.x = drawerTerrainSideView.y;
drawerPointDeChute.y = terrain.y + terrain.h;
calculationTrajectory(canon_trajectoire_sideview,
drawerPointDeChute.y,
drawerPointDeChute.x
);
for(int i=0; i<NUMBERPOINT-1; 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]);
}
}
void drawBall(){
/*int i;
SDL_Rect rect_life;
......@@ -293,6 +312,7 @@ void mainLoop(){
drawTerrainSideView();
drawCanonSideView();
drawPointDeChuteSideView();
drawTrajectoireSideView();
//
drawInformations();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment