add Abs() method to vector

This commit is contained in:
phinicota 2018-12-27 12:41:49 -03:00
parent bdd9349b37
commit 1d93d75a61
1 changed files with 5 additions and 0 deletions

View File

@ -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.