Loading ale/rotation.py +47 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,26 @@ class ConstantRotation: The NAIF ID code for the destination frame """ def from_matrix(mat, source, dest): """ Create a constant rotation from a directed cosine matrix Parameters ---------- mat : 2darray The rotation matrix source : int The NAIF ID code for the source frame dest : int The NAIF ID code for the destination frame See Also -------- scipy.spatial.transform.Rotation.from_dcm """ rot = Rotation.from_dcm(mat) return ConstantRotation(rot.as_quat(), source, dest) def __init__(self, quat, source, dest): """ Construct a constant rotation Loading Loading @@ -104,9 +124,35 @@ class TimeDependentRotation: The NAIF ID code for the destination frame """ def from_euler(sequence, euler, times, source, dest): """ Create a time dependent rotation from a set of Euler angles. Parameters ---------- sequence : string The axis sequence that the Euler angles are applied in. I.E. 'XYZ' or 'ZXZ'. euler : 2darray 2D numpy array of the euler angle rotations in radians. times : array The time for each rotation in euler. This array must be sorted in ascending order. source : int The NAIF ID code for the source frame dest : int The NAIF ID code for the destination frame See Also -------- scipy.spatial.transform.Rotation.from_euler """ rot = Rotation.from_euler(sequence, np.asarray(euler)) return TimeDependentRotation(rot.as_quat(), times, source, dest) def __init__(self, quats, times, source, dest): """ Construct a constant rotation Construct a time dependent rotation Parameters ---------- Loading tests/pytests/test_rotation.py +22 −0 Original line number Diff line number Diff line Loading @@ -89,3 +89,25 @@ def test_rotation_matrix(): mat = rot.rotation_matrix() assert isinstance(mat, np.ndarray) assert mat.shape == (3, 3) def test_from_euler(): angles = [[np.pi/2, np.pi/2, 0], [-np.pi/2, -np.pi/2, 0]] times = [0, 1] seq = 'XYZ' rot = TimeDependentRotation.from_euler(seq, angles, times, 0, 1) expected_quats = np.asarray([[0.5, 0.5, 0.5, 0.5], [-0.5, -0.5, 0.5, 0.5]]) np.testing.assert_almost_equal(rot.quats, expected_quats) np.testing.assert_equal(rot.times, np.asarray(times)) assert rot.source == 0 assert rot.dest == 1 def test_from_matrix(): mat = [[0, 0, 1], [1, 0 ,0], [0, 1, 0]] rot = ConstantRotation.from_matrix(mat, 0, 1) expected_quats = np.asarray([0.5, 0.5, 0.5, 0.5]) np.testing.assert_almost_equal(rot.quat, expected_quats) assert rot.source == 0 assert rot.dest == 1 Loading
ale/rotation.py +47 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,26 @@ class ConstantRotation: The NAIF ID code for the destination frame """ def from_matrix(mat, source, dest): """ Create a constant rotation from a directed cosine matrix Parameters ---------- mat : 2darray The rotation matrix source : int The NAIF ID code for the source frame dest : int The NAIF ID code for the destination frame See Also -------- scipy.spatial.transform.Rotation.from_dcm """ rot = Rotation.from_dcm(mat) return ConstantRotation(rot.as_quat(), source, dest) def __init__(self, quat, source, dest): """ Construct a constant rotation Loading Loading @@ -104,9 +124,35 @@ class TimeDependentRotation: The NAIF ID code for the destination frame """ def from_euler(sequence, euler, times, source, dest): """ Create a time dependent rotation from a set of Euler angles. Parameters ---------- sequence : string The axis sequence that the Euler angles are applied in. I.E. 'XYZ' or 'ZXZ'. euler : 2darray 2D numpy array of the euler angle rotations in radians. times : array The time for each rotation in euler. This array must be sorted in ascending order. source : int The NAIF ID code for the source frame dest : int The NAIF ID code for the destination frame See Also -------- scipy.spatial.transform.Rotation.from_euler """ rot = Rotation.from_euler(sequence, np.asarray(euler)) return TimeDependentRotation(rot.as_quat(), times, source, dest) def __init__(self, quats, times, source, dest): """ Construct a constant rotation Construct a time dependent rotation Parameters ---------- Loading
tests/pytests/test_rotation.py +22 −0 Original line number Diff line number Diff line Loading @@ -89,3 +89,25 @@ def test_rotation_matrix(): mat = rot.rotation_matrix() assert isinstance(mat, np.ndarray) assert mat.shape == (3, 3) def test_from_euler(): angles = [[np.pi/2, np.pi/2, 0], [-np.pi/2, -np.pi/2, 0]] times = [0, 1] seq = 'XYZ' rot = TimeDependentRotation.from_euler(seq, angles, times, 0, 1) expected_quats = np.asarray([[0.5, 0.5, 0.5, 0.5], [-0.5, -0.5, 0.5, 0.5]]) np.testing.assert_almost_equal(rot.quats, expected_quats) np.testing.assert_equal(rot.times, np.asarray(times)) assert rot.source == 0 assert rot.dest == 1 def test_from_matrix(): mat = [[0, 0, 1], [1, 0 ,0], [0, 1, 0]] rot = ConstantRotation.from_matrix(mat, 0, 1) expected_quats = np.asarray([0.5, 0.5, 0.5, 0.5]) np.testing.assert_almost_equal(rot.quat, expected_quats) assert rot.source == 0 assert rot.dest == 1