Feature #10442 » angle_with.patch
lib/matrix.rb | ||
---|---|---|
self / n
|
||
end
|
||
#
|
||
# Returns an angle with another vector. Result is within the [0...Math::PI].
|
||
# Vector[1,0].angle_with(Vector[0,1])
|
||
# # => 1.5707963267948966
|
||
#
|
||
def angle_with(v)
|
||
raise TypeError, "Expected a Vector, got a #{v.class}" unless v.is_a?(Vector)
|
||
Vector.Raise ErrDimensionMismatch if size != v.size
|
||
raise ZeroVectorError, "Can't get angle of zero vector" if magnitude == 0 || v.magnitude == 0
|
||
Math.acos( inner_product(v) / (magnitude * v.magnitude) )
|
||
end
|
||
#--
|
||
# CONVERTING
|
||
#++
|
test/matrix/test_vector.rb | ||
---|---|---|
v = Vector[1, 0, 0].cross_product Vector[0, 1, 0]
|
||
assert_equal(Vector[0, 0, 1], v)
|
||
end
|
||
def test_angle_with
|
||
assert_in_epsilon(1.5707963267948966, Vector[1, 0].angle_with(Vector[0, 1]))
|
||
end
|
||
end
|