From 8b65973f6f2da84b97ce014ffdee8d874e025a0e Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Wed, 20 Feb 2019 17:15:26 -0600 Subject: [PATCH] Added normalized and magnitude to Vector --- lib/math/vector.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) 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