ENH: vectorTools: add cosPhi function

This commit is contained in:
laurence
2012-02-07 12:04:20 +00:00
parent ec2b286b72
commit 8e8ff31458

View File

@ -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
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //