]> Creatis software - FrontAlgorithms.git/blob - appli/TempAirwaysAppli/MathLib/Quaternion.h
On my way... it does not work yet, but I think I'm on the good track.
[FrontAlgorithms.git] / appli / TempAirwaysAppli / MathLib / Quaternion.h
1 /**
2  * Class that represents a Quaternion
3  * Author: Alfredo Morales Pinzón
4  * Date: October 7, 2014
5  */
6
7 #ifndef __Quaternion_h__
8 #define __Quaternion_h__
9
10 //-----------------
11 // C++
12 //-----------------
13 #include <math.h>
14
15 //-----------------
16 // OWN
17 //-----------------
18 #include <appli/TempAirwaysAppli/MathLib/MathLib_Export.h>
19 #include "vec3.h"
20
21 // Namespaces
22 using namespace std;
23
24 //------------------------------------------------------------------------------
25 // Class that represents a Quaterion with all its operations
26 //------------------------------------------------------------------------------
27 class MathLib_EXPORT Quaternion
28 {
29 public:
30
31         //------------------------------------------------------------
32         //Builder
33         //------------------------------------------------------------
34
35         /*
36          * Class builder
37          */
38         Quaternion( );
39
40         /*
41          * Class builder using two vectors
42          * @param v1 is the first vector
43          * @param v2 is the second vector
44          */
45         Quaternion(Vec3 v1, Vec3 v2);
46
47         /*
48          * Class builder using theta and w vector
49          * @param nTheta is the theta angle
50          * @param nW is the w vector
51          */
52         Quaternion(float nTheta, Vec3 nW);
53
54         /*
55          * Class builder using r and im
56          * @param nR in the real part of the quaternion
57          * @param nI, nJ and nK are the imaginary parts of the quaternion
58          */
59         Quaternion(float nR, float nI, float nJ, float nK);
60
61         //------------------------------------------------------------
62         //Destructor
63         //------------------------------------------------------------
64
65         ~Quaternion();
66
67         //------------------------------------------------------------
68         //Public methods
69         //------------------------------------------------------------
70
71         /**
72          * Method that returns the real (r) component
73          * @return the r component
74          */
75         float getR();
76
77         /**
78          * Method that returns the i component
79          * @return the i component
80          */
81         float getI();
82
83         /**
84          * Method that returns the j component
85          * @return the j component
86          */
87         float getJ();
88
89         /**
90          * Method that returns the k component
91          * @return the k component
92          */
93         float getK();
94
95         /**
96          * Method that returns the w vector
97          * @return the w vector
98          */
99         Vec3 getW();
100
101         /**
102          * Method that returns the conjugate of the quaternion
103          * @return the conjugate of the quaternion
104          */
105         Quaternion conjugate( );
106
107         /**
108          * Method that returns a vector transformed by the quaternion
109          * @param vector to be rotated
110          * @return the transformed vector
111          */
112         Vec3 rotateVector(Vec3 vector);
113
114         //------------------------------------------------------------
115         //Operators
116         //------------------------------------------------------------
117
118         /*
119          * Definition of operator *
120          * @param is the quaternion to be multiplied with
121          * @return the multiplication quaternion
122          */
123         Quaternion operator*(Quaternion q);
124
125         /**
126          * Definition of operator []
127          * @param Position of the quanternion to be returned. Position 0 corresponds
128          * to the real component and 1, 2, and 3 to the complex components.
129          * @param The value on the specified position is returned.
130          *
131          */
132         const float& operator[](unsigned int i) const;
133
134         /**
135          * Operator to print
136          */
137         friend std::ostream& operator<<(std::ostream& os, const Quaternion& coord);
138
139
140 private:
141
142         //------------------------------------------------------------
143         //Private methods
144         //------------------------------------------------------------
145
146
147         //------------------------------------------------------------
148         //Atributes
149         //------------------------------------------------------------
150
151         /**
152          * Real part of the quaternion
153          */
154         float r;
155
156         /**
157          * Angle between vectors
158          */
159         float theta;
160
161         /**
162          * Rotation vector
163          */
164         Vec3 w;
165
166         /**
167          * Vector the quaternion
168          */
169         Vec3 im;
170
171 };
172
173 //------------------------------------------------------------------------------
174 #endif