-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget_position_velocity.py
More file actions
39 lines (32 loc) · 1.39 KB
/
get_position_velocity.py
File metadata and controls
39 lines (32 loc) · 1.39 KB
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
from astropy import units as u
from poliastro.bodies import *
from poliastro.core.elements import coe2rv
from poliastro.twobody import Orbit
class GetPositionVectors:
def __init__(self, orbit):
self.a = orbit.a
self.ecc = orbit.ecc
self.inc = orbit.inc
self.raan = orbit.raan
self.argp = orbit.argp
self.body = orbit.attractor
self.k = orbit.attractor.k.to(u.km**3 / u.s**2) # Gravitational parameter in km^3/s^2
self.p = (self.a * (1 - self.ecc**2)).to(u.km) # Semi-latus rectum in km
def get_position_velocity(self, nu):
'''
Return the position and velocity vector for any orbit.
'''
r_ijk, v_ijk = coe2rv(self.k, self.p, self.ecc.value, self.inc.to(u.rad).value,
self.raan.to(u.rad).value, self.argp.to(u.rad).value, nu.to(u.rad).value)
position = r_ijk * u.km
velocity = v_ijk * u.km / u.s
return position, velocity
def get_periapsis_apoapsis_positions(self):
'''
Return the position and velocity vector for periapsis and apoapsis of any given orbit.
'''
nu_periapsis = 0 * u.deg
position_periapsis, _ = self.get_position_velocity(nu_periapsis)
nu_apoapsis = 180 * u.deg
position_apoapsis, _ = self.get_position_velocity(nu_apoapsis)
return position_periapsis, position_apoapsis