From 2106aa1990a5b6a81c0883d8732741de51e449cd Mon Sep 17 00:00:00 2001 From: marcandre Date: Sat, 13 Apr 2013 03:08:28 +0000 Subject: * 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 --- ChangeLog | 5 +++++ NEWS | 3 +++ lib/matrix.rb | 12 ++++++++++++ 3 files changed, 20 insertions(+) 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 + + * 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 * 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 @@ -1757,6 +1758,17 @@ class Vector p 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. # -- cgit v1.2.3