mantaflow  0.10
A framework for fluid simulation
quaternion.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * MantaFlow fluid solver framework
5  * Copyright 2011 Tobias Pfaff, Nils Thuerey
6  *
7  * This program is free software, distributed under the terms of the
8  * GNU General Public License (GPL)
9  * http://www.gnu.org/licenses
10  *
11  * Basic quaternion class
12  *
13  ******************************************************************************/
14 
15 #ifndef _QUATERNION_H
16 #define _QUATERNION_H
17 
18 #include "vectorbase.h"
19 
20 namespace Manta {
21 
23 class Quaternion {
24 public:
25 
27  Quaternion() : x(0), y(0), z(0), w(0) {}
28 
30  Quaternion(const Quaternion& q) : x(q.x), y(q.y), z(q.z), w(q.w) {}
31 
33  Quaternion(Real _x, Real _y, Real _z, Real _w) : x(_x), y(_y), z(_z), w(_w) {}
34 
36  Quaternion(Vec3 i, Real r) : x(i.x), y(i.y), z(i.z), w(r) {}
37 
39  inline Quaternion& operator= (const Quaternion& q) {
40  x = q.x;
41  y = q.y;
42  z = q.z;
43  w = q.w;
44  return *this;
45  }
46 
48  inline Quaternion& operator*= ( const Real a ) {
49  x *= a;
50  y *= a;
51  z *= a;
52  w *= a;
53  return *this;
54  }
55 
57  inline Quaternion inverse() const {
58  Real mag = 1.0/(x*x+y*y+z*z+w*w);
59  return Quaternion(-x*mag,-y*mag,-z*mag,w*mag);
60  }
61 
63  inline Vec3 imag() { return Vec3(x,y,z); }
64 
65  // imaginary part
66  Real x;
67  Real y;
68  Real z;
69 
70  // real part
71  Real w;
72 };
73 
74 
76 inline Quaternion operator* ( const Quaternion &q1, const Quaternion &q2 ) {
77  return Quaternion ( q2.w * q1.x + q2.x * q1.w + q2.y * q1.z - q2.z * q1.y,
78  q2.w * q1.y + q2.y * q1.w + q2.z * q1.x - q2.x * q1.z,
79  q2.w * q1.z + q2.z * q1.w + q2.x * q1.y - q2.y * q1.x,
80  q2.w * q1.w - q2.x * q1.x - q2.y * q1.y - q2.z * q1.z );
81 }
82 
84 inline Quaternion operator* ( const Quaternion &q, const Real a ) {
85  return Quaternion ( q.x*a, q.y*a, q.z*a, q.w*a);
86 }
87 
88 } // namespace
89 
90 #endif
91 
92 
Definition: commonkernels.h:22
Quaternion & operator=(const Quaternion &q)
Assign operator.
Definition: quaternion.h:39
Vec3 imag()
imaginary part accessor
Definition: quaternion.h:63
Quaternion inverse() const
return inverse quaternion
Definition: quaternion.h:57
Basic inlined vector class.
Definition: vectorbase.h:71
Quaternion(Vec3 i, Real r)
construct a quaternion from imag/real parts
Definition: quaternion.h:36
Very basic quaternion class.
Definition: quaternion.h:23
Quaternion(const Quaternion &q)
copy constructor
Definition: quaternion.h:30
Quaternion(Real _x, Real _y, Real _z, Real _w)
construct a quaternion from members
Definition: quaternion.h:33
Quaternion()
default constructor
Definition: quaternion.h:27
Quaternion & operator*=(const Real a)
Assign multiplication operator.
Definition: quaternion.h:48