Procházet zdrojové kódy

Merge pull request #213 from wolfgarnet/feature/angle-to-vector2

Adding angle to for vector2
Daniel Salvadori před 4 roky
rodič
revize
0653c2ddda
1 změnil soubory, kde provedl 8 přidání a 0 odebrání
  1. 8 0
      math32/vector2.go

+ 8 - 0
math32/vector2.go

@@ -420,3 +420,11 @@ func (v *Vector2) AlmostEquals(other *Vector2, tolerance float32) bool {
 	}
 	return false
 }
+
+// AngleTo returns the angle between this vector and other
+func (v *Vector2) AngleTo(other *Vector2) float32 {
+
+	theta := v.Dot(other) / (v.Length() * other.Length())
+	// clamp, to handle numerical problems
+	return Acos(Clamp(theta, -1, 1))
+}