summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--NEWS3
-rw-r--r--lib/matrix.rb12
3 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index d493f17967..e31b8085fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Apr 13 12:08:16 2013 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * lib/matrix.rb: Add Vector#cross_product, patch by Luis Ezcurdia
+ [fix GH-276] [rubyspec:81eec89a124]
+
Sat Apr 13 10:20:37 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* struct.c (rb_struct_define_without_accessor, rb_struct_define),
diff --git a/NEWS b/NEWS
index 9032a8509c..885f6c2b79 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,9 @@ with all sufficient information, see the ChangeLog file.
=== Stdlib updates (outstanding ones only)
+* Matrix
+ * Added Vector#cross_product.
+
* Net::SMTP
* Added Net::SMTP#rset to implement the RSET command
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