diff --git a/applications/utilities/mesh/generation/cvMesh/vectorTools/vectorTools.H b/applications/utilities/mesh/generation/cvMesh/vectorTools/vectorTools.H index 91ffae198d8e85b414892322125c3f5b6c08a453..9fb39a159bafbfb8de882cb4b469fbf6e7d14af8 100644 --- a/applications/utilities/mesh/generation/cvMesh/vectorTools/vectorTools.H +++ b/applications/utilities/mesh/generation/cvMesh/vectorTools/vectorTools.H @@ -102,6 +102,21 @@ namespace vectorTools return ((a & b) < 0) ? true : false; } + //- Calculate angle between a and b in radians + template <typename T> + T cosPhi + ( + const Vector<T>& a, + const Vector<T>& b, + const T& tolerance = SMALL + ) + { + scalar cosPhi = (a & b)/(mag(a)*mag(b) + tolerance); + + // Enforce bounding between -1 and 1 + return min(max(cosPhi, -1), 1); + } + //- Calculate angle between a and b in radians template <typename T> T radAngleBetween @@ -111,7 +126,10 @@ namespace vectorTools const T& tolerance = SMALL ) { - return Foam::acos( (a & b)/(mag(a)*mag(b) + tolerance) ); + scalar cosPhi = (a & b)/(mag(a)*mag(b) + tolerance); + + // Enforce bounding between -1 and 1 + return acos( min(max(cosPhi, -1), 1) ); } //- Calculate angle between a and b in degrees @@ -123,8 +141,9 @@ namespace vectorTools const T& tolerance = SMALL ) { - return Foam::radToDeg(radAngleBetween(a, b, tolerance)); + return radToDeg(radAngleBetween(a, b, tolerance)); } + } // End namespace vectorTools // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //