From 1d93d75a61e04c0a1d2ff745a81212070b5d8f87 Mon Sep 17 00:00:00 2001 From: phinicota Date: Thu, 27 Dec 2018 12:41:49 -0300 Subject: [PATCH] add Abs() method to vector --- geometry.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/geometry.go b/geometry.go index 5f16ba4..8f32d87 100644 --- a/geometry.go +++ b/geometry.go @@ -164,6 +164,11 @@ func (u Vec) Map(f func(float64) float64) Vec { } } +// Abs returns the absolute value (also called the modulus) of vector u. +func (u Vec) Abs() float64 { + return math.Sqrt(math.Pow(u.X, 2) + math.Pow(u.Y, 2)) +} + // Lerp returns a linear interpolation between vectors a and b. // // This function basically returns a point along the line between a and b and t chooses which one.