mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: vectorTools: add cosPhi function
This commit is contained in:
@ -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
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
Reference in New Issue
Block a user