mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Added handling of inclination, longitude of ascending node, and argument of periapsis.
This commit is contained in:
parent
fc7c8601e6
commit
e8942d925c
|
@ -52,15 +52,17 @@ class Satellite(Planet):
|
|||
self.orbit_speed = kwargs.pop('orbit_speed', 1)
|
||||
|
||||
# Semi-major axis and eccentricity defines orbit
|
||||
self.distance = kwargs.pop('distance', 100)
|
||||
self.eccentricity = kwargs.pop('eccentricity', 0)
|
||||
distance = kwargs.pop('distance', 100)
|
||||
eccentricity = kwargs.pop('eccentricity', 0)
|
||||
|
||||
# Inclination and longitude of ascending node defines orbital plane
|
||||
self.inclination = kwargs.pop('inclination', 0)
|
||||
# Inclination, longitude of ascending node, and argument of periapsis defines orbital plane
|
||||
inclination = kwargs.pop('inclination', 0)
|
||||
longitude = kwargs.pop('longitude', 0)
|
||||
argument = kwargs.pop('argument', 0)
|
||||
|
||||
self.theta = 0
|
||||
# OpenGL's z-axis is reversed
|
||||
self.orbit = KeplerOrbit(self.distance, self.eccentricity, -self.inclination)
|
||||
self.orbit = KeplerOrbit(distance, eccentricity, inclination, longitude, argument)
|
||||
super(Satellite, self).__init__(*args, **kwargs)
|
||||
|
||||
def update(self):
|
||||
|
|
|
@ -159,9 +159,9 @@ class Applet(pyglet.window.Window):
|
|||
elif symbol == key.NUM_DIVIDE:
|
||||
self.speed -= 10
|
||||
elif symbol == key.PAGEUP:
|
||||
self.speed += 1000
|
||||
self.speed += 100
|
||||
elif symbol == key.PAGEDOWN:
|
||||
self.speed -= 1000
|
||||
self.speed -= 100
|
||||
elif symbol == key.I:
|
||||
self.info = not self.info
|
||||
elif symbol == key.D:
|
||||
|
|
|
@ -1,15 +1,69 @@
|
|||
from math import sin, cos, tan, atan, sqrt, radians
|
||||
from math import sin, cos, tan, atan, sqrt, radians, degrees
|
||||
|
||||
|
||||
class KeplerOrbit(object):
|
||||
def __init__(self, sma, eccentricity, inclination=0):
|
||||
def __init__(self, sma, eccentricity, inclination=0, longitude=0, argument=0):
|
||||
self.sma = sma
|
||||
self.eccentricity = eccentricity
|
||||
self.inclination = radians(inclination)
|
||||
self.inclination = inclination
|
||||
self.longitude = longitude
|
||||
self.argument = argument
|
||||
self.__true_anomaly_factor = sqrt((1 + eccentricity)/(1 - eccentricity))
|
||||
self.__distance_factor = sma * (1 - eccentricity ** 2)
|
||||
self.__sin_inclination = sin(self.inclination)
|
||||
self.__cos_inclination = cos(self.inclination)
|
||||
|
||||
@property
|
||||
def inclination(self):
|
||||
return degrees(self._inclination)
|
||||
|
||||
@inclination.setter
|
||||
def inclination(self, value):
|
||||
self.inclination_radian = radians(value)
|
||||
|
||||
@property
|
||||
def inclination_radian(self):
|
||||
return self._inclination
|
||||
|
||||
@inclination_radian.setter
|
||||
def inclination_radian(self, value):
|
||||
self._inclination = value
|
||||
self.__sin_inclination = sin(self._inclination)
|
||||
self.__cos_inclination = cos(self._inclination)
|
||||
|
||||
@property
|
||||
def longitude(self):
|
||||
return degrees(self._longitude)
|
||||
|
||||
@longitude.setter
|
||||
def longitude(self, value):
|
||||
self.longitude_radian = radians(value)
|
||||
|
||||
@property
|
||||
def longitude_radian(self):
|
||||
return self._longitude
|
||||
|
||||
@longitude_radian.setter
|
||||
def longitude_radian(self, value):
|
||||
self._longitude = value
|
||||
self.__sin_longitude = sin(self._longitude)
|
||||
self.__cos_longitude = cos(self._longitude)
|
||||
|
||||
@property
|
||||
def argument(self):
|
||||
return degrees(self._argument)
|
||||
|
||||
@argument.setter
|
||||
def argument(self, value):
|
||||
self.argument_radian = radians(value)
|
||||
|
||||
@property
|
||||
def argument_radian(self):
|
||||
return self._argument
|
||||
|
||||
@argument_radian.setter
|
||||
def argument_radian(self, value):
|
||||
self._argument = value
|
||||
self.__sin_argument = sin(self._argument)
|
||||
self.__cos_argument = cos(self._argument)
|
||||
|
||||
def eccentric_anomaly(self, mean_anomaly):
|
||||
e1 = mean_anomaly
|
||||
|
@ -30,7 +84,12 @@ class KeplerOrbit(object):
|
|||
y = r * sin(phi)
|
||||
z = 0
|
||||
|
||||
x, z = (x * self.__cos_inclination - z * self.__sin_inclination,
|
||||
x * self.__sin_inclination + z * self.__cos_inclination)
|
||||
# phi = longitude, theta = inclination, psi = argument
|
||||
x, y = (x * self.__cos_longitude + y * self.__sin_longitude,
|
||||
-x * self.__sin_longitude + y * self.__cos_longitude)
|
||||
x, z = (x * self.__cos_inclination + z * self.__sin_inclination,
|
||||
-x * self.__sin_inclination + z * self.__cos_inclination)
|
||||
x, y = (x * self.__cos_argument + y * self.__sin_argument,
|
||||
-x * self.__sin_argument + y * self.__cos_argument)
|
||||
|
||||
return x, y, z
|
||||
|
|
|
@ -109,7 +109,8 @@ def load_world(file):
|
|||
x -= distance
|
||||
type = partial(Satellite, parent=parent, orbit_speed=info.get('orbit_speed', 1),
|
||||
distance=distance, eccentricity=info.get('eccentricity', 0),
|
||||
inclination=info.get('inclination', 0))
|
||||
inclination=info.get('inclination', 0), longitude=info.get('longitude', 0),
|
||||
argument=info.get('argument', 0))
|
||||
|
||||
atmosphere_id = 0
|
||||
cloudmap_id = 0
|
||||
|
|
Loading…
Reference in a new issue