Merge branch 'intolerantape-Vector-Angle-Functions-CPP'

This commit is contained in:
Wojtek Figat
2021-09-23 12:22:56 +02:00
2 changed files with 27 additions and 0 deletions

View File

@@ -614,6 +614,20 @@ public:
/// <param name="v2">The third triangle vertex.</param>
/// <returns>The triangle area.</returns>
static float TriangleArea(const Vector2& v0, const Vector2& v1, const Vector2& v2);
/// <summary>
/// Calculates the angle (in radians) between from and to. This is always the smallest value.
/// </summary>
/// <param name="from">The first vector.</param>
/// <param name="to">The second vector.</param>
/// <returns>The angle (in radians).</returns>
static float Angle(const Vector2& from, const Vector2& to)
{
const float dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0f, 1.0f);
if (Math::Abs(dot) > (1.0f - ZeroTolerance))
return dot > 0.0f ? 0.0f : PI;
return Math::Acos(dot);
}
};
inline Vector2 operator+(float a, const Vector2& b)

View File

@@ -929,6 +929,19 @@ public:
/// <returns>The triangle area.</returns>
static float TriangleArea(const Vector3& v0, const Vector3& v1, const Vector3& v2);
/// <summary>
/// Calculates the angle (in radians) between from and to. This is always the smallest value.
/// </summary>
/// <param name="from">The first vector.</param>
/// <param name="to">The second vector.</param>
/// <returns>The angle (in radians).</returns>
static float Angle(const Vector3& from, const Vector3& to)
{
const float dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0f, 1.0f);
if (Math::Abs(dot) > (1.0f - ZeroTolerance))
return dot > 0.0f ? 0.0f : PI;
return Math::Acos(dot);
}
};
inline Vector3 operator+(float a, const Vector3& b)