def test_rot_mat(self): rot = Mat.new_rotation_3d() ident = Mat.new_identity(4) # a rotation matrix with no rotations is just the basis vectors self.assertEqual(rot, ident) vec = Vec(1, 0, 0, 1) self.assertEqual(rot * vec, Vec(1, 0, 0, 1)) rot = Mat.new_rotation_3d(0, -pi/2, 0) self.assertEqual(rot * vec, Vec(0, 0, 1, 1))
def test_print(self): mat = Mat([ [1.234, 9, 39], [3, 165, 0.1], ]) self.assertEqual(str(mat), "| 1.23 9 39 |\n| 3 165 0.10 |") mat = Mat.new_identity(4) self.assertEqual(str(mat), "| 1 0 0 0 |\n| 0 1 0 0 |\n| 0 0 1 0 |\n| 0\ 0 0 1 |") mat[1][1] = 348290482.23984 self.assertEqual(str(mat), "| 1 0 0 \ 0 |\n| 0 348290482.24 0 0 |\n| \ 0 0 1 0 |\n| 0 0\ 0 1 |") # try some fancy character renderings mat = Mat( [pi, pi/2, pi/4], ) self.assertEqual(str(mat.friendly()), "| \xcf\x80 \xcf\x80/2 \xcf\x80/4 |") mat = Mat.new_rotation_3d(radians(45), radians(30), radians(270)) self.assertEqual(str(mat.friendly()), "| 0 cos(\xcf\x80/6) \ sin(\xcf\x80/6) 0 |\n| sin(-\xcf\x80/4) 0.35 -0.61 0 \ |\n| sin(-\xcf\x80/4) -0.35 0.61 0 |\n| 0 0 \ 0 1 |") self.assertEqual(str(mat), "| -0.00 0.87 0.50 0.00 |\n| -0.71 \ 0.35 -0.61 0.00 |\n| -0.71 -0.35 0.61 0.00 |\n| 0.00 0.00 0.00 1.00 |")