This repository has been archived by the owner on May 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
orbital.py
88 lines (73 loc) · 2.19 KB
/
orbital.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
import numpy as np
from astropy.coordinates import angles
k_Sun = 132749351440.0
def rv2coe(k, a, ecc, inc, raan, argp, nu):
"""Convierte elementos keplerianos a vectores r y v.
Parámetros
==========
k : float
Parámetro gravitacional (km^3 / s^2)
a : float
Semieje mayor (km)
ecc : float
Excentricidad
inc : float
Inclinación (rad)
raan : float
Ascensión recta del nodo ascendente (rad)
argp : float
Argumento del perigeo (rad)
nu : float
Anomalía verdadera (rad)
Devuelve
========
r, v : arrays
Vectores posición (km) y velocidad (km / s)
"""
p = a * (1 - ecc ** 2)
r_pqw = p * np.array([np.cos(nu) / (1 + ecc * np.cos(nu)),
np.sin(nu) / (1 + ecc * np.cos(nu)),
0])
v_pqw = np.sqrt(k / p) * np.array([-np.sin(nu),
ecc + np.cos(nu),
0])
r_ijk = transform(r_pqw, -argp, 'z')
r_ijk = transform(r_ijk, -inc, 'x')
r_ijk = transform(r_ijk, -raan, 'z')
v_ijk = transform(v_pqw, -argp, 'z')
v_ijk = transform(v_ijk, -inc, 'x')
v_ijk = transform(v_ijk, -raan, 'z')
return r_ijk, v_ijk
def rotate(vec, angle, axis):
"""Rotates the coordinate system around axis 1, 2 or 3 a CCW angle.
Parameters
----------
vec : array
Dimension 3 vector.
ax : int
Axis to be rotated.
angle : float
Angle of rotation (rad).
"""
assert vec.shape == (3,)
rot = np.eye(3)
if axis == 'x':
sl = slice(1, 3)
elif axis == 'y':
sl = slice(0, 3, 2)
elif axis == 'z':
sl = slice(0, 2)
rot[sl, sl] = np.array([
[np.cos(angle), np.sin(angle)],
[-np.sin(angle), np.cos(angle)]
])
return np.dot(rot, vec)
def transform(vector, angle, axis):
"""Rotates a coordinate system around axis a positive right-handed angle.
Notes
-----
This is a convenience function, equivalent to
`rotate(vec, -angle, axis, unit)`.
Refer to the documentation of that function for further information.
"""
return rotate(vector, -angle, axis)