1 | // %flair:license{ |
---|
2 | // This file is part of the Flair framework distributed under the |
---|
3 | // CECILL-C License, Version 1.0. |
---|
4 | // %flair:license} |
---|
5 | /*! |
---|
6 | * \file Quaternion.h |
---|
7 | * \brief Class defining a quaternion |
---|
8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253 |
---|
9 | * \date 2016/02/03 |
---|
10 | * \version 4.0 |
---|
11 | */ |
---|
12 | #ifndef QUATERNION_H |
---|
13 | #define QUATERNION_H |
---|
14 | |
---|
15 | #include <Vector3D.h> |
---|
16 | |
---|
17 | namespace flair { |
---|
18 | namespace core { |
---|
19 | class Euler; |
---|
20 | class RotationMatrix; |
---|
21 | |
---|
22 | /*! \class Quaternion |
---|
23 | * |
---|
24 | * \brief Class defining a quaternion |
---|
25 | */ |
---|
26 | class Quaternion { |
---|
27 | public: |
---|
28 | /*! |
---|
29 | * \brief Constructor |
---|
30 | * |
---|
31 | * Construct a quaternion using specified values. |
---|
32 | * |
---|
33 | * \param q0, scalar part |
---|
34 | * \param q1 |
---|
35 | * \param q2 |
---|
36 | * \param q3 |
---|
37 | */ |
---|
38 | Quaternion(float q0 = 1, float q1 = 0, float q2 = 0, float q3 = 0); |
---|
39 | |
---|
40 | /*! |
---|
41 | * \brief Destructor |
---|
42 | * |
---|
43 | */ |
---|
44 | ~Quaternion(); |
---|
45 | |
---|
46 | /*! |
---|
47 | * \brief Norm |
---|
48 | * |
---|
49 | * \return norm |
---|
50 | */ |
---|
51 | float GetNorm(void) const; |
---|
52 | |
---|
53 | /*! |
---|
54 | * \brief Normalize |
---|
55 | */ |
---|
56 | void Normalize(void); |
---|
57 | |
---|
58 | /*! |
---|
59 | * \brief Logarithm |
---|
60 | * |
---|
61 | * This method also Normalize the quaternion. |
---|
62 | * |
---|
63 | * \param logarithm output logarithm |
---|
64 | */ |
---|
65 | void GetLogarithm(Vector3Df &logarithm); |
---|
66 | |
---|
67 | /*! |
---|
68 | * \brief Logarithm |
---|
69 | * |
---|
70 | * This method also Normalize the quaternion. |
---|
71 | * |
---|
72 | * \return output logarithm |
---|
73 | */ |
---|
74 | Vector3Df GetLogarithm(void); |
---|
75 | |
---|
76 | /*! |
---|
77 | * \brief Conjugate |
---|
78 | */ |
---|
79 | void Conjugate(void); |
---|
80 | |
---|
81 | /*! |
---|
82 | * \brief Conjugate |
---|
83 | * |
---|
84 | * \return Conjugate |
---|
85 | */ |
---|
86 | Quaternion GetConjugate(void); |
---|
87 | |
---|
88 | /*! |
---|
89 | * \brief Derivative |
---|
90 | * |
---|
91 | * \param w angular speed |
---|
92 | * |
---|
93 | * \return derivative |
---|
94 | */ |
---|
95 | Quaternion GetDerivative(const Vector3Df &angularSpeed) const; |
---|
96 | |
---|
97 | /*! |
---|
98 | * \brief Derivate |
---|
99 | * |
---|
100 | * \param w rotationonal speed |
---|
101 | */ |
---|
102 | void Derivate(const Vector3Df &angularSpeed); |
---|
103 | |
---|
104 | /*! |
---|
105 | * \brief Convert to euler angles |
---|
106 | * |
---|
107 | * \param euler output euler angles |
---|
108 | */ |
---|
109 | void ToEuler(Euler &euler) const; |
---|
110 | |
---|
111 | /*! |
---|
112 | * \brief Convert to euler angles |
---|
113 | * |
---|
114 | * \return euler angles |
---|
115 | */ |
---|
116 | Euler ToEuler(void) const; |
---|
117 | |
---|
118 | /*! |
---|
119 | * \brief Get roll euler angle |
---|
120 | * |
---|
121 | * \return roll euler angle |
---|
122 | */ |
---|
123 | float GetEulerRoll(void) const; |
---|
124 | |
---|
125 | /*! |
---|
126 | * \brief Get pitch euler angle |
---|
127 | * |
---|
128 | * \return pitch euler angle |
---|
129 | */ |
---|
130 | float GetEulerPitch(void) const; |
---|
131 | |
---|
132 | /*! |
---|
133 | * \brief Get yaw euler angle |
---|
134 | * |
---|
135 | * \return yaw euler angle |
---|
136 | */ |
---|
137 | float GetEulerYaw(void) const; |
---|
138 | |
---|
139 | /*! |
---|
140 | * \brief Convert to rotation matrix |
---|
141 | * |
---|
142 | * \param m output matrix |
---|
143 | */ |
---|
144 | void ToRotationMatrix(RotationMatrix &matrix) const; |
---|
145 | |
---|
146 | /*! |
---|
147 | * \brief q0 |
---|
148 | */ |
---|
149 | float q0; |
---|
150 | |
---|
151 | /*! |
---|
152 | * \brief q1 |
---|
153 | */ |
---|
154 | float q1; |
---|
155 | |
---|
156 | /*! |
---|
157 | * \brief q2 |
---|
158 | */ |
---|
159 | float q2; |
---|
160 | |
---|
161 | /*! |
---|
162 | * \brief q3 |
---|
163 | */ |
---|
164 | float q3; |
---|
165 | |
---|
166 | Quaternion &operator+=(const Quaternion &quaternion); |
---|
167 | Quaternion &operator-=(const Quaternion &quaternion); |
---|
168 | Quaternion &operator=(const Quaternion &quaternion); |
---|
169 | }; |
---|
170 | |
---|
171 | /*! Add |
---|
172 | * |
---|
173 | * \brief Add |
---|
174 | * |
---|
175 | * \param quaterniontA quaternion |
---|
176 | * \param quaterniontB quaternion |
---|
177 | * |
---|
178 | * \return quaterniontA+quaterniontB |
---|
179 | */ |
---|
180 | Quaternion operator+(Quaternion const &quaterniontA, |
---|
181 | Quaternion const &quaterniontB); |
---|
182 | |
---|
183 | /*! Substract |
---|
184 | * |
---|
185 | * \brief Substract |
---|
186 | * |
---|
187 | * \param quaterniontA quaternion |
---|
188 | * \param quaterniontB quaternion |
---|
189 | * |
---|
190 | * \return quaterniontA-quaterniontB |
---|
191 | */ |
---|
192 | Quaternion operator-(Quaternion const &quaternionA, |
---|
193 | Quaternion const &quaterniontB); |
---|
194 | |
---|
195 | /*! Minus |
---|
196 | * |
---|
197 | * \brief Minus |
---|
198 | * |
---|
199 | * \param quaternion quaternion |
---|
200 | * |
---|
201 | * \return -quaternion |
---|
202 | */ |
---|
203 | Quaternion operator-(const Quaternion &quaternion); |
---|
204 | |
---|
205 | /*! Multiply |
---|
206 | * |
---|
207 | * \brief Multiply |
---|
208 | * |
---|
209 | * \param quaterniontA quaternion |
---|
210 | * \param quaterniontB quaternion |
---|
211 | * |
---|
212 | * \return quaterniontA*quaterniontB |
---|
213 | */ |
---|
214 | Quaternion operator*(Quaternion const &quaternionA, |
---|
215 | Quaternion const &quaterniontB); |
---|
216 | |
---|
217 | /*! Multiply |
---|
218 | * |
---|
219 | * \brief Multiply |
---|
220 | * |
---|
221 | * \param coeff coefficient |
---|
222 | * \param quat quaternion |
---|
223 | * |
---|
224 | * \return coeff*quat |
---|
225 | */ |
---|
226 | Quaternion operator*(float coeff, Quaternion const &quaternion); |
---|
227 | |
---|
228 | /*! Multiply |
---|
229 | * |
---|
230 | * \brief Multiply |
---|
231 | * |
---|
232 | * \param quat quaternion |
---|
233 | * \param coeff coefficient |
---|
234 | * |
---|
235 | * \return coeff*quat |
---|
236 | */ |
---|
237 | Quaternion operator*(Quaternion const &quaternion, float coeff); |
---|
238 | |
---|
239 | } // end namespace core |
---|
240 | } // end namespace flair |
---|
241 | |
---|
242 | #endif // QUATERNION_H |
---|