adding AngleTo method to Vec

This commit is contained in:
unknown 2020-06-29 16:35:13 +02:00
parent 335b1b366d
commit 9ffe982efb
1 changed files with 6 additions and 0 deletions

View File

@ -169,6 +169,12 @@ func (u Vec) Normal() Vec {
return Vec{-u.Y, u.X} return Vec{-u.Y, u.X}
} }
// Returns angle between two vectors
func (u Vec) AngleTo(v Vec) {
u, v = u.Unit(), v.Unit()
return math.Acos(u.Dot(v))
}
// Dot returns the dot product of vectors u and v. // Dot returns the dot product of vectors u and v.
func (u Vec) Dot(v Vec) float64 { func (u Vec) Dot(v Vec) float64 {
return u.X*v.X + u.Y*v.Y return u.X*v.X + u.Y*v.Y