Example #1
0
    def test_operators_quaternion(self):
        q1 = Quaternion()
        q2 = Quaternion.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: q1 + q2)

        # subtract
        # we had to add this to enable np.array_equal to work
        # as it uses subtraction
        #self.assertRaises(ValueError, lambda: q1 - q2)

        # multiply
        self.assertTrue(
            np.array_equal(
                q1 * q2,
                quaternion.cross(quaternion.create(),
                                 quaternion.create_from_x_rotation(0.5))))

        # divide
        self.assertRaises(ValueError, lambda: q1 / q2)

        # or
        self.assertTrue(
            np.array_equal(
                q1 | q2,
                quaternion.dot(quaternion.create(),
                               quaternion.create_from_x_rotation(0.5))))

        # inverse
        self.assertTrue(
            np.array_equal(
                ~q2,
                quaternion.conjugate(quaternion.create_from_x_rotation(0.5))))
Example #2
0
    def test_operators_quaternion(self):
        q1 = Quaternion()
        q2 = Quaternion.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: q1 + q2)

        # subtract
        # we had to add this to enable np.array_equal to work
        # as it uses subtraction
        #self.assertRaises(ValueError, lambda: q1 - q2)

        # multiply
        self.assertTrue(np.array_equal(q1 * q2, quaternion.cross(quaternion.create(), quaternion.create_from_x_rotation(0.5))))

        # divide
        self.assertRaises(ValueError, lambda: q1 / q2)

        # or
        self.assertTrue(np.array_equal(q1 | q2, quaternion.dot(quaternion.create(), quaternion.create_from_x_rotation(0.5))))

        # inverse
        self.assertTrue(np.array_equal(~q2, quaternion.conjugate(quaternion.create_from_x_rotation(0.5))))

        # ==
        self.assertTrue(Quaternion() == Quaternion())
        self.assertFalse(Quaternion() == Quaternion([0., 0., 0., 0.]))

        # !=
        self.assertTrue(Quaternion() != Quaternion([1., 1., 1., 1.]))
        self.assertFalse(Quaternion() != Quaternion())
Example #3
0
 def test_dot_batch(self):
     result = quaternion.dot([
         [1., 0., 0., 0.],
         [0., 1., 0., 0.],
         [.2, .2, 0., 0.]
     ], [
         [0., 1., 0., 0.],
         [0., 1., 0., 0.],
         [2., -.2, 0., 0.]
     ])
     expected = [0., 1., 0.36]
     np.testing.assert_almost_equal(result, expected, decimal=5)
Example #4
0
 def test_dot_batch(self):
     result = quaternion.dot([
         [1., 0., 0., 0.],
         [0., 1., 0., 0.],
         [.2, .2, 0., 0.]
     ], [
         [0., 1., 0., 0.],
         [0., 1., 0., 0.],
         [2., -.2, 0., 0.]
     ])
     expected = [0., 1., 0.36]
     np.testing.assert_almost_equal(result, expected, decimal=5)
Example #5
0
    def test_operators_quaternion(self):
        q1 = Quaternion()
        q2 = Quaternion.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: q1 + q2)

        # subtract
        self.assertRaises(ValueError, lambda: q1 - q2)

        # multiply
        self.assertTrue(np.array_equal(q1 * q2, quaternion.cross(quaternion.create(), quaternion.create_from_x_rotation(0.5))))

        # divide
        self.assertRaises(ValueError, lambda: q1 / q2)

        # or
        self.assertTrue(np.array_equal(q1 | q2, quaternion.dot(quaternion.create(), quaternion.create_from_x_rotation(0.5))))

        # inverse
        self.assertTrue(np.array_equal(~q2, quaternion.conjugate(quaternion.create_from_x_rotation(0.5))))
Example #6
0
 def test_dot_angle(self):
     result = quaternion.dot([.2, .2, 0., 0.], [2., -.2, 0., 0.])
     np.testing.assert_almost_equal(result, 0.36, decimal=5)
Example #7
0
 def test_dot_parallel(self):
     result = quaternion.dot([0., 1., 0., 0.], [0., 1., 0., 0.])
     np.testing.assert_almost_equal(result, 1.0, decimal=5)
Example #8
0
 def test_dot_adjacent(self):
     result = quaternion.dot([1., 0., 0., 0.], [0., 1., 0., 0.])
     np.testing.assert_almost_equal(result, 0.0, decimal=5)
Example #9
0
 def test_dot_angle(self):
     result = quaternion.dot([.2, .2, 0., 0.], [2., -.2, 0., 0.])
     np.testing.assert_almost_equal(result, 0.36, decimal=5)
Example #10
0
 def test_dot_parallel(self):
     result = quaternion.dot([0., 1., 0., 0.], [0., 1., 0., 0.])
     np.testing.assert_almost_equal(result, 1.0, decimal=5)
Example #11
0
 def test_dot_adjacent(self):
     result = quaternion.dot([1., 0., 0., 0.], [0., 1., 0., 0.])
     np.testing.assert_almost_equal(result, 0.0, decimal=5)
Example #12
0
 def test_dot(self):
     q1 = Quaternion.from_x_rotation(np.pi / 2.0)
     q2 = Quaternion.from_y_rotation(np.pi / 2.0)
     self.assertTrue(np.allclose(q1.dot(q2), quaternion.dot(q1, q2)))
Example #13
0
 def test_dot(self):
     q1 = Quaternion.from_x_rotation(np.pi / 2.0)
     q2 = Quaternion.from_y_rotation(np.pi / 2.0)
     self.assertTrue(np.allclose(q1.dot(q2), quaternion.dot(q1, q2)))