Skip to content

Commit eaa635d

Browse files
committed
reduce calculations in attitude calculation and represent result using Geometric object
1 parent 4462b17 commit eaa635d

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

skyfield/sgp4lib.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from numpy import (
55
array, concatenate, identity, multiply, ones_like, repeat,
66
)
7-
from collections import namedtuple
87
from sgp4.api import SGP4_ERRORS, Satrec
98

109
from .constants import AU_KM, DAY_S, T0, tau
1110
from .framelib import LVLH
1211
from .functions import _T, mxm, mxv, rot_x, rot_y, rot_z
12+
from .positionlib import Geometric
1313
from .searchlib import _find_discrete, find_maxima
1414
from .timelib import compute_calendar_date
1515
from .vectorlib import VectorFunction
@@ -284,26 +284,32 @@ def below_horizon_at(t):
284284
return ts.tt_jd(jd[i]), v[i]
285285

286286
def _attitude(self, t, roll=0.0, pitch=0.0, yaw=0.0, rotation_order="xyz"):
287-
"""Return a unit vector in the attitude direction in local coordinates.
287+
"""Return a unit vector in the attitude direction in ICRF coordinates.
288288
289-
Rotations are applied to an initial vector pointing along the z-axis.
290-
Rotations should be provided as radians; `roll` is rotation about the
291-
x-axis, `pitch` is about the y-axis, and `yaw` is about the z-axis.
289+
Rotations are applied relative to the LVLH frame axes, where the
290+
neutral attitude vector is pointing along the z-axis. Rotation angles
291+
should be provided as radians; `roll` is rotation about the x-axis,
292+
`pitch` is about the y-axis, and `yaw` is about the z-axis.
292293
"""
293294
rotations = {
294-
"x": rot_x(roll) if roll != 0 else _identity,
295-
"y": rot_y(pitch) if pitch != 0 else _identity,
296-
"z": rot_z(yaw) if yaw != 0 else _identity,
295+
"x": (roll, rot_x),
296+
"y": (pitch, rot_y),
297+
"z": (yaw, rot_z),
297298
}
298299

299300
lvlh_attitude = array([0, 0, 1])
300301
for axis in rotation_order:
301-
lvlh_attitude = mxv(rotations[axis], lvlh_attitude)
302-
303-
lvlh_frame = LVLH(self)
304-
direction = mxv(lvlh_frame.rotation_at(t), lvlh_attitude)
305-
Attitude = namedtuple("Attitude", "center, target, t")
306-
attitude = Attitude(self.at(t).position, direction, t)
302+
angle, rotation = rotations[axis]
303+
if angle != 0:
304+
lvlh_attitude = mxv(rotation(angle), lvlh_attitude)
305+
306+
R = LVLH(self).rotation_at(t)
307+
direction = mxv(R, lvlh_attitude)
308+
attitude = Geometric(
309+
position_au=self.at(t).xyz.au,
310+
velocity_au_per_d=self.at(t).velocity.au_per_d,
311+
t=t, center=self.at(t), target=direction
312+
)
307313

308314
return attitude
309315

0 commit comments

Comments
 (0)