36 #ifndef VIGRA_QUATERNION_HXX
37 #define VIGRA_QUATERNION_HXX
40 #include "numerictraits.hxx"
41 #include "tinyvector.hxx"
43 #include "mathutil.hxx"
60 template<
class ValueType>
83 typedef typename NormTraits<ValueType>::NormType
NormType;
87 Quaternion(ValueType
w = 0, ValueType x = 0, ValueType y = 0, ValueType z = 0)
144 ValueType
w()
const {
return w_; }
147 ValueType &
w() {
return w_; }
163 void setV(ValueType x, ValueType y, ValueType z)
170 ValueType x()
const {
return v_[0]; }
171 ValueType y()
const {
return v_[1]; }
172 ValueType z()
const {
return v_[2]; }
173 ValueType &x() {
return v_[0]; }
174 ValueType &y() {
return v_[1]; }
175 ValueType &z() {
return v_[2]; }
176 void setX(ValueType x) { v_[0] = x; }
177 void setY(ValueType y) { v_[1] = y; }
178 void setZ(ValueType z) { v_[2] = z; }
270 v_ = w_ * other.v_ + other.w_ * v_ +
cross(v_, other.v_);
305 return (w_ == other.w_) && (v_ == other.v_);
312 return (w_ != other.w_) || (v_ != other.v_);
322 template<
class MatrixType>
326 typename NumericTraits<ValueType>::RealPromote s =
338 matrix[0][0] = 1 - (vv[1] + vv[2]);
339 matrix[0][1] = ( xy - wv[2]);
340 matrix[0][2] = ( xz + wv[1]);
342 matrix[1][0] = ( xy + wv[2]);
343 matrix[1][1] = 1 - (vv[0] + vv[2]);
344 matrix[1][2] = ( yz - wv[0]);
346 matrix[2][0] = ( xz - wv[1]);
347 matrix[2][1] = ( yz + wv[0]);
348 matrix[2][2] = 1 - (vv[0] + vv[1]);
354 typename NumericTraits<ValueType>::RealPromote s =
366 matrix(0, 0) = 1 - (vv[1] + vv[2]);
367 matrix(0, 1) = ( xy - wv[2]);
368 matrix(0, 2) = ( xz + wv[1]);
370 matrix(1, 0) = ( xy + wv[2]);
371 matrix(1, 1) = 1 - (vv[0] + vv[2]);
372 matrix(1, 2) = ( yz - wv[0]);
374 matrix(2, 0) = ( xz - wv[1]);
375 matrix(2, 1) = ( yz + wv[0]);
376 matrix(2, 2) = 1 - (vv[0] + vv[1]);
385 struct NormTraits<Quaternion<T> >
387 typedef Quaternion<T> Type;
388 typedef typename NumericTraits<T>::Promote SquaredNormType;
389 typedef typename SquareRootTraits<SquaredNormType>::SquareRootResult NormType;
398 template<
class ValueType>
405 template<
typename Type>
406 inline Quaternion<Type>
414 template<
typename Type>
415 inline Quaternion<Type>
423 template<
typename Type>
424 inline Quaternion<Type>
432 template<
typename Type>
433 inline Quaternion<Type>
441 template<
typename Type>
442 inline Quaternion<Type>
450 template<
typename Type>
451 inline Quaternion<Type>
459 template<
typename Type>
460 inline Quaternion<Type>
468 template<
typename Type>
469 inline Quaternion<Type>
477 template<
typename Type>
478 inline Quaternion<Type>
486 template<
typename Type>
487 inline Quaternion<Type>
495 template<
typename Type>
496 inline Quaternion<Type>
504 template<
typename Type>
505 inline Quaternion<Type>
513 template<
typename Type>
515 typename Quaternion<Type>::SquaredNormType
522 template<
typename Type>
524 typename Quaternion<Type>::NormType
536 template<
class ValueType>
538 ostream & operator<<(ostream & os, vigra::Quaternion<ValueType>
const & q)
540 os << q.w() <<
" " << q.x() <<
" " << q.y() <<
" " << q.z();
544 template<
class ValueType>
548 ValueType w, x, y, z;
549 is >> w >> x >> y >> z;
559 #endif // VIGRA_QUATERNION_HXX
Definition: quaternion.hxx:61
NormType magnitude() const
Definition: tinyvector.hxx:802
bool operator==(Quaternion const &other) const
Definition: quaternion.hxx:303
Quaternion operator-() const
Definition: quaternion.hxx:257
PromoteTraits< V1, V2 >::Promote dot(RGBValue< V1, RIDX1, GIDX1, BIDX1 > const &r1, RGBValue< V2, RIDX2, GIDX2, BIDX2 > const &r2)
dot product
Definition: rgbvalue.hxx:906
FFTWComplex< R > conj(const FFTWComplex< R > &a)
complex conjugate
Definition: fftw3.hxx:1030
PromoteTraits< RGBValue< V1, R, G, B >, RGBValue< V2, R, G, B > >::Promote cross(RGBValue< V1, R, G, B > const &r1, RGBValue< V2, R, G, B > const &r2)
cross product
Definition: rgbvalue.hxx:889
Diff2D operator-(Diff2D const &a, Diff2D const &b)
Definition: diff2d.hxx:711
NormTraits< ValueType >::NormType NormType
Definition: quaternion.hxx:83
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
Quaternion & operator=(ValueType w)
Definition: quaternion.hxx:116
void setV(const Vector &v)
Definition: quaternion.hxx:160
ValueType const & const_reference
Definition: quaternion.hxx:75
void fillRotationMatrix(MatrixType &matrix) const
Definition: quaternion.hxx:323
bool operator!=(Quaternion const &other) const
Definition: quaternion.hxx:310
FFTWComplex< R >::SquaredNormType squaredNorm(const FFTWComplex< R > &a)
squared norm (= squared magnitude)
Definition: fftw3.hxx:1044
Diff2D operator+(Diff2D const &a, Diff2D const &b)
Definition: diff2d.hxx:739
void setW(ValueType w)
Definition: quaternion.hxx:150
static Quaternion createRotation(double angle, const Vector &rotationAxis)
Definition: quaternion.hxx:131
SquaredNormType squaredMagnitude() const
Definition: tinyvector.hxx:810
Quaternion & operator=(Quaternion const &other)
Definition: quaternion.hxx:107
Quaternion & operator-=(Quaternion const &other)
Definition: quaternion.hxx:241
const Vector & v() const
Definition: quaternion.hxx:154
FFTWComplex< R >::NormType norm(const FFTWComplex< R > &a)
norm (= magnitude)
Definition: fftw3.hxx:1037
Quaternion(ValueType w=0, ValueType x=0, ValueType y=0, ValueType z=0)
Definition: quaternion.hxx:87
Vector & v()
Definition: quaternion.hxx:157
Quaternion & operator-=(value_type const &w)
Definition: quaternion.hxx:233
ValueType value_type
Definition: quaternion.hxx:67
SquaredNormType squaredMagnitude() const
Definition: quaternion.hxx:203
Quaternion & operator+=(value_type const &w)
Definition: quaternion.hxx:213
ValueType & w()
Definition: quaternion.hxx:147
NormTraits< ValueType >::SquaredNormType SquaredNormType
Definition: quaternion.hxx:79
value_type operator[](int index) const
Definition: quaternion.hxx:189
ValueType w() const
Definition: quaternion.hxx:144
FFTWComplex< R >::NormType abs(const FFTWComplex< R > &a)
absolute value (= magnitude)
Definition: fftw3.hxx:1002
Quaternion & operator/=(Quaternion const &other)
Definition: quaternion.hxx:286
Quaternion & operator/=(double scale)
Definition: quaternion.hxx:294
void setV(ValueType x, ValueType y, ValueType z)
Definition: quaternion.hxx:163
Quaternion & operator*=(double scale)
Definition: quaternion.hxx:277
Quaternion & operator+=(Quaternion const &other)
Definition: quaternion.hxx:221
Quaternion(ValueType w, const Vector &v)
Definition: quaternion.hxx:95
void init(Iterator i, Iterator end)
Definition: tinyvector.hxx:708
value_type & operator[](int index)
Definition: quaternion.hxx:182
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616
Quaternion operator+() const
Definition: quaternion.hxx:250
NormType magnitude() const
Definition: quaternion.hxx:196
ValueType & reference
Definition: quaternion.hxx:71
Quaternion(const Quaternion &q)
Definition: quaternion.hxx:101
Quaternion & operator*=(Quaternion const &other)
Definition: quaternion.hxx:267