Exemplo n.º 1
0
 def test_to_matrix(self):
     self.assertAlmostEqual(
         RotateAxisAngle(X, 90).to_matrix(), affine_matrix(X, Z, -Y))
     self.assertAlmostEqual(
         RotateAxisAngle(X + Y, 180).to_matrix(), affine_matrix(Y, X, -Z))
     self.assertAlmostEqual(
         RotateAxisAngle(X + Y + Z, 120).to_matrix(),
         affine_matrix(Y, Z, X))
Exemplo n.º 2
0
    def test_homogeneous_multiplication(self):
        # Swap X and Y axes and translate by <2, 3, 4>
        m = affine_matrix(Y, X, Z, [2, 3, 4])

        self.assertEqual(m.homogeneous_mul(Vector(0, 0, 0)), Vector(2, 3, 4))
        self.assertEqual(m.homogeneous_mul(Vector(10, 20, 30)),
                         Vector(22, 13, 34))
Exemplo n.º 3
0
 def test_affine_matrix(self):
     self.assertAlmostEqual(
         affine_matrix(X, Y, Z),
         Matrix(rows=[
             [1, 0, 0, 0],
             [0, 1, 0, 0],
             [0, 0, 1, 0],
             [0, 0, 0, 1],
         ]))
     self.assertAlmostEqual(
         affine_matrix(X, Y, Z, [1, 2, 3]),
         Matrix(rows=[
             [1, 0, 0, 1],
             [0, 1, 0, 2],
             [0, 0, 1, 3],
             [0, 0, 0, 1],
         ]))
Exemplo n.º 4
0
    def test_rotation_matrix(self):
        self.assertAlmostEqual(rotation_matrix(0, 0 * degree),
                               affine_matrix(X, Y, Z))

        self.assertAlmostEqual(rotation_matrix(0, 90 * degree),
                               affine_matrix(X, Z, -Y))
        self.assertAlmostEqual(rotation_matrix(1, 90 * degree),
                               affine_matrix(-Z, Y, X))
        self.assertAlmostEqual(rotation_matrix(2, 90 * degree),
                               affine_matrix(Y, -X, Z))

        self.assertOrthogonal(rotation_matrix(0, 0 * degree))

        rx = rotation_matrix(0, 10 * degree)
        ry = rotation_matrix(1, 10 * degree)
        rz = rotation_matrix(2, 10 * degree)

        self.assertOrthogonal(rx)
        self.assertOrthogonal(ry)
        self.assertOrthogonal(rz)
        self.assertOrthogonal(rx * ry * rz)
        self.assertOrthogonal(rx * rx * rx)
Exemplo n.º 5
0
    def test_to_matrix(self):
        # No rotation
        self.assertAlmostEqual(RotateXyz( 0 , 0,  0).to_matrix(), affine_matrix(X, Y, Z))

        # 90 degrees around a single axis
        self.assertAlmostEqual(RotateXyz(90,  0,  0).to_matrix(), affine_matrix( X,  Z, -Y))
        self.assertAlmostEqual(RotateXyz( 0, 90,  0).to_matrix(), affine_matrix(-Z,  Y,  X))
        self.assertAlmostEqual(RotateXyz( 0,  0, 90).to_matrix(), affine_matrix( Y, -X,  Z))

        # 180 degrees around a single axis
        self.assertAlmostEqual(RotateXyz(180,   0,   0).to_matrix(), affine_matrix( X, -Y, -Z))
        self.assertAlmostEqual(RotateXyz(  0, 180,   0).to_matrix(), affine_matrix(-X,  Y, -Z))
        self.assertAlmostEqual(RotateXyz(  0,   0, 180).to_matrix(), affine_matrix(-X, -Y,  Z))

        # 90 degrees each around two axes
        self.assertAlmostEqual(RotateXyz(90, 90,  0).to_matrix(), affine_matrix(-Z,  X, -Y))
        self.assertAlmostEqual(RotateXyz(90,  0, 90).to_matrix(), affine_matrix( Y,  Z,  X))
        self.assertAlmostEqual(RotateXyz( 0, 90, 90).to_matrix(), affine_matrix(-Z, -X,  Y))

        # 90 degrees each around all three axes
        self.assertAlmostEqual(RotateXyz(90, 90, 90).to_matrix(), affine_matrix(-Z, Y, X))
