mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/matrix.rb: Fix sign for cross_product [#9499]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9412551ee2
commit
72d0536606
3 changed files with 12 additions and 3 deletions
|
@ -1,3 +1,7 @@
|
|||
Fri Jul 11 14:19:14 2014 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* lib/matrix.rb: Fix sign for cross_product [#9499]
|
||||
|
||||
Fri Jul 11 11:11:50 2014 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* benchmark/prepare_so_k_nucleotide.rb: use require_relative.
|
||||
|
|
|
@ -1811,9 +1811,9 @@ class Vector
|
|||
#
|
||||
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] ]
|
||||
Vector[ v[2]*@elements[1] - v[1]*@elements[2],
|
||||
v[0]*@elements[2] - v[2]*@elements[0],
|
||||
v[1]*@elements[0] - v[0]*@elements[1] ]
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -146,4 +146,9 @@ class TestVector < Test::Unit::TestCase
|
|||
v = Vector[Rational(1,2), 0]
|
||||
assert_equal(0.5, v.norm)
|
||||
end
|
||||
|
||||
def test_cross_product
|
||||
v = Vector[1, 0, 0].cross_product Vector[0, 1, 0]
|
||||
assert_equal(Vector[0, 0, 1], v)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue