-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoustava.py
112 lines (96 loc) · 2.77 KB
/
Soustava.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#import Teleso
from Teleso import Teleso
import numpy as np
import matplotlib.pyplot as plt
from typing import List
class Soustava:
"""
Trida zahrnujici nekolik teles
"""
def __init__(self):
"""
Konstruktor - jen vynuluje pocet teles
"""
self._telesa: List[Teleso]=[] # prazdny list
self._xCent=[]
self._yCent=[]
self._zCent=[]
self._t=[]
def __str__(self):
text=f"Soustava ma {len(self._telesa)} teles: "
for teleso in self._telesa:
text=text+teleso._jmeno+","
return(text)
def pridej_teleso(self,teleso:'Teleso'):
"""
Prida teleso do soustavy teles
"""
if (isinstance(teleso,Teleso)):
self._telesa.append(teleso)
else:
print("Nejde")
def hmotny_stred(self):
M=0.0
r=np.array([0,0,0])
for teleso in self._telesa:
r=r+teleso.pozice()*teleso.hmotnost();
M=M+teleso.hmotnost()
return(r/M) # hmotny stred
def spocitej_sily_na_telesa(self):
"""
Spocita sily pusobici na jednotliva telesa soustavy
"""
for teleso in self._telesa:
F=np.array([0,0,0]) # inicializuj silu
for teleso2 in self._telesa:
if (teleso is teleso2):
#print("teleso a teleso2 jsou stejne objekty, nemohou pusobit vzajemne")
continue
F=F+teleso.sila(teleso2)
teleso.setSila(F)
def pohni_telesy(self,t,dt):
"""
spocita sily pusobici na telesa a pohne telesy o dany casovy krok
"""
self.spocitej_sily_na_telesa()
for teleso in self._telesa:
teleso.pohni(t,dt)
rCent=self.hmotny_stred()
self._xCent.append(rCent[0])
self._yCent.append(rCent[1])
self._zCent.append(rCent[2])
self._t.append(t)
def zobraz_soustavu(self):
"""
Nakresli obrazek soustavy
"""
plt.figure(1,figsize=[20,10])
for teleso in self._telesa:
teleso.zobraz(plt)
plt.plot(self._xCent,self._yCent)
plt.axis('equal')
plt.show()
r=np.array([0,0,0])
v=np.array([0,0,0])
zeme=Teleso("Zeme",5.972e24,r,v)
r=np.array([384400e3,0,0])
T=27.321582*24*60*60 # obezna doba mesice
s=2*np.pi*r[0]
v_mesic=s/T
v=np.array([0.0,v_mesic,0])
mesic=Teleso("Mesic",7.347e22,r,v)
print(zeme)
soustava=Soustava()
soustava.pridej_teleso(4)
soustava.pridej_teleso(zeme)
print(soustava)
soustava.pridej_teleso(mesic)
print(soustava)
soustava.spocitej_sily_na_telesa()
dt=1*60*60 # 1 hodina
t=0
while t<=5.5*T:
t=t+dt
soustava.pohni_telesy(t,dt)
r=soustava.hmotny_stred()
soustava.zobraz_soustavu()