51#define ACG_DUALQUATERNIONT_C
57#include "DualQuaternionT.hh"
68 template <
typename Scalar>
70 *
this = DualQuaternion::identity();
76 template <
typename Scalar>
82 template <
typename Scalar>
92 template <
typename Scalar>
101 template <
typename Scalar>
103 Scalar _Dw, Scalar _Dx, Scalar _Dy, Scalar _Dz){
111 template <
typename Scalar>
120 template <
typename Scalar>
123 dual_ =
Quaternion( 0.0, 0.5 * _translation[0], 0.5 * _translation[1], 0.5 * _translation[2] );
129 template <
typename Scalar>
133 dual_ =
Quaternion( 0.0, 0.5 * _translation[0], 0.5 * _translation[1], 0.5 * _translation[2] );
141 template <
typename Scalar>
144 dual_ =
Quaternion( 0.0, 0.5 * _transformation(0,3), 0.5 * _transformation(1,3), 0.5 * _transformation(2,3) );
152 template <
typename Scalar>
166 template <
typename Scalar>
178 template <
typename Scalar>
186 template <
typename Scalar>
189 double sqrLen0 = real_.sqrnorm();
190 double sqrLenE = 2.0 * (real_ | dual_);
192 if ( sqrLen0 > 0.0 ){
194 double invSqrLen0 = 1.0/sqrLen0;
195 double invSqrLenE = -sqrLenE/(sqrLen0*sqrLen0);
200 conj.dual_ = invSqrLen0 * conj.dual_ + invSqrLenE * conj.
real_;
205 return DualQuaternion::zero();
211 template <
typename Scalar>
214 const double magn = 1.0/real_.norm();
215 const double magnSqr = 1.0/real_.sqrnorm();
222 dual_ -= ((real_| dual_)* magnSqr) * real_;
229 template <
typename Scalar>
231 return (_other.
real_ == real_) && (_other.dual_ == dual_);
237 template <
typename Scalar>
239 return (_other.
real_ != real_) || (_other.dual_ != dual_);
245 template <
typename Scalar>
253 template <
typename Scalar>
255 real_ = real_ + _other.
real_;
256 dual_ = dual_ + _other.dual_;
264 template <
typename Scalar>
272 template <
typename Scalar>
274 real_ -= _other.
real_;
275 dual_ -= _other.dual_;
283 template <
typename Scalar>
291 template <
typename Scalar>
293 dual_ = real_ * _q.dual_ + dual_ * _q.
real_;
302 template <
typename Scalar>
306 q.
real_ = real_ * _scalar;
307 q.dual_ = dual_ * _scalar;
314 template <
typename Scalar>
318 }
else if ( b < 8 ) {
322 std::cerr <<
"Error in Dualquaternion operator[], index b out of range [0...7]" << std::endl;
331 template <
typename Scalar>
template<
typename VectorType>
334 if ( (_weights.size() != _dualQuaternions.size()) || (_weights.size() == 0) ){
335 std::cerr <<
"Cannot interpolate dual quaternions ( weights: " << _weights.size() <<
", DQs: " << _dualQuaternions.size() << std::endl;
343 for (uint i=1; i<_dualQuaternions.size(); i++)
344 if (_weights[pivotID] < _weights[i])
352 for (uint i=0; i<_dualQuaternions.size(); i++){
358 if ( ( currentQ | pivotQ ) < 0.0 )
359 _weights[i] = -_weights[i];
361 res += _dualQuaternions[i] * _weights[i];
372 template <
typename Scalar>
382 Vec3 rv =
Vec3(real_[1], real_[2], real_[3]);
385 Vec3 dv =
Vec3(dual_[1], dual_[2], dual_[3]);
387 Vec3 tempVec = (rv % p) + r * p;
388 p+=2.0*(rv % tempVec);
401 template <
typename Scalar>
411 Vec3 rv =
Vec3(real_[1], real_[2], real_[3]);
413 Vec3 tempVec = (rv % p) + r * p;
414 p+=2.0*(rv % tempVec);
422 template <
typename Scalar>
425 std::cerr <<
"Real Part:" << std::endl;
427 std::cerr <<
"Dual Part:" << std::endl;
DualQuaternion class for representing rigid motions in 3d.
DualQuaternion operator*(const DualQuaternion &_q) const
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)
substraction
DualQuaternion invert() const
invert dual quaternion
Vec3 transform_point(const Vec3 &_point) const
Transform a point with the dual quaternion.
Quaternion real_
real and dual quaternion parts
static DualQuaternion identity()
identity dual quaternion [ R(1, 0, 0, 0), D(0,0,0,0) ]
DualQuaternion conjugate() const
conjugate dual quaternion
DualQuaternion operator-(const DualQuaternion &_other) const
substraction
Vec3 transform_vector(const Vec3 &_point) const
Transform a vector with the dual quaternion.
DualQuaternion & operator*=(const DualQuaternion &_q)
dualQuaternion *= dualQuaternion
void normalize()
normalize dual quaternion
void printInfo()
print some info about the DQ
static DualQuaternion zero()
zero dual quaternion [ R(0, 0, 0, 0), D(0,0,0,0) ]
DualQuaternion operator+(const DualQuaternion &_other) const
addition
bool operator!=(const DualQuaternion &_other) const
dual quaternion comparison
DualQuaternion & operator+=(const DualQuaternion &_other)
addition
bool operator==(const DualQuaternion &_other) const
dual quaternion comparison
Scalar & operator[](const unsigned int &b)
Access as one big vector.
DualQuaternionT()
Default constructor ( constructs an identity dual quaternion )
void identity()
identity rotation
Namespace providing different geometric functions concerning angles.