Exemplo n.º 6
0
 def test_to_matrix(self):
     self.assertAlmostEqual(
         Translate([1, 2, 3]).to_matrix(),
         affine_matrix(X, Y, Z, [1, 2, 3]))
Exemplo n.º 7
0
    def test_to_matrix(self):
        # No rotation
        self.assertAlmostEqual(RotateFromTo(X, X).to_matrix(), affine_matrix(X, Y, Z))

        # One axis onto another
        self.assertAlmostEqual(RotateFromTo(X, Y).to_matrix(), affine_matrix(Y, -X, Z))
        self.assertAlmostEqual(RotateFromTo(Y, Z).to_matrix(), affine_matrix(X, Z, -Y))
        self.assertAlmostEqual(RotateFromTo(Z, X).to_matrix(), affine_matrix(-Z, Y, X))

        # More of the same
        self.assertAlmostEqual(RotateFromTo( X,  Z).to_matrix(), affine_matrix( Z, Y, -X))
        self.assertAlmostEqual(RotateFromTo( X, -Z).to_matrix(), affine_matrix(-Z, Y,  X))
        self.assertAlmostEqual(RotateFromTo(-X,  Z).to_matrix(), affine_matrix(-Z, Y,  X))
        self.assertAlmostEqual(RotateFromTo(-X, -Z).to_matrix(), affine_matrix( Z, Y, -X))

        # Non-unit axis
        self.assertAlmostEqual(RotateFromTo(2*X,   Y).to_matrix(), affine_matrix(Y, -X, Z))
        self.assertAlmostEqual(RotateFromTo(2*X, 2*Y).to_matrix(), affine_matrix(Y, -X, Z))
        self.assertAlmostEqual(RotateFromTo(X-Y, X+Y).to_matrix(), affine_matrix(Y, -X, Z))
Exemplo n.º 8
0
    def test_to_matrix(self):
        # No rotation
        self.assertAlmostEqual(
            RotateYpr(0, 0, 0).to_matrix(), affine_matrix(X, Y, Z))

        # 90 degrees around a single axis
        self.assertAlmostEqual(
            RotateYpr(90, 0, 0).to_matrix(), affine_matrix(Y, -X,
                                                           Z))  # Yaw left
        self.assertAlmostEqual(
            RotateYpr(0, 90, 0).to_matrix(), affine_matrix(X, Z,
                                                           -Y))  # Pitch up
        self.assertAlmostEqual(
            RotateYpr(0, 0, 90).to_matrix(), affine_matrix(-Z, Y,
                                                           X))  # Roll right

        # 180 degrees around a single axis
        self.assertAlmostEqual(
            RotateYpr(180, 0, 0).to_matrix(), affine_matrix(-X, -Y, Z))  # Yaw
        self.assertAlmostEqual(
            RotateYpr(0, 180, 0).to_matrix(), affine_matrix(X, -Y,
                                                            -Z))  # Pitch
        self.assertAlmostEqual(
            RotateYpr(0, 0, 180).to_matrix(), affine_matrix(-X, Y, -Z))  # Roll

        # 90 degrees each around two axes
        self.assertAlmostEqual(
            RotateYpr(90, 90, 0).to_matrix(),
            affine_matrix(Y, Z, X))  # Yaw left, pitch up
        self.assertAlmostEqual(
            RotateYpr(90, 0, 90).to_matrix(),
            affine_matrix(-Z, -X, Y))  # Yaw left, roll right
        self.assertAlmostEqual(
            RotateYpr(0, 90, 90).to_matrix(),
            affine_matrix(Y, Z, X))  # Pitch up, roll right

        # 90 degrees each around all three axes
        self.assertAlmostEqual(
            RotateYpr(90, 90, 90).to_matrix(),
            affine_matrix(-X, Z, Y))  # Yaw left, pitch up, roll right