libalmath  2.5.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alquaternion.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Aldebaran Robotics. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the COPYING file.
5  */
6 
7 
8 #pragma once
9 #ifndef _LIBALMATH_ALMATH_TYPES_ALQUATERNION_H_
10 #define _LIBALMATH_ALMATH_TYPES_ALQUATERNION_H_
11 
12 #include <vector>
13 
14 namespace AL {
15  namespace Math {
16 
23  struct Quaternion {
25  float w;
27  float x;
29  float y;
31  float z;
32 
35 
50  Quaternion();
52 
55 
70  Quaternion(
76  float pW,
77  float pX,
78  float pY,
79  float pZ);
80 
83 
98  Quaternion(const std::vector<float>& pFloats);
104 
109  Quaternion& operator*= (const Quaternion& pQua2);
110 
115  inline Quaternion operator* (const Quaternion& pQua2) const
116  {
117  return Quaternion(
118  w*pQua2.w - x*pQua2.x - y*pQua2.y - z*pQua2.z,
119  w*pQua2.x + pQua2.w*x + y*pQua2.z - z*pQua2.y,
120  w*pQua2.y + pQua2.w*y + z*pQua2.x - x*pQua2.z,
121  w*pQua2.z + pQua2.w*z + x*pQua2.y - y*pQua2.x);
122  }
123 
128  bool operator== (const Quaternion& pQua2) const;
129 
134  bool operator!= (const Quaternion& pQua2) const;
135 
140  inline Quaternion operator* (float pVal) const
141  {
142  return Quaternion(w*pVal, x*pVal, y*pVal, z*pVal);
143  }
144 
149  Quaternion operator/ (float pVal) const;
150 
155  Quaternion& operator*= (float pVal);
156 
161  Quaternion& operator/= (float pVal);
162 
174  bool isNear(
175  const Quaternion& pQua2,
176  const float& pEpsilon=0.0001f) const;
177 
186  float norm() const;
187 
196  Quaternion normalize() const;
197 
205  Quaternion inverse() const;
206 
216  const float pAngle,
217  const float pAxisX,
218  const float pAxisY,
219  const float pAxisZ);
220 
224  void toVector(std::vector<float>& pReturnVector) const;
225  std::vector<float> toVector(void) const;
226  };
227 
238  float norm(const Quaternion& pQua);
239 
250  Quaternion normalize(const Quaternion& pQua);
251 
252 
260  void quaternionInverse(
261  const Quaternion& pQua,
262  Quaternion& pQuaOut);
263 
273  Quaternion quaternionInverse(const Quaternion& pQua);
274 
275 
289  const float pAngle,
290  const float pAxisX,
291  const float pAxisY,
292  const float pAxisZ);
293 
294 
306  const Quaternion& pQuaternion,
307  float& pAngle,
308  float& pAxisX,
309  float& pAxisY,
310  float& pAxisZ);
311 
321  std::vector<float> angleAndAxisRotationFromQuaternion(
322  const Quaternion& pQuaternion);
323 
324 
325  } // end namespace math
326 } // end namespace al
327 #endif // _LIBALMATH_ALMATH_TYPES_ALQUATERNION_H_
Quaternion & operator/=(float pVal)
Overloading of operator /= for Quaternion.
float norm() const
Compute the norm of the actual Quaternion.
Quaternion & operator*=(const Quaternion &pQua2)
Overloading of operator *= for Quaternion.
float norm(const Position2D &pPos)
Compute the norm of a Position2D.
Quaternion operator/(float pVal) const
Overloading of operator / for Quaternion.
bool operator==(const Quaternion &pQua2) const
Overloading of operator == for Quaternion.
bool operator!=(const Quaternion &pQua2) const
Overloading of operator != for Quaternion.
std::vector< float > toVector(void) const
Quaternion inverse() const
Compute the quaternion inverse of the actual Quaternion
Position2D normalize(const Position2D &pPos)
Normalize a Position2D.
void angleAndAxisRotationFromQuaternion(const Quaternion &pQuaternion, float &pAngle, float &pAxisX, float &pAxisY, float &pAxisZ)
Compute angle and axis rotation from a Quaternion.
Quaternion quaternionFromAngleAndAxisRotation(const float pAngle, const float pAxisX, const float pAxisY, const float pAxisZ)
Create a Quaternion initialized with explicit angle and axis rotation.
Quaternion operator*(const Quaternion &pQua2) const
Overloading of operator * for Quaternion.
Definition: alquaternion.h:115
Quaternion normalize() const
Normalize the actual Quaterion.
static Quaternion fromAngleAndAxisRotation(const float pAngle, const float pAxisX, const float pAxisY, const float pAxisZ)
Create a Quaternion initialized with explicit angle and axis rotation.
Quaternion()
Create a Quaternion initialize with 0.0f.
bool isNear(const Quaternion &pQua2, const float &pEpsilon=0.0001f) const
Check if the actual Quaternion is near the one give in argument.
Create and play with a Quaternion.
Definition: alquaternion.h:23
void quaternionInverse(const Quaternion &pQua, Quaternion &pQuaOut)
Return the quaternion inverse of the given Quaternion: