From f25dae2da2d0afac31c98387d70c06974cfad33e Mon Sep 17 00:00:00 2001 From: intolerantape Date: Thu, 30 Sep 2021 12:24:30 -0700 Subject: [PATCH] Added Double3::Angle --- Source/Engine/Core/Math/Double3.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Core/Math/Double3.h b/Source/Engine/Core/Math/Double3.h index 177bbcc5e..356c2ee26 100644 --- a/Source/Engine/Core/Math/Double3.h +++ b/Source/Engine/Core/Math/Double3.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once @@ -934,6 +934,19 @@ public: /// The triangle area. static double TriangleArea(const Double3& v0, const Double3& v1, const Double3& v2); + /// + /// Calculates the angle (in radians) between from and to. This is always the smallest value. + /// + /// The first vector. + /// The second vector. + /// The angle (in radians). + static double Angle(const Double3& from, const Double3& to) + { + const double dot = Math::Clamp(Dot(Normalize(from), Normalize(to)), -1.0, 1.0); + if (Math::Abs(dot) > (1.0 - ZeroTolerance)) + return dot > 0.0 ? 0.0 : PI; + return Math::Acos(dot); + } }; inline Double3 operator+(double a, const Double3& b)