aboutsummaryrefslogtreecommitdiffstats
path: root/lib/matrix.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index b1d1a5c2bd..9bda8855ce 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -1519,6 +1519,7 @@ end
#
# Vector functions:
# * #inner_product(v)
+# * #cross_product(v)
# * #collect
# * #magnitude
# * #map
@@ -1758,6 +1759,17 @@ class Vector
end
#
+ # Returns the cross product of this vector whit the other.
+ # Vector[1, 0, 0].cross_product Vector[0, 1, 0] => Vector[0, 0, 1]
+ #
+ def cross_product(v)
+ Vector.Raise ErrDimensionMismatch unless size == v.size && v.size == 3
+ Vector[ v[1]*@elements[2] - v[2]*@elements[1],
+ v[2]*@elements[0] - v[0]*@elements[2],
+ v[0]*@elements[1] - v[1]*@elements[0] ]
+ end
+
+ #
# Like Array#collect.
#
def collect(&block) # :yield: e