コード例 #1
0
ファイル: TestVector.py プロジェクト: Plan-V/python-demoscene
 def test_matrix(self):
     """basic matrix functions"""
     result = Utils3d.get_identity_matrix()
     identity = Utils3d.get_identity_matrix()
     result *= 2
     print "__imul__(2):\n", result
     result /= 2
     print "__idiv__(2):\n", result 
     result += identity
     print "__iadd__(eye):\n", result
     print "__mul__(2):\n", result * 2
     print "__div__(2):\n", result / 2
     print "__add__(eye):\n", result + identity
コード例 #2
0
 def test_matrix(self):
     """basic matrix functions"""
     result = Utils3d.get_identity_matrix()
     identity = Utils3d.get_identity_matrix()
     result *= 2
     print("__imul__(2):\n", result)
     result /= 2
     print("__idiv__(2):\n", result) 
     result += identity
     print("__iadd__(eye):\n", result)
     print("__mul__(2):\n", result * 2)
     print("__div__(2):\n", result / 2)
     print("__add__(eye):\n", result + identity)
コード例 #3
0
 def test_determinant(self):
     identity = Utils3d.get_identity_matrix()
     det = identity.determinant()
     #print "Determinant of Identity Matrix: ", det
     self.assertEqual(det, 1.0)
     matrix = Matrix3d.from_row_vectors(Vector.from_tuple(1, 0, 0),
                                        Vector.from_tuple(0, 2, 0),
                                        Vector.from_tuple(0, 0, 3))
     det = matrix.determinant()
     #print "Determinant of test matrix: ", det
     self.assertEqual(det, 6.0)
     inv = matrix.inverse()
コード例 #4
0
ファイル: TestVector.py プロジェクト: Plan-V/python-demoscene
 def test_determinant(self):
     identity = Utils3d.get_identity_matrix()
     det = identity.determinant()
     #print "Determinant of Identity Matrix: ", det
     self.assertEqual(det, 1.0)
     matrix = Matrix3d.from_row_vectors(
         Vector.from_tuple(1, 0, 0),
         Vector.from_tuple(0, 2, 0),
         Vector.from_tuple(0, 0, 3))
     det = matrix.determinant()
     #print "Determinant of test matrix: ", det
     self.assertEqual(det, 6.0)
     inv = matrix.inverse()
コード例 #5
0
 def test_change_of_basis(self):
     vector = Vector.from_tuple(16, 9, 0)
     identiy = Utils3d.get_identity_matrix()
     rot_z = Utils3d.get_rot_z_matrix(1)
     y_ratio = 16.0 / 9.0
     alt_basis = Matrix3d.from_row_vectors(Vector.from_tuple(1, 0, 0),
                                           Vector.from_tuple(0, y_ratio, 0),
                                           Vector.from_tuple(0, 0, 1))
     alt_basis_inv = alt_basis.inverse()
     # these two vectors should be the same
     #print "v = ", vector
     result_1 = alt_basis_inv.mul_vec(vector)
     #print "v1 = C⁻¹(v): ", result_1
     result_2 = alt_basis.mul_vec(result_1)
     #print "v = C(v1)): ", result_2
     self.assertEqual(vector, result_2)
コード例 #6
0
ファイル: TestVector.py プロジェクト: Plan-V/python-demoscene
 def test_rotation(self):
     """test rotation transformation"""
     # original vector point to 0 degree in X-Y coordinates
     vector = Vector.from_tuple(1, 0, 0)
     # print "Original Vector.from_tuple", vector
     identity = Utils3d.get_identity_matrix()
     # should rotate about math.pi = 180 degrees on X-Y Plane counter-clockwise
     # so we need Rotation Matrix around Z-axis
     rot_x = Utils3d.get_rot_z_matrix(math.pi)
     # print "Rotation matrix: \n", rot_x
     t = rot_x.mul_vec(vector)
     # print "Rotated vector: ", t
     self.assertEqual(t.length(), 1)
     # this is maybe not exactly equal
     self.assertTrue(-1.0-1e10 < t[0] < -1+1e10)
     self.assertTrue(0.0-1e10 < t[1] < 0+1e10)
     self.assertTrue(0.0-1e10 < t[2] < 0+1e10)
コード例 #7
0
ファイル: TestVector.py プロジェクト: Plan-V/python-demoscene
 def test_change_of_basis(self):
     vector = Vector.from_tuple(16, 9, 0)
     identiy = Utils3d.get_identity_matrix()
     rot_z = Utils3d.get_rot_z_matrix(1)
     y_ratio = 16.0/9.0
     alt_basis = Matrix3d.from_row_vectors(
         Vector.from_tuple(1, 0, 0),
         Vector.from_tuple(0, y_ratio, 0),
         Vector.from_tuple(0, 0, 1))
     alt_basis_inv = alt_basis.inverse()
     # these two vectors should be the same
     #print "v = ", vector
     result_1 = alt_basis_inv.mul_vec(vector)
     #print "v1 = C⁻¹(v): ", result_1
     result_2 = alt_basis.mul_vec(result_1)
     #print "v = C(v1)): ", result_2
     self.assertEqual(vector, result_2)
コード例 #8
0
 def test_rotation(self):
     """test rotation transformation"""
     # original vector point to 0 degree in X-Y coordinates
     vector = Vector.from_tuple(1, 0, 0)
     # print "Original Vector.from_tuple", vector
     identity = Utils3d.get_identity_matrix()
     # should rotate about math.pi = 180 degrees on X-Y Plane counter-clockwise
     # so we need Rotation Matrix around Z-axis
     rot_x = Utils3d.get_rot_z_matrix(math.pi)
     # print "Rotation matrix: \n", rot_x
     t = rot_x.mul_vec(vector)
     # print "Rotated vector: ", t
     self.assertEqual(t.length(), 1)
     # this is maybe not exactly equal
     self.assertTrue(-1.0-1e10 < t[0] < -1+1e10)
     self.assertTrue(0.0-1e10 < t[1] < 0+1e10)
     self.assertTrue(0.0-1e10 < t[2] < 0+1e10)