Skip to content
Snippets Groups Projects
Commit dc0f2b69 authored by gawen.ackerman's avatar gawen.ackerman :robot:
Browse files

modification fonction de création de CelestialObject pour calculer la...

modification fonction de création de CelestialObject pour calculer la périhélie directement à la création
parent 647574ca
No related branches found
No related tags found
No related merge requests found
......@@ -5,12 +5,14 @@
#define G 6.67e-11
#define SUN_MASS 1.989e30
CelestialObject *celestial_object_create(double mass, Vector2 position) {
CelestialObject *celestial_object_create(double mass, double semi_major_half, double orbital_eccentricity) {
CelestialObject *object = (CelestialObject*)malloc(sizeof(CelestialObject));
object->mass = mass;
object->previous_position = vector2_create_zero();
object->current_position = position;
double perihelion = semi_major_half * (1 - orbital_eccentricity);
object->current_position = vector2_create(-perihelion, 0);
return object;
}
......@@ -11,6 +11,6 @@ typedef struct CelestialObject {
Vector2 current_position;
} CelestialObject;
CelestialObject *celestial_object_create(double mass, Vector2 position);
CelestialObject *celestial_object_create(double mass, double semi_major_half, double orbital_eccentricity);
#endif
......@@ -8,22 +8,50 @@
#define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 1000
const int SUN_INDEX = 0;
const int MERCURE_INDEX = 1;
const int VENUS_INDEX = 2;
const int EARTH_INDEX = 3;
const int MARS_INDEX = 4;
const double G = 6.67430 * 1E-11;
// Eccentricties found at : https://fr.wikipedia.org/wiki/Excentricit%C3%A9_orbitale
const double MERCURE_ECCENTRICITY = 0.20563069;
const double VENUS_ECCENTRICITY = 0.00677323;
const double EARTH_ECCENTRICITY = 0.01671022;
const double MARS_ECCENTRICITY = 0.09341233;
// CelestialObjects Masses found at : https://promenade.imcce.fr/fr/pages5/557.html
const double SUN_MASS = 1.9889 * 1E30;
const double MERCURE_MASS = 0.33018 * 1E24;
const double VENUS_MASS = 4.8685 * 1E24;
const double EARTH_MASS = 5.9736 * 1E24;
const double MARS_MASS = 0.64185 * 1E24;
// CelestialObjects Semi-major axis found at : https://www.le-systeme-solaire.net/demi-grand-axe.html
const double MERCURE_SEMI_MAJOR_AXIS = 579.1 * 1E8;
const double VENUS_SEMI_MAJOR_AXIS = 108.2 * 1E9;
const double EARTH_SEMI_MAJOR_AXIS = 149.6 * 1E9;
const double MARS_SEMI_MAJOR_AXIS = 227.9 * 1E9;
SolarSystem *solar_system_create(double interval) {
SolarSystem *solar_system = (SolarSystem *)malloc(sizeof(SolarSystem));
solar_system->objects_length = 3;
solar_system->objects_length = 5;
solar_system->objects = (CelestialObject **)malloc(sizeof(SolarSystem *) * solar_system->objects_length);
solar_system->interval = interval;
solar_system->objects[0] = celestial_object_create(1.989 * 1E30, vector2_create(0, 0));
solar_system->objects[SUN_INDEX] = celestial_object_create(SUN_MASS, 0, 0);
solar_system->objects[MERCURE_INDEX] = celestial_object_create(MERCURE_MASS, MERCURE_SEMI_MAJOR_AXIS, MERCURE_ECCENTRICITY);
solar_system->objects[VENUS_INDEX] = celestial_object_create(VENUS_MASS, VENUS_SEMI_MAJOR_AXIS, VENUS_ECCENTRICITY);
double perihelion_1 = 149.6 * 1E9 * (1 - 0.01671123);
solar_system->objects[1] = celestial_object_create(5.972 * 1E24, vector2_create(-perihelion_1, 0));
solar_system->objects[EARTH_INDEX] = celestial_object_create(EARTH_MASS, EARTH_SEMI_MAJOR_AXIS, EARTH_ECCENTRICITY);
double perihelion_2 = 227.9 * 1E9 * (1 - 0.09341233);
solar_system->objects[2] = celestial_object_create(6.39 * 1E23, vector2_create(-perihelion_2, 0));
solar_system->objects[MARS_INDEX] = celestial_object_create(MARS_MASS, MARS_SEMI_MAJOR_AXIS, MARS_ECCENTRICITY);
return solar_system;
}
......@@ -53,13 +81,18 @@ void solar_system_update(SolarSystem *solar_system) {
if (vector2_is_zero(solar_system->objects[i]->previous_position)) {
// https://i.ytimg.com/vi/hbEbD1Z_tNQ/maxresdefault.jpg
CelestialObject *star = solar_system->objects[0];
CelestialObject *star = solar_system->objects[SUN_INDEX];
double perihelion_speed = 0;
if (i == 1) {
perihelion_speed = sqrt((G * star->mass * (1 + 0.01671123)) / (149.6 * 1E9 * (1 - 0.01671123)));
} else if (i == 2) {
perihelion_speed = sqrt((G * star->mass * (1 + 0.09341233)) / (227.9 * 1E9 * (1 - 0.09341233)));
if (i == MERCURE_INDEX) {
perihelion_speed = sqrt((G * star->mass * (1 + MERCURE_ECCENTRICITY)) / (MERCURE_SEMI_MAJOR_AXIS * (1 - MERCURE_ECCENTRICITY)));
} else if (i == VENUS_INDEX) {
perihelion_speed = sqrt((G * star->mass * (1 + VENUS_ECCENTRICITY)) / (VENUS_SEMI_MAJOR_AXIS * (1 - VENUS_ECCENTRICITY)));
} else if (i == EARTH_INDEX) {
perihelion_speed = sqrt((G * star->mass * (1 + EARTH_ECCENTRICITY)) / (EARTH_SEMI_MAJOR_AXIS * (1 - EARTH_ECCENTRICITY)));
} else if (i == MARS_INDEX) {
perihelion_speed = sqrt((G * star->mass * (1 + MARS_ECCENTRICITY)) / (MARS_SEMI_MAJOR_AXIS * (1 - MARS_ECCENTRICITY)));
}
Vector2 tmp = object->current_position;
......@@ -89,16 +122,24 @@ void solar_system_draw(SolarSystem *solar_system, struct gfx_context_t *context)
Vector2 scaled_position = vector2_multiply(object->current_position, 1.0 / (300 * 1E9));
scaled_position = vector2_fit_canvas(scaled_position, SCREEN_WIDTH, SCREEN_HEIGHT);
if (i == 0) {
if (i == SUN_INDEX) {
draw_full_circle(context, scaled_position.x, scaled_position.y, 50, COLOR_YELLOW);
}
if (i == 1) {
if (i == MERCURE_INDEX) {
draw_full_circle(context, scaled_position.x, scaled_position.y, 10, (COLOR_WHITE + COLOR_BLACK));
}
if (i == VENUS_INDEX) {
draw_full_circle(context, scaled_position.x, scaled_position.y, 20, (COLOR_RED + COLOR_YELLOW));
}
if (i == EARTH_INDEX) {
draw_full_circle(context, scaled_position.x, scaled_position.y, 20, COLOR_BLUE);
}
if (i == 2) {
draw_full_circle(context, scaled_position.x, scaled_position.y, 10, COLOR_RED);
if (i == MARS_INDEX) {
draw_full_circle(context, scaled_position.x, scaled_position.y, 12, COLOR_RED);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment