Commits

German Larrain  committed a221c19

new functions in utilities.mathematical: matrix3_multiply, matrix_as_tuple, matrix_as_3x3_tuples

  • Participants
  • Parent commits 3f5af2d
  • Branches default

Comments (0)

Files changed (1)

File ars/utilities/mathematical.py

 	return np.concatenate( (np.concatenate((rot_matrix, np.zeros((3,1))),1),
 						np.mat([0,0,0,1])) )
 
+def matrix3_multiply(matrix1, matrix2):
+	'''
+	returns the matrix multiplication of matrix1 and matrix2.
+	TODO: check objects are valid, or use exceptions to catch errors raised by numpy
+	'''
+	import numpy as np
+	a1 = np.array(matrix1)
+	a2 = np.array(matrix2)
+	result = np.dot(a1, a2)
+	return matrix_as_3x3_tuples(tuple(result.flatten()))
+
+def matrix_as_tuple(matrix_):
+	'''
+	matrix_: nested tuples, e.g. ((1,0),(1,1),(2,5))
+	TODO: improve a lot
+	'''
+	return gut.nested_iterable_to_tuple(matrix_)
+
+def matrix_as_3x3_tuples(tuple_9):
+	'''
+	TODO: improve a lot
+	'''
+	matrix = None
+	if isinstance(tuple_9, tuple):
+		if len(tuple_9) == 9:
+			matrix = (tuple_9[0:3], tuple_9[3:6], tuple_9[6:9])
+	return matrix
+
 class Transform:
 	def __init__(self, position, rot_matrix):
 		'''