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_; }
154 const Vector &
v()
const {
return v_; }
157 Vector &
v() {
return v_; }
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; }
269 value_type newW = w_*other.w_ -
dot(v_, other.v_);
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> >
389 typedef typename SquareRootTraits<SquaredNormType>::SquareRootResult
NormType;
398 template<
class ValueType>
405 template<
typename Type>
414 template<
typename Type>
423 template<
typename Type>
432 template<
typename Type>
441 template<
typename Type>
450 template<
typename Type>
459 template<
typename Type>
468 template<
typename Type>
477 template<
typename Type>
486 template<
typename Type>
495 template<
typename Type>
504 template<
typename Type>
513 template<
typename Type>
522 template<
typename Type>
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
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
NormTraits< ValueType >::NormType NormType
Definition: quaternion.hxx:83
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
SquaredNormType squaredMagnitude() const
Definition: tinyvector.hxx:810
NormType magnitude() const
Definition: tinyvector.hxx:802
Definition: matrix.hxx:121
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
Definition: array_vector.hxx:954
FFTWComplex< R >::SquaredNormType squaredNorm(const FFTWComplex< R > &a)
squared norm (= squared magnitude)
Definition: fftw3.hxx:1044
void setW(ValueType w)
Definition: quaternion.hxx:150
Quaternion operator+() const
Definition: quaternion.hxx:250
void fillRotationMatrix(MatrixType &matrix) const
Definition: quaternion.hxx:323
static Quaternion createRotation(double angle, const Vector &rotationAxis)
Definition: quaternion.hxx:131
bool operator!=(Quaternion const &other) const
Definition: quaternion.hxx:310
Quaternion & operator=(Quaternion const &other)
Definition: quaternion.hxx:107
Definition: accessor.hxx:43
Quaternion & operator-=(Quaternion const &other)
Definition: quaternion.hxx:241
NormType magnitude() const
Definition: quaternion.hxx:196
FFTWComplex< R >::NormType norm(const FFTWComplex< R > &a)
norm (= magnitude)
Definition: fftw3.hxx:1037
bool operator==(Quaternion const &other) const
Definition: quaternion.hxx:303
Quaternion operator-() const
Definition: quaternion.hxx:257
Quaternion(ValueType w=0, ValueType x=0, ValueType y=0, ValueType z=0)
Definition: quaternion.hxx:87
Vector & v()
Definition: quaternion.hxx:157
const Vector & v() const
Definition: quaternion.hxx:154
Quaternion & operator-=(value_type const &w)
Definition: quaternion.hxx:233
ValueType value_type
Definition: quaternion.hxx:67
ValueType w() const
Definition: quaternion.hxx:144
Quaternion & operator+=(value_type const &w)
Definition: quaternion.hxx:213
ValueType & w()
Definition: quaternion.hxx:147
NormTraits< ValueType >::SquaredNormType SquaredNormType
Definition: quaternion.hxx:79
SquaredNormType squaredMagnitude() const
Definition: quaternion.hxx:203
FFTWComplex< R >::NormType abs(const FFTWComplex< R > &a)
absolute value (= magnitude)
Definition: fftw3.hxx:1002
value_type operator[](int index) const
Definition: quaternion.hxx:189
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
ValueType & reference
Definition: quaternion.hxx:71
Quaternion(const Quaternion &q)
Definition: quaternion.hxx:101
Quaternion & operator*=(Quaternion const &other)
Definition: quaternion.hxx:267