mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
4123b0d9db
commit
2106aa1990
3 changed files with 20 additions and 0 deletions
|
@ -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),
|
||||
|
|
3
NEWS
3
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
|
||||
|
||||
|
|
|
@ -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.
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue