59 #define ACG_DUALQUATERNIONT_C 65 #include "DualQuaternionT.hh" 76 template <
typename Scalar>
78 *
this = DualQuaternion::identity();
84 template <
typename Scalar>
93 template <
typename Scalar>
102 template <
typename Scalar>
104 Scalar _Dw, Scalar _Dx, Scalar _Dy, Scalar _Dz){
112 template <
typename Scalar>
121 template <
typename Scalar>
124 dual_ =
Quaternion( 0.0, 0.5 * _translation[0], 0.5 * _translation[1], 0.5 * _translation[2] );
130 template <
typename Scalar>
134 dual_ =
Quaternion( 0.0, 0.5 * _translation[0], 0.5 * _translation[1], 0.5 * _translation[2] );
142 template <
typename Scalar>
145 dual_ =
Quaternion( 0.0, 0.5 * _transformation(0,3), 0.5 * _transformation(1,3), 0.5 * _transformation(2,3) );
153 template <
typename Scalar>
167 template <
typename Scalar>
179 template <
typename Scalar>
187 template <
typename Scalar>
190 double sqrLen0 = real_.sqrnorm();
191 double sqrLenE = 2.0 * (real_ | dual_);
193 if ( sqrLen0 > 0.0 ){
195 double invSqrLen0 = 1.0/sqrLen0;
196 double invSqrLenE = -sqrLenE/(sqrLen0*sqrLen0);
201 conj.dual_ = invSqrLen0 * conj.dual_ + invSqrLenE * conj.
real_;
206 return DualQuaternion::zero();
212 template <
typename Scalar>
215 const double magn = 1.0/real_.norm();
216 const double magnSqr = 1.0/real_.sqrnorm();
223 dual_ -= ((real_| dual_)* magnSqr) * real_;
230 template <
typename Scalar>
232 return (_other.
real_ == real_) && (_other.dual_ == dual_);
238 template <
typename Scalar>
240 return (_other.
real_ != real_) || (_other.dual_ != dual_);
246 template <
typename Scalar>
254 template <
typename Scalar>
256 real_ = real_ + _other.
real_;
257 dual_ = dual_ + _other.dual_;
265 template <
typename Scalar>
273 template <
typename Scalar>
275 real_ -= _other.
real_;
276 dual_ -= _other.dual_;
284 template <
typename Scalar>
292 template <
typename Scalar>
294 dual_ = real_ * _q.dual_ + dual_ * _q.
real_;
303 template <
typename Scalar>
307 q.
real_ = real_ * _scalar;
308 q.dual_ = dual_ * _scalar;
315 template <
typename Scalar>
319 }
else if ( b < 8 ) {
323 std::cerr <<
"Error in Dualquaternion operator[], index b out of range [0...7]" << std::endl;
332 template <
typename Scalar>
template<
typename VectorType>
335 if ( (_weights.size() != _dualQuaternions.size()) || (_weights.size() == 0) ){
336 std::cerr <<
"Cannot interpolate dual quaternions ( weights: " << _weights.size() <<
", DQs: " << _dualQuaternions.size() << std::endl;
344 for (uint i=1; i<_dualQuaternions.size(); i++)
345 if (_weights[pivotID] < _weights[i])
353 for (uint i=0; i<_dualQuaternions.size(); i++){
359 if ( ( currentQ | pivotQ ) < 0.0 )
360 _weights[i] = -_weights[i];
362 res += _dualQuaternions[i] * _weights[i];
373 template <
typename Scalar>
383 Vec3 rv =
Vec3(real_[1], real_[2], real_[3]);
386 Vec3 dv =
Vec3(dual_[1], dual_[2], dual_[3]);
388 Vec3 tempVec = (rv % p) + r * p;
389 p+=2.0*(rv % tempVec);
402 template <
typename Scalar>
412 Vec3 rv =
Vec3(real_[1], real_[2], real_[3]);
414 Vec3 tempVec = (rv % p) + r * p;
415 p+=2.0*(rv % tempVec);
423 template <
typename Scalar>
426 std::cerr <<
"Real Part:" << std::endl;
428 std::cerr <<
"Dual Part:" << std::endl;
static DualQuaternion zero()
zero dual quaternion [ R(0, 0, 0, 0), D(0,0,0,0) ]
DualQuaternion class for representing rigid motions in 3d.
DualQuaternion & operator+=(const DualQuaternion &_other)
addition
DualQuaternionT()
Default constructor ( constructs an identity dual quaternion )
DualQuaternion operator*(const DualQuaternion &_q) const
dualQuaternion * dualQuaternion
Quaternion real_
real and dual quaternion parts
DualQuaternion & operator*=(const DualQuaternion &_q)
dualQuaternion *= dualQuaternion
Vec3 transform_vector(const Vec3 &_point) const
Transform a vector with the dual quaternion.
DualQuaternion & operator-=(const DualQuaternion &_other)
substraction
void identity()
identity rotation
DualQuaternion conjugate() const
conjugate dual quaternion
bool operator==(const DualQuaternion &_other) const
dual quaternion comparison
static DualQuaternion interpolate(VectorType &_weights, const std::vector< DualQuaternion > &_dualQuaternions)
linear interpolation of dual quaternions. Result is normalized afterwards
DualQuaternion invert() const
invert dual quaternion
Namespace providing different geometric functions concerning angles.
bool operator!=(const DualQuaternion &_other) const
dual quaternion comparison
Vec3 transform_point(const Vec3 &_point) const
Transform a point with the dual quaternion.
void printInfo()
print some info about the DQ
DualQuaternion operator-(const DualQuaternion &_other) const
substraction
DualQuaternion operator+(const DualQuaternion &_other) const
addition
static DualQuaternion identity()
identity dual quaternion [ R(1, 0, 0, 0), D(0,0,0,0) ]
Scalar & operator[](const unsigned int &b)
Access as one big vector.
void normalize()
normalize dual quaternion