cqrlib.h | cqrlib.h | |||
---|---|---|---|---|
skipping to change at line 213 | skipping to change at line 213 | |||
if (angle <= DBL_MIN) { | if (angle <= DBL_MIN) { | |||
return (CPPQR(cos(angle)*std::exp(w),0.,0.,0.)); | return (CPPQR(cos(angle)*std::exp(w),0.,0.,0.)); | |||
} | } | |||
const double rat = std::exp(w)*sin(angle)/angle; | const double rat = std::exp(w)*sin(angle)/angle; | |||
return(CPPQR(cos(angle)*std::exp(w),rat*x,rat*y,rat*z)); | return(CPPQR(cos(angle)*std::exp(w),rat*x,rat*y,rat*z)); | |||
} | } | |||
template <typename powertype> | template <typename powertype> | |||
inline CPPQR pow( const powertype p) const { | inline CPPQR pow( const powertype p) const { | |||
return(((*this).log()*p).exp()); | return (((*this).log()*p).exp()); | |||
} | } | |||
inline CPPQR pow( const int p) const { | inline CPPQR pow( const int p) const { | |||
CPPQR qtemp, qaccum; | CPPQR qtemp, qaccum; | |||
unsigned int ptemp; | unsigned int ptemp; | |||
if ( p == 0 ) return (CPPQR(1.0,0.,0.,0.)); | if ( p == 0 ) return (CPPQR(1.0,0.,0.,0.)); | |||
else if ( p > 0 ) { | else if ( p > 0 ) { | |||
qtemp = *this; | qtemp = *this; | |||
skipping to change at line 312 | skipping to change at line 312 | |||
return( temp ); | return( temp ); | |||
} | } | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR& operator+= ( const CPPQR& q ) | inline CPPQR& operator+= ( const CPPQR& q ) | |||
{ | { | |||
w += q.w; | w += q.w; | |||
x += q.x; | x += q.x; | |||
y += q.y; | y += q.y; | |||
z += q.z; | z += q.z; | |||
return *this; | return (*this); | |||
} | } | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR& operator-= ( const CPPQR& q ) | inline CPPQR& operator-= ( const CPPQR& q ) | |||
{ | { | |||
w -= q.w; | w -= q.w; | |||
x -= q.x; | x -= q.x; | |||
y -= q.y; | y -= q.y; | |||
z -= q.z; | z -= q.z; | |||
return *this; | return (*this); | |||
} | } | |||
/* Subtract -- subtract a quaternion (q2) from a quaternion (q1) */ | /* Subtract -- subtract a quaternion (q2) from a quaternion (q1) */ | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR operator- ( const CPPQR& q ) const | inline CPPQR operator- ( const CPPQR& q ) const | |||
{ | { | |||
CPPQR temp; | CPPQR temp; | |||
temp.w = w - q.w; | temp.w = w - q.w; | |||
temp.x = x - q.x; | temp.x = x - q.x; | |||
temp.y = y - q.y; | temp.y = y - q.y; | |||
skipping to change at line 373 | skipping to change at line 373 | |||
{ | { | |||
CPPQR temp; | CPPQR temp; | |||
temp.w = -z*q.z - y*q.y - x*q.x + w*q.w; | temp.w = -z*q.z - y*q.y - x*q.x + w*q.w; | |||
temp.x = y*q.z - z*q.y + w*q.x + x*q.w; | temp.x = y*q.z - z*q.y + w*q.x + x*q.w; | |||
temp.y = -x*q.z + w*q.y + z*q.x + y*q.w; | temp.y = -x*q.z + w*q.y + z*q.x + y*q.w; | |||
temp.z = w*q.z + x*q.y - y*q.x + z*q.w; | temp.z = w*q.z + x*q.y - y*q.x + z*q.w; | |||
w = temp.w; | w = temp.w; | |||
x = temp.x; | x = temp.x; | |||
y = temp.y; | y = temp.y; | |||
z = temp.z; | z = temp.z; | |||
return *this; | return (*this); | |||
} | } | |||
/* Divide -- Divide a quaternion (q1) by quaternion (q2) */ | /* Divide -- Divide a quaternion (q1) by quaternion (q2) */ | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR operator/ ( const CPPQR& q2 ) const | inline CPPQR operator/ ( const CPPQR& q2 ) const | |||
{ | { | |||
const DistanceType norm2sq = q2.w*q2.w + q2.x*q2.x + q2.y*q2.y + q2.z*q 2.z; | const DistanceType norm2sq = q2.w*q2.w + q2.x*q2.x + q2.y*q2.y + q2.z*q 2.z; | |||
if ( norm2sq == 0.0 ) | if ( norm2sq == 0.0 ) | |||
{ | { | |||
skipping to change at line 417 | skipping to change at line 417 | |||
q.w = z*q2.z + y*q2.y + x*q2.x + w*q2.w; | q.w = z*q2.z + y*q2.y + x*q2.x + w*q2.w; | |||
q.x = -y*q2.z + z*q2.y - w*q2.x + x*q2.w; | q.x = -y*q2.z + z*q2.y - w*q2.x + x*q2.w; | |||
q.y = x*q2.z - w*q2.y - z*q2.x + y*q2.w; | q.y = x*q2.z - w*q2.y - z*q2.x + y*q2.w; | |||
q.z = -w*q2.z - x*q2.y + y*q2.x + z*q2.w; | q.z = -w*q2.z - x*q2.y + y*q2.x + z*q2.w; | |||
w = q.w/norm2sq; | w = q.w/norm2sq; | |||
x = q.x/norm2sq; | x = q.x/norm2sq; | |||
y = q.y/norm2sq; | y = q.y/norm2sq; | |||
z = q.z/norm2sq; | z = q.z/norm2sq; | |||
return *this; | return (*this); | |||
} | } | |||
/* ScalarMultiply -- multiply a quaternion (q) by scalar (s) */ | /* ScalarMultiply -- multiply a quaternion (q) by scalar (s) */ | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR operator* ( const DistanceType& d ) const // multiply by a con stant | inline CPPQR operator* ( const DistanceType& d ) const // multiply by a con stant | |||
{ | { | |||
CPPQR temp; | CPPQR temp; | |||
temp.w = w*d; | temp.w = w*d; | |||
temp.x = x*d; | temp.x = x*d; | |||
temp.y = y*d; | temp.y = y*d; | |||
skipping to change at line 439 | skipping to change at line 439 | |||
return( temp ); | return( temp ); | |||
} | } | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR& operator*= ( const DistanceType& d ) | inline CPPQR& operator*= ( const DistanceType& d ) | |||
{ | { | |||
w *= d; | w *= d; | |||
x *= d; | x *= d; | |||
y *= d; | y *= d; | |||
z *= d; | z *= d; | |||
return *this; | return (*this); | |||
} | } | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR& operator/= ( const DistanceType& d ) | inline CPPQR& operator/= ( const DistanceType& d ) | |||
{ | { | |||
if ( std::abs((double)d) <= DBL_MIN ) { | if ( std::abs((double)d) <= DBL_MIN ) { | |||
w = DBL_MAX; | w = DBL_MAX; | |||
x = DBL_MAX; | x = DBL_MAX; | |||
y = DBL_MAX; | y = DBL_MAX; | |||
z = DBL_MAX; | z = DBL_MAX; | |||
} else { | } else { | |||
w /= d; | w /= d; | |||
x /= d; | x /= d; | |||
y /= d; | y /= d; | |||
z /= d; | z /= d; | |||
} | } | |||
return *this; | return (*this); | |||
} | } | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR operator/ ( const DistanceType& d ) const // divide by a const ant | inline CPPQR operator/ ( const DistanceType& d ) const // divide by a const ant | |||
{ | { | |||
CPPQR temp; | CPPQR temp; | |||
temp.w = w/d; | temp.w = w/d; | |||
temp.x = x/d; | temp.x = x/d; | |||
temp.y = y/d; | temp.y = y/d; | |||
temp.z = z/d; | temp.z = z/d; | |||
skipping to change at line 540 | skipping to change at line 540 | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline CPPQR& operator= ( const CPPQR& q ) | inline CPPQR& operator= ( const CPPQR& q ) | |||
{ | { | |||
if ( this != &q ) | if ( this != &q ) | |||
{ | { | |||
w = q.w; | w = q.w; | |||
x = q.x; | x = q.x; | |||
y = q.y; | y = q.y; | |||
z = q.z; | z = q.z; | |||
} | } | |||
return( *this ); | return (*this); | |||
} | } | |||
/* Equal */ | /* Equal */ | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline bool operator== ( const CPPQR& q ) const | inline bool operator== ( const CPPQR& q ) const | |||
{ | { | |||
return( w==q.w && x==q.x && y==q.y && z==q.z ); | return( w==q.w && x==q.x && y==q.y && z==q.z ); | |||
} | } | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
skipping to change at line 568 | skipping to change at line 568 | |||
{ | { | |||
return( RotateByQuaternion( v ) ); | return( RotateByQuaternion( v ) ); | |||
} | } | |||
/* RotateByQuaternion -- Rotate a vector by a Quaternion, w = qvq* */ | /* RotateByQuaternion -- Rotate a vector by a Quaternion, w = qvq* */ | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
inline void RotateByQuaternion(VectorType &w, const VectorType v ) | inline void RotateByQuaternion(VectorType &w, const VectorType v ) | |||
{ | { | |||
CPPQR vquat( 0.0, v[0], v[1], v[2] ); | CPPQR vquat( 0.0, v[0], v[1], v[2] ); | |||
const CPPQR wquat = (*this)*vquat; | const CPPQR wquat = (*this)*vquat; | |||
const CPPQR qconj = *this.Conjugate( ); | const CPPQR qconj = (*this).Conjugate( ); | |||
vquat = wquat * qconj; | vquat = wquat * qconj; | |||
w[0] = vquat.x; w[1] = vquat.y; w[2] = vquat.z; | w[0] = vquat.x; w[1] = vquat.y; w[2] = vquat.z; | |||
return; | return; | |||
} | } | |||
inline VectorType& RotateByQuaternion(const VectorType v ) | inline VectorType& RotateByQuaternion(const VectorType v ) | |||
{ | { | |||
CPPQR vquat( 0.0, v[0], v[1], v[2] ); | CPPQR vquat( 0.0, v[0], v[1], v[2] ); | |||
const CPPQR wquat = (*this)*vquat; | const CPPQR wquat = (*this)*vquat; | |||
const CPPQR qconj = *this.Conjugate( ); | const CPPQR qconj = (*this).Conjugate( ); | |||
vquat = wquat * qconj; | vquat = wquat * qconj; | |||
return VectorType(vquat.x, vquat.y, vquat.z); | return VectorType(vquat.x, vquat.y, vquat.z); | |||
} | } | |||
/* Axis2Quaternion -- Form the quaternion for a rotation around axis v by angle theta */ | /* Axis2Quaternion -- Form the quaternion for a rotation around axis v by angle theta */ | |||
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++*/ | |||
static inline CPPQR Axis2Quaternion ( const DistanceType& angle, const Vect orType v ) | static inline CPPQR Axis2Quaternion ( const DistanceType& angle, const Vect orType v ) | |||
{ | { | |||
return( Axis2Quaternion( v, angle ) ); | return( Axis2Quaternion( v, angle ) ); | |||
} | } | |||
End of changes. 10 change blocks. | ||||
10 lines changed or deleted | 10 lines changed or added | |||