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
NormType magnitude() const
Definition: tinyvector.hxx:776
bool operator==(Quaternion const &other) const
Definition: quaternion.hxx:303
Quaternion operator-() const
Definition: quaternion.hxx:257
Quaternion< Type >::NormType abs(Quaternion< Type > const &q)
norm
Definition: quaternion.hxx:525
void cross(const MultiArrayView< 1, T, C1 > &x, const MultiArrayView< 1, T, C2 > &y, MultiArrayView< 1, T, C3 > &r)
Definition: matrix.hxx:1402
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
Quaternion< ValueType > conj(Quaternion< ValueType > const &q)
Create conjugate quaternion.
Definition: quaternion.hxx:399
bool operator!=(Quaternion const &other) const
Definition: quaternion.hxx:310
Definition: array_vector.hxx:903
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:784
Quaternion & operator=(Quaternion const &other)
Definition: quaternion.hxx:107
Quaternion< Type >::SquaredNormType squaredNorm(Quaternion< Type > const &q)
squared norm
Definition: quaternion.hxx:516
Definition: accessor.hxx:43
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< Type > operator*(double t1, const Quaternion< Type > &t2)
Multiplication with a scalar on the left.
Definition: quaternion.hxx:479
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
Quaternion< Type > operator/(double t1, const Quaternion< Type > &t2)
Division of a scalar by a Quaternion.
Definition: quaternion.hxx:506
NormTraits< ValueType >::SquaredNormType SquaredNormType
Definition: quaternion.hxx:79
value_type operator[](int index) const
Definition: quaternion.hxx:189
NormTraits< T >::SquaredNormType dot(const MultiArrayView< 2, T, C1 > &x, const MultiArrayView< 2, T, C2 > &y)
Definition: matrix.hxx:1340
ValueType w() const
Definition: quaternion.hxx:144
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:699
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