Пример #1
0
    def test_chain(self):
        s = Matrix44.scale(10, 20, 30)
        t = Matrix44.translate(10, 20, 30)

        c = Matrix44.chain(s, t)
        x = diag((10., 20., 30., 1.))
        x[3, 0] = 10.
        x[3, 1] = 20.
        x[3, 2] = 30.
        self.assertTrue(equal_matrix(c, x))
Пример #2
0
    def test_chain2(self):
        s = Matrix44.scale(10, 20, 30)
        t = Matrix44.translate(10, 20, 30)
        r = Matrix44.axis_rotate(angle=pi / 2, axis=(0., 0., 1.))
        points = ((23., 97., .5), (2., 7., 13.))

        p1 = s.transform_vectors(points)
        p1 = t.transform_vectors(p1)
        p1 = r.transform_vectors(p1)

        c = Matrix44.chain(s, t, r)
        p2 = c.transform_vectors(points)
        self.assertTrue(equal_vectors(p1, p2))
Пример #3
0
 def test_invalid_init(self):
     with self.assertRaises(ValueError):
         Matrix44((0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11),
                  (12, 13, 14, 15, 16))
     with self.assertRaises(ValueError):
         Matrix44(
             (0, 1, 2, 3),
             (4, 5, 6, 7),
             (8, 9, 10, 11),
         )
     with self.assertRaises(ValueError):
         Matrix44(
             [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
     with self.assertRaises(ValueError):
         Matrix44([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
Пример #4
0
 def test_init_4(self):
     matrix = Matrix44((0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11),
                       (12, 13, 14, 15))
     self.assertEqual(matrix.get_row(0), (0.0, 1.0, 2.0, 3.0))
     self.assertEqual(matrix.get_row(1), (4.0, 5.0, 6.0, 7.0))
     self.assertEqual(matrix.get_row(2), (8.0, 9.0, 10.0, 11.0))
     self.assertEqual(matrix.get_row(3), (12.0, 13.0, 14.0, 15.0))
Пример #5
0
 def test_translate(self):
     t = Matrix44.translate(10, 20, 30)
     x = diag((1., 1., 1., 1.))
     x[3, 0] = 10.
     x[3, 1] = 20.
     x[3, 2] = 30.
     self.assertTrue(equal_matrix(t, x))
Пример #6
0
def test_matrix44_to_ocs():
    ocs = OCS(EXTRUSION)
    matrix = Matrix44.ucs(ocs.ux, ocs.uy, ocs.uz)
    assert is_close_points(
        matrix.transform((-9.56460754, 8.44764172, 9.97894327)),
        (9.41378764657076, 13.15481838975576, 0.8689258932616031),
        places=6,
    )
Пример #7
0
 def test_set(self):
     matrix = Matrix44()
     matrix.set((2., 3., 4., 5.), (6., 7., 8., 9.), (10., 11., 12., 13.),
                (14., 15., 16., 17.))
     self.assertEqual(matrix.get_row(0), (2.0, 3.0, 4.0, 5.0))
     self.assertEqual(matrix.get_row(1), (6.0, 7.0, 8.0, 9.0))
     self.assertEqual(matrix.get_row(2), (10.0, 11.0, 12.0, 13.0))
     self.assertEqual(matrix.get_row(3), (14.0, 15.0, 16.0, 17.0))
Пример #8
0
 def test_transpose(self):
     matrix = Matrix44((0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11),
                       (12, 13, 14, 15))
     matrix.transpose()
     self.assertEqual(matrix.get_row(0), (0.0, 4.0, 8.0, 12.0))
     self.assertEqual(matrix.get_row(1), (1.0, 5.0, 9.0, 13.0))
     self.assertEqual(matrix.get_row(2), (2.0, 6.0, 10.0, 14.0))
     self.assertEqual(matrix.get_row(3), (3.0, 7.0, 11.0, 15.0))
Пример #9
0
 def test_z_rotate(self):
     alpha = radians(25)
     t = Matrix44.z_rotate(alpha)
     x = diag((1., 1., 1., 1.))
     x[0, 0] = cos(alpha)
     x[1, 0] = -sin(alpha)
     x[0, 1] = sin(alpha)
     x[1, 1] = cos(alpha)
     self.assertTrue(equal_matrix(t, x))
Пример #10
0
 def test_get_row(self):
     matrix = Matrix44()
     self.assertEqual(matrix.get_row(0), (1.0, 0.0, 0.0, 0.0))
     self.assertEqual(matrix.get_row(1), (0.0, 1.0, 0.0, 0.0))
     self.assertEqual(matrix.get_row(2), (0.0, 0.0, 1.0, 0.0))
     self.assertEqual(matrix.get_row(3), (0.0, 0.0, 0.0, 1.0))
Пример #11
0
 def test_copy(self):
     values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
     m1 = Matrix44(values)
     matrix = m1.copy()
     for v1, m1 in zip(values, matrix):
         self.assertAlmostEqual(v1, m1)
Пример #12
0
 def test_init_0(self):
     matrix = Matrix44()
     self.assertAlmostEqual(matrix[0, 0], 1.)
     self.assertAlmostEqual(matrix[1, 1], 1.)
     self.assertAlmostEqual(matrix[2, 2], 1.)
     self.assertAlmostEqual(matrix[3, 3], 1.)
Пример #13
0
 def test_transform(self):
     t = Matrix44.scale(2., .5, 1.)
     r = t.transform((10., 20., 30.))
     self.assertEqual(r, (20., 10., 30.))
Пример #14
0
 def test_scale(self):
     t = Matrix44.scale(10, 20, 30)
     x = diag((10., 20., 30., 1.))
     self.assertTrue(equal_matrix(t, x))
Пример #15
0
def write(filename, sponge, merge=False):
    dwg = ezdxf.new('R2000')
    transform = Matrix44.chain(Matrix44.z_rotate(math.radians(45)),
                               Matrix44.translate(5, 3, 4))
    sponge.render(dwg.modelspace(), merge=merge, matrix=transform)
    dwg.saveas(filename)
Пример #16
0
 def test_inverse_error(self):
     m = Matrix44([1] * 16)
     self.assertRaises(ZeroDivisionError, m.inverse)
Пример #17
0
def get_matrix(subclass, code):
    values = [tag.value for tag in subclass.find_all(code)]
    if len(values) != 16:
        raise DXFStructureError('Invalid transformation matrix.')
    return Matrix44(values)
Пример #18
0
def diag(values):
    m = Matrix44()
    for i, value in enumerate(values):
        m[i, i] = value
    return m