summaryrefslogtreecommitdiff
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-13 03:08:28 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-13 03:08:28 +0000
commit2106aa1990a5b6a81c0883d8732741de51e449cd (patch)
tree54dd4f5ed7107783beb020cbdedcee500e0c2d2f /lib/matrix.rb
parent4123b0d9db2353b629ad6be14bb884ecf5408524 (diff)
* lib/matrix.rb: Add Vector#cross_product, patch by Luis Ezcurdia
[fix GH-276] [rubyspec:81eec89a124] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40273 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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 b1d1a5c..9bda885 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