method
normalize
ruby latest stable - Class:
Vector
normalize()public
Returns a new vector with the same direction but with norm 1.
v = Vector [5,8,2].normalize # => Vector[0.5184758473652127, 0.8295613557843402, 0.20739033894608505] v.norm => 1.0
# File lib/matrix.rb, line 2054
def normalize
n = magnitude
raise ZeroVectorError, "Zero vectors can not be normalized" if n == 0
self / n
end