소스 검색

Adding angle to for vector2

Christian Wolfgang 5 년 전
부모
커밋
2e6ad0a78f
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  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))
+}