Commits

German Larrain committed 1be8b50

utils.mathematical: new 'dot_product' function; changed comments

Comments (0)

Files changed (1)

ars/utils/mathematical.py

 def radians_to_degrees(radians_):
 	return degrees(radians_)
 
-# TODO: mix with the corresponding scalar-argument function
+# TODO: combine with the corresponding scalar-argument function
 def vec3_radians_to_degrees(vector_):
 	result = []
 	for radians_ in vector_:
 def degrees_to_radians(degrees_):
 	return radians(degrees_)
 
-# TODO: mix with the corresponding scalar-argument function
+# TODO: combine with the corresponding scalar-argument function
 def vec3_degrees_to_radians(vector_):
 	result = []
 	for degrees_ in vector_:
 
 def dot_product3(vector1, vector2):
 	"""Returns the dot product of 3-vectors vector1 and vector2"""
-	#TODO: convert it so it can handle vector of any dimension
-	return vector1[0] * vector2[0] + vector1[1] * vector2[1] + vector1[2] * vector2[2]
+	return dot_product(vector1, vector2)
+
+def dot_product(vec1, vec2):
+	"""Efficient dot-product operation between two vectors of the same size.
+	source: http://docs.python.org/library/itertools.html
+
+	"""
+	return sum(itertools.imap(operator.mul, vec1, vec2))
 
 def cross_product(vector1, vector2):
 	"""Returns the cross_product product of 3-vectors vector1 and vector2"""