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
e506aa6d
Commit
e506aa6d
authored
3 years ago
by
Boris Stefanovic
Browse files
Options
Downloads
Patches
Plain Diff
ADD: update_system
parent
d840a2e7
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
main.c
+2
-6
2 additions, 6 deletions
main.c
planet/constants.h
+8
-7
8 additions, 7 deletions
planet/constants.h
planet/planet.c
+22
-1
22 additions, 1 deletion
planet/planet.c
with
32 additions
and
14 deletions
main.c
+
2
−
6
View file @
e506aa6d
...
...
@@ -8,20 +8,16 @@
#define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 1000
// arbitraire, en secondes ?
#define DELTA_T 0.125
int
main
()
{
srand
(
time
(
NULL
));
struct
gfx_context_t
*
ctxt
=
gfx_create
(
"Planetary system"
,
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
struct
gfx_context_t
*
ctxt
=
gfx_create
(
"Planetary system"
,
SCREEN_WIDTH
,
SCREEN_HEIGHT
);
if
(
!
ctxt
)
{
fprintf
(
stderr
,
"Graphics initialization failed!
\n
"
);
return
EXIT_FAILURE
;
}
// TODO : create your system
system_t
sys
=
create_system
(
DELTA_T
);
system_t
sys
=
create_system
(
0
.
125
);
// end : create system
while
(
true
)
{
gfx_present
(
ctxt
);
...
...
This diff is collapsed.
Click to expand it.
planet/constants.h
+
8
−
7
View file @
e506aa6d
...
...
@@ -5,28 +5,29 @@
#define G 6.67e-11
#define M_SOLEIL 1.989e30
//
source: CRM
//
mass
#define M_TERRE 5.9742e24
// source: wiki
#define M_MERCURE 3.3011e23
#define M_VENUS 4.8675e24
#define M_MARS 6.4171e23
// major axis
#define A_MERCURE 5.7909e10
#define A_VENUS 1.0821e11
#define A_TERRE 1.4960e11
#define A_MARS 2.2794e11
// excentricity
#define E_MERCURE 0.205630
#define E_VENUS 0.006772
#define E_TERRE 0.0167086
#define E_MARS 0.0934
//
TODO:
perihelion
#define PER_MERCURE
#define PER_VENUS
#define PER_TERRE
#define PER_MARS
// perihelion
#define PER_MERCURE
4.60012e10
#define PER_VENUS
1.07477e11
#define PER_TERRE
1.47095e11
#define PER_MARS
2.06700e11
#endif //PLANET_CONSTANTS_H
This diff is collapsed.
Click to expand it.
planet/planet.c
+
22
−
1
View file @
e506aa6d
...
...
@@ -47,7 +47,28 @@ system_t create_system(double delta_t) {
void
show_system
(
struct
gfx_context_t
*
ctxt
,
system_t
*
system
);
void
update_system
(
system_t
*
system
,
double
delta_t
);
void
update_system
(
system_t
*
system
,
double
delta_t
)
{
for
(
uint32_t
i
=
0
;
i
<
system
->
nb_planets
;
++
i
)
{
// apply the effects of the sun
vec2
a
=
vec2_mul
((
G
*
system
->
star
.
mass
)
/
r_star_2
,
vec2_normalize
(
system
->
planets
[
i
].
pos
));
// apply the effects of all other planets
for
(
uint32_t
k
=
0
;
k
<
system
->
nb_planets
;
++
k
)
{
if
(
k
==
i
)
continue
;
const
vec2
r_ik
=
vec2_sub
(
system
->
planets
[
k
].
pos
,
system
->
planets
[
i
].
pos
);
const
vec2
u
=
vec2_normalize
(
r_ik
);
// unit vector from planet i to planet k
// force already divided by system->planets[i].mass to get acceleration
const
double
a_norm
=
(
G
*
system
->
planets
[
k
].
mass
)
/
vec2_norm_sqr
(
r_ik
);
const
vec2
a_k
=
vec2_mul
(
a_norm
,
u
);
a
=
vec2_add
(
a
,
a_k
);
}
// update position
vec2
next_pos
=
vec2_mul
(
2
.
0
,
system
->
planets
[
i
].
pos
);
next_pos
=
vec2_sub
(
next_pos
,
system
->
planets
[
i
].
prec_pos
);
next_pos
=
vec2_add
(
next_pos
,
vec2_mul
(
delta_t
*
delta_t
,
a
));
system
->
planets
[
i
].
prec_pos
=
system
->
planets
[
i
].
pos
;
system
->
planets
[
i
].
pos
=
next_pos
;
}
}
void
free_system
(
system_t
*
system
);
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