Skip to content
Snippets Groups Projects
Commit b3d4f757 authored by arnaud.devevey's avatar arnaud.devevey
Browse files

18h

parent 7acbc444
No related branches found
No related tags found
No related merge requests found
Pipeline #6074 failed
...@@ -30,6 +30,24 @@ ...@@ -30,6 +30,24 @@
* * * *
* * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * */
int main(int argc, char **argv) { int main(int argc, char **argv) {
if (argc == 3) {
// convertit argv[#] en int
int nb_stars = atoi(argv[1]);
double theta = atoi(argv[2]);
printf("\n\n");
tests();
Box box_initial = new_box(0.0, 0.0, 10.0, 10.0);
// Galaxy* galaxy = create_and_init_galaxy(nb_stars, box_initial, DELTA_T);
/* /*
gestion_de_la_ligne_de_commande(); gestion_de_la_ligne_de_commande();
allocation_mémoire_et_initialisation_de_la_galaxie(); allocation_mémoire_et_initialisation_de_la_galaxie();
...@@ -44,20 +62,15 @@ int main(int argc, char **argv) { ...@@ -44,20 +62,15 @@ int main(int argc, char **argv) {
destruction_galaxie(); destruction_galaxie();
*/ */
printf("\n\n");
tests_vector(); } else {
tests_box(); printf("Nombre d'arguments non valide");
tests_star(); exit(1);
// tests_quadtree(); }
}
// tests_galaxy();
// on crée une étoile en (0;0) qui a comme masse 10^6 * masse solaire
// sun = new_star_vel(new_vec(0, 0), Vector speed, Vector acc, (math.powf(10, 6) * MASSE_SOLAIRE), DELTA_T)
}
/* * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * *
...@@ -65,19 +78,26 @@ int main(int argc, char **argv) { ...@@ -65,19 +78,26 @@ int main(int argc, char **argv) {
* --- FONCTIONS --- * * --- FONCTIONS --- *
* * * *
* * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * */
/*
Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) { Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) {
Star* list_stars = malloc(sizeof(Star) * nb_bodies);
// on crée une étoile en (0;0) qui a comme masse 10^6 * masse solaire
// Star* sun = new_star_vel(new_vec(0, 0), speed, acc, 1e6 * MASSE_SOLAIRE, DELTA_T);
// list_stars[0] = sun;
for (int i = 1; i <= nb_bodies; i++) {
// Star* temp = new_star_vel();
}
} }
void reset_acc_galaxy(Galaxy* galaxy) { void reset_acc_galaxy(Galaxy* galaxy) {
printf("bla");
} }
void update_pos_galaxy(Galaxy* galaxy, double delta_t) { void update_pos_galaxy(Galaxy* galaxy, double delta_t) {
printf("bla");
} }
...@@ -87,6 +107,20 @@ void free_galaxy(Galaxy* galaxy) { ...@@ -87,6 +107,20 @@ void free_galaxy(Galaxy* galaxy) {
void resize_galaxy(Galaxy* galaxy) { void resize_galaxy(Galaxy* galaxy) {
double enlarge = 10.0;
galaxy -> box.x0 -= enlarge;
galaxy -> box.y0 += enlarge;
galaxy -> box.x1 += enlarge;
galaxy -> box.y1 -= enlarge;
}
void tests() {
tests_vector();
tests_box();
tests_star();
// tests_quadtree();
// tests_galaxy();
} }
\ No newline at end of file
*/
\ No newline at end of file
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include "star.h" #include "star.h"
#define FORCE_GRAVITATION (6.67 * math.pow(10, -11))
#define NB_PLANETS 10 #define DELTA_T 1e10 // discrétisation temporelle
/* * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * *
* * * *
...@@ -43,8 +43,6 @@ typedef struct __node { ...@@ -43,8 +43,6 @@ typedef struct __node {
* * * *
* * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * */
/* --- GALAXIE --- */
// alloue et initialise une galaxie // alloue et initialise une galaxie
Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t); Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t);
...@@ -62,49 +60,14 @@ void resize_galaxy(Galaxy* galaxy); ...@@ -62,49 +60,14 @@ void resize_galaxy(Galaxy* galaxy);
// fait les tests de toutes les librairies
void tests();
// calcule la force résultante d'une liste de vecteurs
Vector resultante(Vector** list_vectors);
// calcule la position de la étoile après avoir subi la force résultante des autres vecteurs (deuxième loi de Newton)
void new_position(Star* star, Vector resultante);
// calcule l'accélération
double acceleration(Star* star, Vector resultante);
// discrétise le temps
// UTILITAIRES
// une seule étoile ne devra pas avoir de masse et de position aléatoire : elle sera en (0,0) et aura math.pow(10, 6) * MASSE_SOLAIRE comme masse
// donne une masse aléatoire à une étoile
int random_mass(Star* star);
// MASSE_MIN + (R(10) * MASSE_SOLAIRE)
// donne une position aléatoire à une étoile
Vector random_position(Star* star);
// R * (math.log(1 - random_1()) / 1.8) * chaque composante du vecteur v(0.5 - random_1() ; 0.5 - random_1())
// où R = math.pow(10, 18) [m] et R(0) est R(0) un nombre aléatoire entre 0 et 1
// donne une vitesse aléatoire à une étoile
Vector random_speed(Star* star);
// math.sqrt(FORCE_GRAVITATION * (star -> mass + )) * chaque composante du vecteur v(-sin(phi) ; cos(phi))
// où phi = atan2(star -> position.y / star -> position.x) // tan⁻¹
// calcule une super etoile d'après le poids et la position d'un groupe d'étoiles
Star super_star(Star** list_stars);
void insert_star(Node *n, Star *s); void insert_star(Node *n, Star *s);
...@@ -135,10 +98,7 @@ void insert_star(Node *n, Star *s); ...@@ -135,10 +98,7 @@ void insert_star(Node *n, Star *s);
} }
*/ */
int random_10();
// (rand() % 10) + 1
double random_1();
#endif #endif
\ No newline at end of file
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
#include "star.h" #include "star.h"
#define MASSE_MIN 1e20
#define MASSE_SOLAIRE 1.98892e30
#define DELTA_T 1e10 // discrétisation temporelle
/* * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * *
* * * *
...@@ -17,21 +14,36 @@ Star* new_star_vel(Vector new_pos, Vector new_speed, Vector new_acc, double new_ ...@@ -17,21 +14,36 @@ Star* new_star_vel(Vector new_pos, Vector new_speed, Vector new_acc, double new_
Star* new_star = malloc(sizeof(Star)); Star* new_star = malloc(sizeof(Star));
new_star -> pos = new_pos; new_star -> pos = new_pos;
new_star -> acc = new_acc;
new_star -> mass = new_mass;
// copie mais en pointeur de speed
Vector* p_speed = new_vec(new_speed.x , new_speed.y);
// est-ce que c'est égal à &new_speed ?
// on multiplie le vecteur speed par delta_t (qui retourne un pointeur sur vecteur, que l'on déréférence) // on multiplie le vecteur speed par delta_t (qui retourne un pointeur sur vecteur, que l'on déréférence)
Vector *pos_tmp = mul_vec(&new_speed, new_dt); Vector* pos_tmp = mul_vec(p_speed, new_dt);
new_star -> previous_pos = *pos_tmp; new_star -> previous_pos = *pos_tmp;
free(pos_tmp); free(pos_tmp);
free(p_speed);
// copie mais en pointeur de previous_pos
Vector* p_pre_pos = new_vec(new_star -> previous_pos.x, new_star -> previous_pos.y);
// copie mais en pointeur de pos
Vector* p_pos = new_vec(new_star -> pos.x, new_star -> pos.y);
// et on soustrait ce résultat au vecteur position (qui retourne un pointeur sur vecteur, que l'on déréférence) // et on soustrait ce résultat au vecteur position (qui retourne un pointeur sur vecteur, que l'on déréférence)
pos_tmp = sub_vec(&(new_star -> previous_pos), &new_pos); pos_tmp = sub_vec(p_pre_pos, p_pos);
new_star -> previous_pos = *pos_tmp; new_star -> previous_pos = *pos_tmp;
free(pos_tmp); free(pos_tmp);
free(p_pre_pos);
free(p_pos);
pos_tmp = NULL; pos_tmp = NULL;
new_star -> acc = new_acc;
new_star -> mass = new_mass;
return new_star; return new_star;
} }
...@@ -66,31 +78,82 @@ void print_star(const Star* const star) { ...@@ -66,31 +78,82 @@ void print_star(const Star* const star) {
masse = %f \n", star -> pos.x, star -> pos.y, star -> previous_pos.x, star -> previous_pos.y, star -> acc.x, star -> acc.y, star -> mass); masse = %f \n", star -> pos.x, star -> pos.y, star -> previous_pos.x, star -> previous_pos.y, star -> acc.x, star -> acc.y, star -> mass);
} }
/*
int random_mass() {
return MASSE_MIN + (random_10() * MASSE_SOLAIRE);
}
Vector random_position() {
// R * (math.log(1 - random_1()) / 1.8) * chaque composante du vecteur v(0.5 - random_1() ; 0.5 - random_1())
// où R = math.pow(10, 18) [m] et R(0) est R(0) un nombre aléatoire entre 0 et 1
Vector position;
double temp = 1e18 * (log(1 - random_1()) / 1.8);
position.x = temp * (0.5 - random_1());
temp = 1e18 * (log(1 - random_1()) / 1.8);
position.y = temp * (0.5 - random_1());
return position;
}
Vector random_speed(Star* star) {
// math.sqrt(FORCE_GRAVITATION * (star -> mass + )) * chaque composante du vecteur v(-sin(phi) ; cos(phi))
// où phi = atan2(star -> position.y / star -> position.x) // tan⁻¹
Vector* p_norm = new_vec(star -> pos.x, star -> pos.y);
double temp = sqrt(FORCE_GRAVITATION * (star -> mass + (1e6 * MASSE_SOLAIRE)) / norm(p_norm));
double phi = atan2(star -> pos.y, star -> pos.x);
Vector speed;
speed.x = temp * (-sin(phi));
speed.y = temp * (cos(phi));
return speed;
}
// il faut deja faire une liste de stars qui se trouvent dans une box // il faut deja faire une liste de stars qui se trouvent dans une box
Star* super_star(Star* list_stars, int size_list) { Star* super_star(Star* list_stars, int size_list) {
Star* super_star = malloc(sizeof(Star)) Star* super_star = malloc(sizeof(Star));
for (int i = 0; i < size_list; i++) { for (int i = 0; i < size_list; i++) {
// position // position
super_star -> pos -> x += list_stars[i] -> pos -> x; super_star -> pos.x += list_stars[i].pos.x;
super_star -> pos -> y += list_stars[i] -> pos -> y; super_star -> pos.y += list_stars[i].pos.y;
// accélération // accélération
super_star -> acc -> x += list_stars[i] -> acc -> x; super_star -> acc.x += list_stars[i].acc.x;
super_star -> acc -> y += list_stars[i] -> acc -> y; super_star -> acc.y += list_stars[i].acc.y;
// masse // masse
super_star -> mass -> x += list_stars[i] -> pos -> masse; super_star -> mass += list_stars[i].mass;
} }
// ne donne pas la même chose si on fait /= 2 pour chaque boucle for // ne donne pas la même chose si on fait /= 2 pour chaque boucle for
super_star -> pos.x /= size_list;
super_star -> pos.y /= size_list;
super_star -> acc.x /= size_list;
super_star -> acc.y /= size_list;
super_star -> mass /= size_list; super_star -> mass /= size_list;
return super_star; return super_star;
} }
*/
int random_10() {
return ((rand() % 10) + 1);
}
double random_1() {
return ((rand() % 10) / 10);
}
...@@ -113,6 +176,8 @@ void tests_star() { ...@@ -113,6 +176,8 @@ void tests_star() {
print_star(s1); print_star(s1);
free(s1); free(s1);
free(position); free(position);
free(speed); free(speed);
......
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
#include "vector.h" #include "vector.h"
#define MASSE_MIN 1e20
#define MASSE_SOLAIRE 1.98892e30
#define DELTA_T 1e10 // discrétisation temporelle
#define FORCE_GRAVITATION (6.67 * 1e-11)
/* * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * *
* * * *
* --- STRUCTURES --- * * --- STRUCTURES --- *
...@@ -41,6 +47,38 @@ void update_pos_star(Star* star, double delta_t); ...@@ -41,6 +47,38 @@ void update_pos_star(Star* star, double delta_t);
// affiche les champs d'une étoile // affiche les champs d'une étoile
void print_star(const Star* const star); void print_star(const Star* const star);
// calcule la force résultante d'une liste de vecteurs
Vector resultante(Vector** list_vectors);
// calcule la position de la étoile après avoir subi la force résultante des autres vecteurs (deuxième loi de Newton)
void new_position(Star* star, Vector resultante);
// calcule l'accélération
double acceleration(Star* star, Vector resultante);
// retourne une masse aléatoire
int random_mass();
// retourne une position aléatoire
Vector random_position();
// retourne une vitesse aléatoire
Vector random_speed(Star* star);
// calcule une super etoile d'après le poids et la position d'un groupe d'étoiles
Star* super_star(Star* list_stars, int size_list);
int random_10();
double random_1();
void tests_star(); void tests_star();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment