[前][次][番号順一覧][スレッド一覧]

ruby-changes:28221

From: marcandre <ko1@a...>
Date: Sat, 13 Apr 2013 12:08:37 +0900 (JST)
Subject: [ruby-changes:28221] marcandRe: r40273 (trunk): * lib/matrix.rb: Add Vector#cross_product, patch by Luis Ezcurdia

marcandre	2013-04-13 12:08:28 +0900 (Sat, 13 Apr 2013)

  New Revision: 40273

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40273

  Log:
    * lib/matrix.rb: Add Vector#cross_product, patch by Luis Ezcurdia
      [fix GH-276] [rubyspec:81eec89a124]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/matrix.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40272)
+++ ChangeLog	(revision 40273)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 13 12:08:16 2013  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* 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@r...>
 
 	* struct.c (rb_struct_define_without_accessor, rb_struct_define),
Index: lib/matrix.rb
===================================================================
--- lib/matrix.rb	(revision 40272)
+++ lib/matrix.rb	(revision 40273)
@@ -1519,6 +1519,7 @@ end https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1519
 #
 # Vector functions:
 # * #inner_product(v)
+# * #cross_product(v)
 # * #collect
 # * #magnitude
 # * #map
@@ -1758,6 +1759,17 @@ class Vector https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1759
   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
Index: NEWS
===================================================================
--- NEWS	(revision 40272)
+++ NEWS	(revision 40273)
@@ -38,6 +38,9 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L38
 
 === Stdlib updates (outstanding ones only)
 
+* Matrix
+  * Added Vector#cross_product.
+
 * Net::SMTP
   * Added Net::SMTP#rset to implement the RSET command
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]