6 #define MHF_PI 3.14159265358979323846 13 #ifndef MATH_HELPER_FUNCTIONS 14 #define MATH_HELPER_FUNCTIONS 21 template<
typename _T>
inline double round(_T x)
30 __int64 xint = (__int64) (x+0.5);
33 double diff = x - (double)xint;
35 return double(xint-1);
39 __int64 xint = (__int64) (x-0.5);
42 double diff = x - (double)xint;
44 return double(xint+1);
52 template<
typename _T>
inline short sign(_T x) {
return ( (x<0) ? -1 : 1 ); }
77 template<
typename _T>
inline _T
atan1(_T in1, _T in2) {
83 return atan(in2/in1)+
MHF_PI;
85 if( (in1>0.0) && (in2<0.0) )
86 return atan(in2/in1)+2.0*
MHF_PI;
92 template<
typename _T>
inline _T
acotan(
const _T in) {
100 template<
typename _T>
inline _T
atan0(
const _T in1,
const _T in2) {
103 return atan(in2/in1);
107 template<
typename _T>
inline _T
pow2(
const _T in) {
115 template<
typename _T>
inline _T
rad2deg(
const _T
a) {
122 template<
typename _T>
struct unary_rad2deg :
public std::unary_function<_T, _T> {
129 template<
typename _T>
inline _T
deg2rad(
const _T
a) {
136 template<
typename _T>
struct unary_deg2rad :
public std::unary_function<_T, _T> {
149 template<
typename _angleT,
typename _encT>
inline _encT
rad2enc(_angleT
const&
angle, _angleT
const& angleOffset, _encT
const& epc, _encT
const& encOffset, _encT
const& rotDir) {
151 _angleT _epc = epc, _rotDir = rotDir, _angleOffset = angleOffset, _encOffset = encOffset;
152 return static_cast<_encT
>( round( _encOffset + (_angleOffset-angle)*_epc*_rotDir/(2*
MHF_PI) ) );
158 template<
typename _angleT,
typename _encT>
inline _angleT
enc2rad(_encT
const&
enc, _angleT
const& angleOffset, _encT
const& epc, _encT
const& encOffset, _encT
const& rotDir) {
160 _angleT _epc = epc, _rotDir = rotDir, _angleOffset = angleOffset, _encOffset = encOffset, _enc =
enc;
161 return _angleOffset - (_enc - _encOffset)*2.0*
MHF_PI/(_epc*_rotDir);
170 v1[0] = acos(cosValue);
172 v2[0] = asin(sinValue);
175 for(
int i=0;i<2;++i) {
176 for(
int j=0;j<2;++j) {
180 throw AnaGuess::Exception(
"precondition for findFirstEqualAngle failed -> no equal angles found", -2);
189 #endif // ifndef MATH_HELPER_FUNCTIONS
_T anglereduce(const _T a)
double findFirstEqualAngle(double cosValue, double sinValue, double tolerance)
_encT rad2enc(_angleT const &angle, _angleT const &angleOffset, _encT const &epc, _encT const &encOffset, _encT const &rotDir)
FloatVector FloatVector * a
_T atan0(const _T in1, const _T in2)
_angleT enc2rad(_encT const &enc, _angleT const &angleOffset, _encT const &epc, _encT const &encOffset, _encT const &rotDir)