-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSatellite.py
32 lines (26 loc) · 1.61 KB
/
Satellite.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
import math
from PyQt5.QtCore import QPointF, QPoint
from SpaceObject import SpaceObject
class Satellite(SpaceObject):
def __init__(self, name: str, object_diameter: float, orbit_radius: float, speed_degrees_earth_day: float, color,
center_of_planet, *args, **kwargs):
super(Satellite, self).__init__(name, object_diameter, orbit_radius, speed_degrees_earth_day, color, *args,
**kwargs)
self.current_x = center_of_planet[0] + self.orbit_radius
self.current_y = center_of_planet[1]
self.x_center_of_gravity = center_of_planet[0]
self.y_center_of_gravity = center_of_planet[1]
def get_next_coordinates(self, new_center_of_gravity: QPoint):
"""
Вычисляет сдвиг спутника относительно новой позиции его планеты для перехода к следующей позиции спутника
:return: QPoint, где x - сдвиг по Оx, а y - сдвиг по Oy
"""
self.x_center_of_gravity = new_center_of_gravity.x()
self.y_center_of_gravity = new_center_of_gravity.y()
self.current_degrees += self.speed_degrees_earth_day
old_x = self.current_x
old_y = self.current_y
self.current_x = self.x_center_of_gravity + self.orbit_radius * math.cos(math.radians(self.current_degrees))
self.current_y = self.y_center_of_gravity + self.orbit_radius * math.sin(math.radians(self.current_degrees))
result = QPointF(old_x - self.current_x, old_y - self.current_y)
return result.toPoint()