36#ifndef VIGRA_QUATERNION_HXX
37#define VIGRA_QUATERNION_HXX
40#include "numerictraits.hxx"
41#include "tinyvector.hxx"
43#include "mathutil.hxx"
60template<
class ValueType>
83 typedef typename NormTraits<ValueType>::NormType
NormType;
87 Quaternion(ValueType
w = 0, ValueType x = 0, ValueType y = 0, ValueType z = 0)
137 double t = VIGRA_CSTD::sin(
angle/2.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 =
354 typename NumericTraits<ValueType>::RealPromote s =
385struct NormTraits<Quaternion<T> >
387 typedef Quaternion<T> Type;
388 typedef typename NumericTraits<T>::Promote SquaredNormType;
389 typedef typename SquareRootTraits<SquaredNormType>::SquareRootResult NormType;
398template<
class ValueType>
405template<
typename Type>
406inline Quaternion<Type>
414template<
typename Type>
415inline Quaternion<Type>
423template<
typename Type>
424inline Quaternion<Type>
432template<
typename Type>
433inline Quaternion<Type>
441template<
typename Type>
442inline Quaternion<Type>
450template<
typename Type>
451inline Quaternion<Type>
459template<
typename Type>
460inline Quaternion<Type>
468template<
typename Type>
469inline Quaternion<Type>
477template<
typename Type>
478inline Quaternion<Type>
486template<
typename Type>
487inline Quaternion<Type>
495template<
typename Type>
496inline Quaternion<Type>
504template<
typename Type>
505inline Quaternion<Type>
513template<
typename Type>
522template<
typename Type>
536template<
class ValueType>
540 os << q.w() <<
" " << q.x() <<
" " << q.y() <<
" " << q.z();
544template<
class ValueType>
548 ValueType w, x, y, z;
549 is >> w >> x >> y >> z;
Definition quaternion.hxx:61
Vector & v()
Definition quaternion.hxx:157
bool operator!=(Quaternion const &other) const
Definition quaternion.hxx:310
NormType magnitude() const
Definition quaternion.hxx:196
value_type operator[](int index) const
Definition quaternion.hxx:189
void setW(ValueType w)
Definition quaternion.hxx:150
static Quaternion createRotation(double angle, const Vector &rotationAxis)
Definition quaternion.hxx:131
const Vector & v() const
Definition quaternion.hxx:154
Quaternion & operator*=(Quaternion const &other)
Definition quaternion.hxx:267
Quaternion operator-() const
Definition quaternion.hxx:257
value_type & operator[](int index)
Definition quaternion.hxx:182
ValueType const & const_reference
Definition quaternion.hxx:75
Quaternion & operator+=(Quaternion const &other)
Definition quaternion.hxx:221
Quaternion & operator/=(Quaternion const &other)
Definition quaternion.hxx:286
bool operator==(Quaternion const &other) const
Definition quaternion.hxx:303
ValueType & w()
Definition quaternion.hxx:147
void setV(const Vector &v)
Definition quaternion.hxx:160
Quaternion(ValueType w, const Vector &v)
Definition quaternion.hxx:95
NormTraits< ValueType >::SquaredNormType SquaredNormType
Definition quaternion.hxx:79
ValueType value_type
Definition quaternion.hxx:67
ValueType w() const
Definition quaternion.hxx:144
Quaternion(ValueType w=0, ValueType x=0, ValueType y=0, ValueType z=0)
Definition quaternion.hxx:87
Quaternion & operator-=(Quaternion const &other)
Definition quaternion.hxx:241
Quaternion & operator+=(value_type const &w)
Definition quaternion.hxx:213
Quaternion & operator=(ValueType w)
Definition quaternion.hxx:116
Quaternion & operator*=(double scale)
Definition quaternion.hxx:277
void setV(ValueType x, ValueType y, ValueType z)
Definition quaternion.hxx:163
Quaternion(const Quaternion &q)
Definition quaternion.hxx:101
NormTraits< ValueType >::NormType NormType
Definition quaternion.hxx:83
void fillRotationMatrix(MatrixType &matrix) const
Definition quaternion.hxx:323
ValueType & reference
Definition quaternion.hxx:71
Quaternion & operator/=(double scale)
Definition quaternion.hxx:294
SquaredNormType squaredMagnitude() const
Definition quaternion.hxx:203
Quaternion & operator-=(value_type const &w)
Definition quaternion.hxx:233
Quaternion & operator=(Quaternion const &other)
Definition quaternion.hxx:107
Quaternion operator+() const
Definition quaternion.hxx:250
Class for a single RGB value.
Definition rgbvalue.hxx:128
NormType magnitude() const
Definition rgbvalue.hxx:307
SquaredNormType squaredMagnitude() const
Definition rgbvalue.hxx:313
void init(Iterator i, Iterator end)
Definition tinyvector.hxx:708
SquaredNormType squaredMagnitude() const
Definition tinyvector.hxx:810
Diff2D operator+(Diff2D const &a, Diff2D const &b)
Definition diff2d.hxx:725
FFTWComplex< R >::NormType norm(const FFTWComplex< R > &a)
norm (= magnitude)
Definition fftw3.hxx:1037
FFTWComplex< R > conj(const FFTWComplex< R > &a)
complex conjugate
Definition fftw3.hxx:1030
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:697