diff --git a/lib/math/vector.rb b/lib/math/vector.rb index eb2d87d..8f2c8ad 100644 --- a/lib/math/vector.rb +++ b/lib/math/vector.rb @@ -65,6 +65,17 @@ class IMICFPS ) end + # returns magnitude of Vector, ignoring #weight + def magnitude + Math.sqrt((@x * @x) + (@y * @y) + (@z * @z)) + end + + def normalized + mag = magnitude + p mag + self / Vector.new(mag, mag, mag) + end + def to_a [@x, @y, @z, @weight] end