Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
phys_planetes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
boris.stefanov
phys_planetes
Commits
3e06e219
Commit
3e06e219
authored
3 years ago
by
BobLeHibou
Browse files
Options
Downloads
Patches
Plain Diff
ADD: fictional planets, separate, everything works
parent
204d596c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
planet/constants.h
+18
-40
18 additions, 40 deletions
planet/constants.h
planet/planet.c
+62
-35
62 additions, 35 deletions
planet/planet.c
planet/planet.h
+1
-2
1 addition, 2 deletions
planet/planet.h
with
81 additions
and
77 deletions
planet/constants.h
+
18
−
40
View file @
3e06e219
...
@@ -2,62 +2,40 @@
...
@@ -2,62 +2,40 @@
#define PLANET_CONSTANTS_H
#define PLANET_CONSTANTS_H
// display
#define DISPLAY_PLANET_RADIUS_DIV 1.0e23
#define DISPLAY_MAX_ORBIT_RADIUS
// logic
#define PLANET_COUNT 4
// physical constants
// physical constants
#define G 6.67e-11
#define G 6.67e-11
#define M_SOLEIL 1.989e30
#define M_SOLEIL 1.989e30
// perihelion
#define PER_MERCURE 4.60012e10
#define PER_VENUS 1.07477e11
#define PER_TERRE 1.47095e11
#define PER_MARS 2.06700e11
// mass
// mass
#define M_MERCURE 3.3011e23
#define M_MERCURE 3.3011e23
#define M_VENUS 4.8675e24
#define M_VENUS 4.8675e24
#define M_TERRE 5.9742e24
#define M_TERRE 5.9742e24
#define M_MARS 6.4171e23
#define M_MARS 6.4171e23
#define M_JUPITER 1.8982e27
#define M_SATURN 5.6834e26
#define M_URANUS 8.6810e25
#define M_NEPTUNE 1.02413e26
#define M_PLUTO 1.303e22
// major axis
#define A_MERCURE 5.7909e10
#define A_VENUS 1.0821e11
#define A_TERRE 1.4960e11
#define A_MARS 2.2794e11
#define A_JUPITER 7.7857e11
#define A_SATURN 1.43353e12
#define A_URANUS 2.870972e12
#define A_NEPTUNE 4.50e12
#define A_PLUTO 5.90638e12
// excentricity
// excentricity
#define E_MERCURE 0.205630
#define E_MERCURE 0.205630
#define E_VENUS 0.006772
#define E_VENUS 0.006772
#define E_TERRE 0.0167086
#define E_TERRE 0.0167086
#define E_MARS 0.0934
#define E_MARS 0.0934
#define E_JUPITER 0.0489
#define E_SATURN 0.0565
#define E_URANUS 0.04717
#define E_NEPTUNE 0.008678
#define E_PLUTO 0.2488
// perihelion
// major axis
#define PER_MERCURE 4.60012e10
#define A_MERCURE 5.7909e10
#define PER_VENUS 1.07477e11
#define A_VENUS 1.0821e11
#define PER_TERRE 1.47095e11
#define A_TERRE 1.4960e11
#define PER_MARS 2.06700e11
#define A_MARS 2.2794e11
#define PER_JUPITER 7.40520e11
#define PER_SATURN 1.35255e12
// radius: no hope of writing anything user-friendly that is to scale...
#define PER_URANUS 2.73556e12
#define R_SUN 6.96342e8
#define PER_NEPTUNE 4.46e12
#define R_MERCURY 2.4397e6
#define PER_PLUTO 4.43682e12
#define R_VENUS 6.0518e6
#define R_EARTH 6.3710e6
#define R_MARS 3.3895e6
#endif //PLANET_CONSTANTS_H
#endif //PLANET_CONSTANTS_H
This diff is collapsed.
Click to expand it.
planet/planet.c
+
62
−
35
View file @
3e06e219
...
@@ -3,7 +3,25 @@
...
@@ -3,7 +3,25 @@
#include
"constants.h"
#include
"constants.h"
#define NB_PLANETS 4
#define NB_PLANETS 4
#define NB_FICT 4
#define DISPLAY_DISTANCE 4.0e11
const
double
masses
[]
=
{
M_MERCURE
,
M_VENUS
,
M_TERRE
,
M_MARS
};
const
double
perihelions
[]
=
{
PER_MERCURE
,
PER_VENUS
,
PER_TERRE
,
PER_MARS
};
const
double
eccentricities
[]
=
{
E_MERCURE
,
E_VENUS
,
E_TERRE
,
E_MARS
};
const
double
axis_major
[]
=
{
A_MERCURE
,
A_VENUS
,
A_TERRE
,
A_MARS
};
const
uint32_t
display_sun_radius
=
45
;
const
uint32_t
display_radii
[]
=
{
5
,
10
,
10
,
20
};
// fictional
const
double
fict_per
[]
=
{
7.80e10
,
1.28e11
,
1.85e11
,
3.00e11
};
const
double
fict_mas
[]
=
{
5.9e23
,
7.0e23
,
4.9e24
,
7.0e23
};
const
double
fict_ecc
[]
=
{
0
.
025
,
0
.
005
,
0
.
01
,
0
.
000
8
};
const
double
fict_axm
[]
=
{
8.0e10
,
1.2e11
,
2.0e11
,
2.9e11
};
const
uint32_t
fict_display_radii
[]
=
{
7
,
8
,
14
,
24
};
planet_t
create_planet
(
double
mass
,
vec2
pos
)
{
planet_t
create_planet
(
double
mass
,
vec2
pos
)
{
...
@@ -15,60 +33,69 @@ planet_t create_planet(double mass, vec2 pos) {
...
@@ -15,60 +33,69 @@ planet_t create_planet(double mass, vec2 pos) {
}
}
vec2
calc_prev_position
(
const
double
star_mass
,
const
vec2
pos
,
const
double
ecc
,
const
double
axm
,
const
double
delta_t
)
{
double
vel
=
G
*
star_mass
*
(
1
.
0
+
ecc
);
vel
/=
axm
*
(
1
.
0
-
ecc
);
vel
=
sqrt
(
vel
);
const
vec2
ru
=
vec2_normalize
(
pos
);
const
vec2
rp
=
vec2_create
(
-
ru
.
y
,
ru
.
x
);
const
vec2
v
=
vec2_mul
(
vel
,
rp
);
const
vec2
prec_pos
=
vec2_sub
(
pos
,
vec2_mul
(
delta_t
,
v
));
return
prec_pos
;
}
system_t
create_system
(
double
delta_t
)
{
system_t
create_system
(
double
delta_t
)
{
system_t
system
;
system_t
system
;
system
.
star
=
create_planet
(
M_SOLEIL
,
vec2_create_zero
());
system
.
star
=
create_planet
(
M_SOLEIL
,
vec2_create_zero
());
system
.
nb_planets
=
4
;
system
.
nb_planets
=
NB_PLANETS
+
NB_FICT
;
system
.
planets
=
malloc
(
system
.
nb_planets
*
sizeof
(
planet_t
));
system
.
planets
=
malloc
(
system
.
nb_planets
*
sizeof
(
planet_t
));
double
masses
[]
=
{
// real planets
M_MERCURE
,
for
(
uint32_t
i
=
0
;
i
<
NB_PLANETS
;
++
i
)
{
M_VENUS
,
M_TERRE
,
M_MARS
};
vec2
positions
[]
=
{
vec2_create
(
PER_MERCURE
,
0
.
0
),
vec2_create
(
PER_VENUS
,
0
.
0
),
vec2_create
(
PER_TERRE
,
0
.
0
),
vec2_create
(
PER_MARS
,
0
.
0
)};
double
eccentricities
[]
=
{
E_MERCURE
,
E_VENUS
,
E_TERRE
,
E_MARS
};
double
axis_major
[]
=
{
A_MERCURE
,
A_VENUS
,
A_TERRE
,
A_MARS
};
for
(
uint32_t
i
=
0
;
i
<
system
.
nb_planets
;
++
i
)
{
system
.
planets
[
i
].
mass
=
masses
[
i
];
system
.
planets
[
i
].
mass
=
masses
[
i
];
system
.
planets
[
i
].
pos
=
positions
[
i
];
system
.
planets
[
i
].
pos
=
vec2_create
(
perihelions
[
i
],
0
.
0
);
double
vel
=
G
*
system
.
star
.
mass
*
(
1
.
0
+
eccentricities
[
i
]);
system
.
planets
[
i
].
prec_pos
=
calc_prev_position
(
vel
/=
axis_major
[
i
]
*
(
1
.
0
-
eccentricities
[
i
]);
system
.
star
.
mass
,
vel
=
sqrt
(
vel
);
system
.
planets
[
i
].
pos
,
const
vec2
ru
=
vec2_normalize
(
vec2_sub
(
system
.
planets
[
i
].
pos
,
system
.
star
.
pos
));
eccentricities
[
i
],
const
vec2
rp
=
vec2_create
(
-
ru
.
y
,
ru
.
x
);
axis_major
[
i
],
const
vec2
v
=
vec2_mul
(
vel
,
rp
);
delta_t
);
system
.
planets
[
i
].
prec_pos
=
vec2_sub
(
system
.
planets
[
i
].
pos
,
vec2_mul
(
delta_t
,
v
));
}
// fictional planets
for
(
uint32_t
i
=
0
;
i
<
NB_FICT
;
++
i
)
{
const
size_t
idx
=
i
+
NB_PLANETS
;
system
.
planets
[
idx
].
mass
=
fict_mas
[
i
];
system
.
planets
[
idx
].
pos
=
vec2_create
(
fict_per
[
i
],
0
.
0
);
system
.
planets
[
idx
].
prec_pos
=
calc_prev_position
(
system
.
star
.
mass
,
system
.
planets
[
idx
].
pos
,
fict_ecc
[
i
],
fict_axm
[
i
],
delta_t
);
}
}
return
system
;
return
system
;
}
}
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
,
const
double
show_radius
)
{
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
)
{
// draw sun
// draw sun
const
coordinates
xy_sun
=
vec2_to_coordinates_centered
(
const
coordinates
xy_sun
=
vec2_to_coordinates_centered
(
vec2_normalize
(
system
->
star
.
pos
),
vec2_normalize
(
system
->
star
.
pos
),
ctxt
->
width
,
ctxt
->
width
,
ctxt
->
height
);
ctxt
->
height
);
draw_full_circle
(
ctxt
,
xy_sun
.
column
,
xy_sun
.
row
,
50
,
COLOR_YELLOW
);
draw_full_circle
(
ctxt
,
xy_sun
.
column
,
xy_sun
.
row
,
display_sun_radius
,
COLOR_YELLOW
);
// draw planets
// draw planets
for
(
uint32_t
i
=
0
;
i
<
system
->
nb_planets
;
++
i
)
{
for
(
uint32_t
i
=
0
;
i
<
system
->
nb_planets
;
++
i
)
{
const
double
display_distance
=
vec2_norm
(
system
->
planets
[
i
].
pos
)
/
DISPLAY_DISTANCE
;
const
coordinates
xy
=
vec2_to_coordinates_centered
(
const
coordinates
xy
=
vec2_to_coordinates_centered
(
vec2_mul
(
vec2_norm
(
system
->
planets
[
i
].
pos
)
/
show_radius
,
vec2_normalize
(
system
->
planets
[
i
].
pos
)),
vec2_mul
(
display_distance
,
vec2_normalize
(
system
->
planets
[
i
].
pos
)),
ctxt
->
width
,
ctxt
->
width
,
ctxt
->
height
);
ctxt
->
height
);
draw_full_circle
(
ctxt
,
xy
.
column
,
xy
.
row
,
20
,
COLOR_BLUE
);
if
(
i
<
NB_PLANETS
)
{
draw_full_circle
(
ctxt
,
xy
.
column
,
xy
.
row
,
display_radii
[
i
],
COLOR_BLUE
);
}
else
{
draw_full_circle
(
ctxt
,
xy
.
column
,
xy
.
row
,
fict_display_radii
[
i
-
NB_PLANETS
],
COLOR_GREEN
);
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
planet/planet.h
+
1
−
2
View file @
3e06e219
...
@@ -20,8 +20,7 @@ planet_t create_planet(double mass, vec2 pos);
...
@@ -20,8 +20,7 @@ planet_t create_planet(double mass, vec2 pos);
system_t
create_system
(
double
delta_t
);
system_t
create_system
(
double
delta_t
);
//void show_system(struct gfx_context_t* ctxt, system_t* system);
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
);
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
,
const
double
show_radius
);
void
update_system
(
system_t
*
system
,
double
delta_t
);
void
update_system
(
system_t
*
system
,
double
delta_t
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment