Skip to content

Commit 4462b17

Browse files
committed
simplify calculation of lvlh frame rotation
1 parent e1cbbb2 commit 4462b17

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

skyfield/framelib.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# -*- coding: utf-8 -*-
22
"""Raw transforms between coordinate frames, as NumPy matrices."""
33

4-
from numpy import array
5-
6-
from .constants import ANGVEL, ASEC2RAD, DAY_S, pi, tau
4+
from numpy import array, cross
5+
from .constants import ANGVEL, ASEC2RAD, DAY_S, tau
76
from .data.spice import inertial_frames as _inertial_frames
8-
from .elementslib import osculating_elements_of
9-
from .functions import mxm, mxmxm, rot_x, rot_y, rot_z
7+
from .functions import length_of, mxm, rot_x, rot_z
108

119

1210
def build_matrix():
@@ -172,13 +170,14 @@ def __init__(self, satellite):
172170

173171
def rotation_at(self, t):
174172
position = self.satellite.at(t)
175-
elements = osculating_elements_of(position)
176-
i = elements.inclination.radians
177-
u = elements.argument_of_latitude.radians
178-
om = elements.longitude_of_ascending_node.radians
179-
180-
matrix = mxmxm(rot_x(pi / 2.0), rot_y(pi / 2.0), rot_y(om - pi))
181-
matrix = mxmxm(matrix, rot_z(pi - i), rot_y(-u))
173+
position_vec = position.position.km
174+
velocity_vec = position.velocity.km_per_s
175+
z_lvlh = -position_vec / length_of(position_vec)
176+
L_vec = cross(velocity_vec, z_lvlh)
177+
y_lvlh = -L_vec / length_of(L_vec)
178+
x_lvlh = cross(y_lvlh, z_lvlh)
179+
180+
matrix = array([x_lvlh, y_lvlh, z_lvlh]).T
182181

183182
return matrix
184183

0 commit comments

Comments
 (0)