German Larrain avatar 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"""
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.