-
Notifications
You must be signed in to change notification settings - Fork 0
/
Teleso.py
83 lines (72 loc) · 1.96 KB
/
Teleso.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
import numpy as np
class Teleso:
"""
Trida definujici jedno vesmirne teleso, na ktere mohou pusobit dalsi telesa
"""
G=6.67e-11 # m3s-2kg-1
name=""
def __init__(self,jmeno,m,r,v):
"""
Konstruktor tridy teleso
jmeno = jmeno telesa
m = hmotnost
r = poloha
v = rychlost
"""
Teleso.name=jmeno
self._jmeno=jmeno
self._m=m
self._r=r
self._v=v
self._F=None
self._thist=[]
self._xhist=[]
self._yhist=[]
self._zhist=[]
def __str__(self):
"""
Metoda vypisujici textovou reprezentaci objektu
"""
return str(f"Teleso {self._m}")
def setSila(self,F: np.ndarray):
"""
Nastav silu pusobici na teleso
"""
self._F=F
def sila(self,teleso2:'Teleso') -> np.ndarray:
"""
Urci silu, kterou na teleso self pusobi jine teleso
"""
r=teleso2._r-self._r #
r_delka=np.linalg.norm(r) # vzdalenost teles
r0=r/r_delka # jednotkovy vektor
sila=Teleso.G*self._m*teleso2._m/r_delka**2*r0
return(sila)
def pohni(self,t,dt):
"""
Pohne telesem o casovy krok dt
"""
self._a=self._F/self._m # zrychleni
self._v=self._v+self._a*dt # zmena rychlosti
self._r=self._r+self._v*dt # posun
self._ulozPozici(t)
def _ulozPozici(self,t):
self._thist.append(t)
self._xhist.append(self._r[0])
self._yhist.append(self._r[1])
self._zhist.append(self._r[2])
def pozice(self):
"""
vraci pozici telesa
"""
return(self._r)
def hmotnost(self):
"""
vraci hmotnost
"""
return(self._m)
def zobraz(self,plt):
"""
Zobrazi historii pozice telesa
"""
plt.plot(self._xhist,self._yhist)