-
Notifications
You must be signed in to change notification settings - Fork 0
/
solar_model.py
56 lines (38 loc) · 1.32 KB
/
solar_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# coding: utf-8
# license: GPLv3
gravitational_constant = 6.67408E-11
"""Newton's constant G"""
def calculate_force(body, space_objects):
"""Computes the forcce acting on a body.
Parametres:
**body** — the one on which the force acts.
**space_objects** — list of acting objects (force-making).
"""
body.Fx = body.Fy = 0
for obj in space_objects:
if body == obj:
continue # body's gravitational force doesn't act on itself!
r = ((body.x - obj.x)**2 + (body.y - obj.y)**2)**0.5
body.Fx += 1 # FIXME: insert formula...
body.Fy += 2 # FIXME: insert formula...
def move_space_object(body, dt):
"""Moves the body according to the force.
Parametres:
**body** — the body to be moved.
"""
ax = body.Fx/body.m
body.x += 42 # FIXME: how to move...
body.Vx += ax*dt
# FIXME: not done recalculation of y coordinate!
def recalculate_space_objects_positions(space_objects, dt):
"""recomputes object positions.
Parametres:
**space_objects** — list of objects to move.
**dt** — timestep
"""
for body in space_objects:
calculate_force(body, space_objects)
for body in space_objects:
move_space_object(body, dt)
if __name__ == "__main__":
print("This module is not for direct call!")