*** empty log message ***

This commit is contained in:
jiri 2020-01-01 09:58:51 +00:00
parent 8529a746df
commit 2cb9b28ee3
2 changed files with 27 additions and 6 deletions

View File

@ -35,10 +35,31 @@ return Quaternion<T>
);
};
//basically the same code as in normquat2rotmat, but avoiding extra storage
template<typename T>
Quaternion<T> Quaternion<T>::rotateby(const Quaternion<T> &rhs, bool rhs_is_normalized)
void Quaternion<T>::rotate(T *to, const T *from) const
{
return rhs * *this * rhs.inverse(); //inefficient reference implementation
to[0] = (2*q[0]*q[0]-1+2*q[1]*q[1]) * from[0] +
2*(q[1]*q[2]+q[0]*q[3]) * from[1] +
2*(q[1]*q[3]-q[0]*q[2]) * from[2];
to[1] = 2*(q[1]*q[2]-q[0]*q[3]) * from[0] +
(2*q[0]*q[0]-1+2*q[2]*q[2]) * from[1] +
2*(q[2]*q[3]+q[0]*q[1]) * from[2];
to[2] = 2*(q[1]*q[3]+q[0]*q[2]) * from[0] +
2*(q[2]*q[3]-q[0]*q[1]) * from[1] +
(2*q[0]*q[0]-1+2*q[3]*q[3]) * from[2];
}
template<typename T>
Quaternion<T> Quaternion<T>::rotateby(const Quaternion<T> &rhs)
{
//return rhs.inverse() * *this * rhs; //inefficient reference implementation
Quaternion<T> r;
r[0]=0;
rhs.rotate(&r[1],&q[1]);
return r;
}

View File

@ -71,8 +71,8 @@ public:
Quaternion& normalize(bool unique_sign=false) {*this /= this->norm(); if(unique_sign && q[0]<0) *this *= (T)-1; return *this;};
Quaternion inverse(void) const {return Quaternion(*this).conjugateme()/this->normsqr();};
const Quaternion operator/(const Quaternion &rhs) const {return *this * rhs.inverse();};
Quaternion rotateby(const Quaternion &rhs, bool rhs_is_normalized=true); //conjugation-rotation of this by rhs
void rotate(T *rhs) const; //rotate xyz vector by *this
Quaternion rotateby(const Quaternion &rhs); //conjugation-rotation of this by NORMALIZED rhs
void rotate(T *to, const T *from) const; //rotate xyz vector by NORMALIZED *this
};
@ -102,7 +102,7 @@ template<typename T>
void normquat2euler(const Quaternion<T> &q, T *);
//the following must be in .h due to the generic M type which is unspecified and can be any type providing [][], either plain C matrix or LA matrix
//the following must be in .h due to the generic M type which is unspecified and can be any type providing [][], either plain C matrix or std::matrix or LA matrix
//conversion between quanternions and rotation matrices
//
@ -165,7 +165,7 @@ if(a[0][1]-a[1][0]<0) q[3] = -q[3];
}
//rotation about unit vector axis through an angle to a normalized quaternion
//rotation about unit vector axis (given by pointer for simplicity) through an angle to a normalized quaternion
#ifndef AVOID_GONIOM_FUNC
template<typename T>
void axis2normquat(const T *axis, const T &angle, Quaternion<T> &q);