Example #1
0
    def from_ra_dec_roll(ra, dec, roll):
        '''constructs a quaternion from ra/dec/roll params
        using Tait-Bryan angles XYZ.

        ra stands for right ascencion, and usually lies in [0, 360]
        dec stands for declination, and usually lies in [-90, 90]
        roll stands for rotation/rolling, and usually lies in [0, 360]
        '''
        raq = exp(GeneralQuaternion(0, 0, 0, -np.deg2rad(ra) / 2))
        decq = exp(GeneralQuaternion(0, 0, -np.deg2rad(dec) / 2, 0))
        rollq = exp(GeneralQuaternion(0, -np.deg2rad(roll) / 2, 0, 0))
        q = rollq * decq * raq
        return Quaternion(*q.coordinates)
Example #2
0
    def test_type(self):
        # Unit quaternion can be unitary or general:
        assert isinstance(GeneralQuaternion.unit(), GeneralQuaternion)
        assert isinstance(Quaternion.unit(), Quaternion)

        # Unit quaternion can not be unitary:
        assert isinstance(GeneralQuaternion.zero(), GeneralQuaternion)
        assert not isinstance(Quaternion.zero(), Quaternion)
        assert isinstance(Quaternion.zero(), GeneralQuaternion)

        assert isinstance(exp(GeneralQuaternion(1, 2, 3, 4)), GeneralQuaternion)
        assert isinstance(exp(Quaternion(1, 2, 3, 4)), Quaternion)

        assert isinstance(log(Quaternion(1, 2, 3, 4)), GeneralQuaternion)
        assert not isinstance(log(Quaternion(1, 2, 3, 4)), Quaternion)
 def test_rotate_vector_schaub(self):
     q1 = exp(Quaternion(0, .1, .02, -.3))
     vector = QuaternionTest.schaub_example_dcm[:, 1]
     rotated_vector = q1 * vector
     np.testing.assert_allclose(rotated_vector,
                                q1.matrix.dot(vector),
                                atol=1e-5,
                                rtol=0)
Example #4
0
    def from_rotation_vector(xyz):
        """
        Returns the quaternion corresponding to the rotation xyz.
        Explicitly: rotation occurs along the axis xyz and has angle
        norm(xyz)

        This corresponds to the exponential of the quaternion with
        real part 0 and imaginary part 1/2 * xyz.
        """
        a, b, c = .5 * np.array(xyz)
        q_exp = exp(GeneralQuaternion(0, a, b, c))
        return Quaternion(*q_exp.coordinates)
 def test_exp_identity(self):
     assert exp(GeneralQuaternion.zero()) == GeneralQuaternion.unit()
 def test_exp_identical_both_ways(self, arr):
     q = GeneralQuaternion(*arr)
     assert exp(q) == q.exp()
 def test_exp_log(self, arr):
     assume(np.linalg.norm(arr) > DEFAULT_TOLERANCE)
     q = GeneralQuaternion(*arr).normalized()
     assert exp(log(q)) == q
     assert log(exp(q)) == GeneralQuaternion(*q.coordinates)
 def test_exp_norm(self, arr1):
     q1 = GeneralQuaternion(*arr1)
     assert exp(q1).norm() == pytest.approx(np.exp(q1.qr))  # |exp(q)| == exp(real(q)|
 def test_exp_log(self, arr):
     assume(np.linalg.norm(arr) > DEFAULT_TOLERANCE)
     q = GeneralQuaternion(*arr).normalized()
     assert exp(log(q)) == q
     assert (log(exp(q)).imaginary.tolist() == pytest.approx(
         q.imaginary.tolist()))  # log defined up to real