예제 #1
0
    def test_addition_inverse(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)

        assert -a == Quaternion(-1, -2, -3, -4)
        assert a + -b == a - b
        assert a + +b == a + b
예제 #2
0
    def test_multiplication_commutativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = 5
        d = 5.0

        assert a * b == b * a
        assert a * c == c * a
        assert a * d == d * a
예제 #3
0
    def test_addition_commutativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = 5
        d = 5.0

        assert a + b == b + a
        assert a + c == c + a
        assert a + d == d + a
예제 #4
0
    def test_addition_associativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)
        d = 5
        e = 6
        f = 5.0
        g = 6.0

        assert b + (a + c) == (b + a) + c
        assert d + (a + e) == (d + a) + e
        assert f + (a + g) == (f + a) + g
예제 #5
0
    def test_multiplication_associativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)
        d = 5
        e = 6
        f = 5.0
        g = 6.0

        assert b * (a * c) == (b * a) * c
        assert d * (a * e) == (d * a) * e
        assert f * (a * g) == (f * a) * g
예제 #6
0
    def test_multiplication_inverse(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)

        assert all_close(
            Quaternion(1, 1, 1, 1) / a,
            Quaternion(1 / a.qi, 1 / a.qj, 1 / a.qk, 1 / a.qr))
        assert all_close(1 / a,
                         Quaternion(1 / a.qi, 1 / a.qj, 1 / a.qk, 1 / a.qr))
        assert all_close(1.0 / a,
                         Quaternion(1 / a.qi, 1 / a.qj, 1 / a.qk, 1 / a.qr))
        assert all_close(a * (Quaternion(1, 1, 1, 1) / b), a / b)
        assert all_close(a * (1 / b), a / b)
        assert all_close(a * (1.0 / b), a / b)
예제 #7
0
    def test_quaternion_product_associativity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)

        assert b @ (a @ c) == (b @ a) @ c
예제 #8
0
    def test_quaternion_product_inverse(self):
        a = Quaternion(2, 2, 2, 2)
        b = a.inverse()

        assert a @ b == Quaternion()
        assert b @ a == Quaternion()
예제 #9
0
    def test_quaternion_product_neutral_element(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion()

        assert a @ b == a
        assert a @ b == b @ a
예제 #10
0
    def test_distributivity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)

        assert a * (b + c) == a * b + a * c
예제 #11
0
 def test_conjugate(self):
     assert Quaternion(1, 2, 3, 4).t == Quaternion(-1, -2, -3, 4)
예제 #12
0
 def test_properties(self):
     a = Quaternion(1, 2, 3, 4)
     assert a.qi == 1
     assert a.qj == 2
     assert a.qk == 3
     assert a.qr == 4
예제 #13
0
    def test_multiplication_neutral_element(self):
        a = Quaternion(1, 2, 3, 4)

        assert a * Quaternion(1, 1, 1, 1) == a
        assert a * 1 == a
        assert a * 1.0 == a
예제 #14
0
 def test_matrix(self):
     assert Quaternion().matrix == Matrix.identity(4)
예제 #15
0
    def test_quaternion_distributivity(self):
        a = Quaternion(1, 2, 3, 4)
        b = Quaternion(2, 3, 4, 5)
        c = Quaternion(3, 4, 5, 6)

        assert a @ (b + c) == a @ b + a @ c
예제 #16
0
    def test_addition_neutral_element(self):
        a = Quaternion(1, 2, 3, 4)

        assert a + Quaternion(0, 0, 0, 0) == a
        assert a + 0 == a
        assert a + 0.0 == a
예제 #17
0
    def test_slerp(self):
        a = Quaternion(1, 0, 0, 1)
        b = Quaternion(0, 1, 0, 1)

        assert Quaternion.slerp(a, b, 0.0) == a / a.norm()
        assert Quaternion.slerp(a, b, 1.0) == b / b.norm()
예제 #18
0
    def test_transform(self):
        a = Quaternion(0, 0, 0, 1)
        b = Matrix((4, 1), (1, 2, 3, 4))

        assert a.transform(b) == b
예제 #19
0
 def test_norm(self):
     assert Quaternion().norm() == 1
     assert Quaternion(1, 1, 1, 1).norm() == 2
예제 #20
0
 def test_equality(self):
     assert Quaternion() == Quaternion()
     assert Quaternion(1, 2, 3, 4) == Quaternion(1, 2, 3, 4)
예제 #21
0
    def test_quaternion_vectors(self):
        a = Quaternion(0, 0, 0, 1)
        b = Matrix((4, 1), (1, 2, 3, 4))

        assert a @ b @ a.inverse() == Quaternion(1, 2, 3, 4)
예제 #22
0
 def test_instantiation(self):
     Quaternion()
     Quaternion(qi=0, qj=0, qk=0, qr=1, data_type="f")