51 #define ACG_DUALQUATERNIONT_C 57 #include "DualQuaternionT.hh" 68 template <
typename Scalar>
70 *
this = DualQuaternion::identity();
76 template <
typename Scalar>
85 template <
typename Scalar>
94 template <
typename Scalar>
96 Scalar _Dw, Scalar _Dx, Scalar _Dy, Scalar _Dz){
104 template <
typename Scalar>
113 template <
typename Scalar>
116 dual_ =
Quaternion( 0.0, 0.5 * _translation[0], 0.5 * _translation[1], 0.5 * _translation[2] );
122 template <
typename Scalar>
126 dual_ =
Quaternion( 0.0, 0.5 * _translation[0], 0.5 * _translation[1], 0.5 * _translation[2] );
134 template <
typename Scalar>
137 dual_ =
Quaternion( 0.0, 0.5 * _transformation(0,3), 0.5 * _transformation(1,3), 0.5 * _transformation(2,3) );
145 template <
typename Scalar>
159 template <
typename Scalar>
171 template <
typename Scalar>
179 template <
typename Scalar>
182 double sqrLen0 = real_.sqrnorm();
183 double sqrLenE = 2.0 * (real_ | dual_);
185 if ( sqrLen0 > 0.0 ){
187 double invSqrLen0 = 1.0/sqrLen0;
188 double invSqrLenE = -sqrLenE/(sqrLen0*sqrLen0);
193 conj.dual_ = invSqrLen0 * conj.dual_ + invSqrLenE * conj.
real_;
198 return DualQuaternion::zero();
204 template <
typename Scalar>
207 const double magn = 1.0/real_.norm();
208 const double magnSqr = 1.0/real_.sqrnorm();
215 dual_ -= ((real_| dual_)* magnSqr) * real_;
222 template <
typename Scalar>
224 return (_other.
real_ == real_) && (_other.dual_ == dual_);
230 template <
typename Scalar>
232 return (_other.
real_ != real_) || (_other.dual_ != dual_);
238 template <
typename Scalar>
246 template <
typename Scalar>
248 real_ = real_ + _other.
real_;
249 dual_ = dual_ + _other.dual_;
257 template <
typename Scalar>
265 template <
typename Scalar>
267 real_ -= _other.
real_;
268 dual_ -= _other.dual_;
276 template <
typename Scalar>
284 template <
typename Scalar>
286 dual_ = real_ * _q.dual_ + dual_ * _q.
real_;
295 template <
typename Scalar>
299 q.
real_ = real_ * _scalar;
300 q.dual_ = dual_ * _scalar;
307 template <
typename Scalar>
311 }
else if ( b < 8 ) {
315 std::cerr <<
"Error in Dualquaternion operator[], index b out of range [0...7]" << std::endl;
324 template <
typename Scalar>
template<
typename VectorType>
327 if ( (_weights.size() != _dualQuaternions.size()) || (_weights.size() == 0) ){
328 std::cerr <<
"Cannot interpolate dual quaternions ( weights: " << _weights.size() <<
", DQs: " << _dualQuaternions.size() << std::endl;
336 for (uint i=1; i<_dualQuaternions.size(); i++)
337 if (_weights[pivotID] < _weights[i])
345 for (uint i=0; i<_dualQuaternions.size(); i++){
351 if ( ( currentQ | pivotQ ) < 0.0 )
352 _weights[i] = -_weights[i];
354 res += _dualQuaternions[i] * _weights[i];
365 template <
typename Scalar>
375 Vec3 rv =
Vec3(real_[1], real_[2], real_[3]);
378 Vec3 dv =
Vec3(dual_[1], dual_[2], dual_[3]);
380 Vec3 tempVec = (rv % p) + r * p;
381 p+=2.0*(rv % tempVec);
394 template <
typename Scalar>
404 Vec3 rv =
Vec3(real_[1], real_[2], real_[3]);
406 Vec3 tempVec = (rv % p) + r * p;
407 p+=2.0*(rv % tempVec);
415 template <
typename Scalar>
418 std::cerr <<
"Real Part:" << std::endl;
420 std::cerr <<
"Dual Part:" << std::endl;
Namespace providing different geometric functions concerning angles.
bool operator!=(const DualQuaternion &_other) const
dual quaternion comparison
Quaternion real_
real and dual quaternion parts
void printInfo()
print some info about the DQ
void normalize()
normalize dual quaternion
DualQuaternion & operator-=(const DualQuaternion &_other)
substraction
DualQuaternion operator-(const DualQuaternion &_other) const
substraction
DualQuaternion conjugate() const
conjugate dual quaternion
DualQuaternion invert() const
invert dual quaternion
DualQuaternion operator*(const DualQuaternion &_q) const
dualQuaternion * dualQuaternion
Vec3 transform_vector(const Vec3 &_point) const
Transform a vector with the dual quaternion.
DualQuaternion & operator+=(const DualQuaternion &_other)
addition
DualQuaternion & operator*=(const DualQuaternion &_q)
dualQuaternion *= dualQuaternion
static DualQuaternion interpolate(VectorType &_weights, const std::vector< DualQuaternion > &_dualQuaternions)
linear interpolation of dual quaternions. Result is normalized afterwards
DualQuaternion operator+(const DualQuaternion &_other) const
addition
void identity()
identity rotation
DualQuaternion class for representing rigid motions in 3d.
DualQuaternionT()
Default constructor ( constructs an identity dual quaternion )
bool operator==(const DualQuaternion &_other) const
dual quaternion comparison
static DualQuaternion zero()
zero dual quaternion [ R(0, 0, 0, 0), D(0,0,0,0) ]
static DualQuaternion identity()
identity dual quaternion [ R(1, 0, 0, 0), D(0,0,0,0) ]
Vec3 transform_point(const Vec3 &_point) const
Transform a point with the dual quaternion.
Scalar & operator[](const unsigned int &b)
Access as one big vector.