Commits

German Larrain committed 1752576

utils.geometry.Transform: changed inner workings but interface is the same.

Comments (0)

Files changed (1)

ars/utils/geometry.py

 
 	"""
 
-	def __init__(self, position, rot_matrix):
+	def __init__(self, position=None, rot_matrix=None):
 		"""Constructor.
 
-		:param position: a 3-tuple
-		:param rot_matrix: a 9-tuple
+		With empty arguments it's just a 4x4 identity matrix.
+
+		:param position: a size 3 vector, or 3x1 or 1x3 matrix
+		:type position: tuple, :class:`np.array` or None
+		:param rot_matrix: a 3x3 or 9x1 matrix
+		:type rot_matrix: tuple, :class:`np.array` or None
 
 		"""
-		if not rot_matrix:
-			rot_matrix = []
-			rot_matrix[0:3] = (1,0,0)
-			rot_matrix[3:6] = (0,1,0)
-			rot_matrix[6:9] = (0,0,1)
-			rot_matrix = tuple(rot_matrix)
+		if position is None:
+			position = (0, 0, 0)
+		position = np.array(position)
 
-		row1 = rot_matrix[0:3] + (position[0],)
-		row2 = rot_matrix[3:6] + (position[1],)
-		row3 = rot_matrix[6:9] + (position[2],)
-		row4 = (0,0,0,1)
-		self.matrix = (row1,row2,row3,row4)
+		if position.shape != (3, 1):
+			position = position.reshape((3, 1))
+
+		if rot_matrix is None:
+			rot_matrix = np.identity(3)
+		else:
+			rot_matrix = np.array(rot_matrix)
+
+		if rot_matrix.shape != (3, 3):
+			rot_matrix = rot_matrix.reshape((3, 3))
+
+		temp = np.hstack((rot_matrix, position))
+		self._matrix = np.vstack((temp, np.array([0, 0, 0, 1])))
+
 
 	def __str__(self):
-		return str(self.matrix)
+		return str(self._matrix)
 
 	def get_long_tuple(self):
-		return gut.nested_iterable_to_tuple(self.matrix)
+		return tuple(self._matrix.flatten())
 
 	def get_position(self):
 		raise NotImplementedError()