1  // %flair:license{


2  // This file is part of the Flair framework distributed under the


3  // CECILLC 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 Convert to rotation matrix


120  *


121  * \param m output matrix


122  */


123  void ToRotationMatrix(RotationMatrix &matrix) const;


124 


125  /*!


126  * \brief q0


127  */


128  float q0;


129 


130  /*!


131  * \brief q1


132  */


133  float q1;


134 


135  /*!


136  * \brief q2


137  */


138  float q2;


139 


140  /*!


141  * \brief q3


142  */


143  float q3;


144 


145  Quaternion &operator+=(const Quaternion &quaternion);


146  Quaternion &operator=(const Quaternion &quaternion);


147  Quaternion &operator=(const Quaternion &quaternion);


148  };


149 


150  /*! Add


151  *


152  * \brief Add


153  *


154  * \param quaterniontA quaternion


155  * \param quaterniontB quaternion


156  *


157  * \return quaterniontA+quaterniontB


158  */


159  Quaternion operator+(Quaternion const &quaterniontA,


160  Quaternion const &quaterniontB);


161 


162  /*! Substract


163  *


164  * \brief Substract


165  *


166  * \param quaterniontA quaternion


167  * \param quaterniontB quaternion


168  *


169  * \return quaterniontAquaterniontB


170  */


171  Quaternion operator(Quaternion const &quaternionA,


172  Quaternion const &quaterniontB);


173 


174  /*! Minus


175  *


176  * \brief Minus


177  *


178  * \param quaternion quaternion


179  *


180  * \return quaternion


181  */


182  Quaternion operator(const Quaternion &quaternion);


183 


184  /*! Multiply


185  *


186  * \brief Multiply


187  *


188  * \param quaterniontA quaternion


189  * \param quaterniontB quaternion


190  *


191  * \return quaterniontA*quaterniontB


192  */


193  Quaternion operator*(Quaternion const &quaternionA,


194  Quaternion const &quaterniontB);


195 


196  /*! Multiply


197  *


198  * \brief Multiply


199  *


200  * \param coeff coefficient


201  * \param quat quaternion


202  *


203  * \return coeff*quat


204  */


205  Quaternion operator*(float coeff, Quaternion const &quaternion);


206 


207  /*! Multiply


208  *


209  * \brief Multiply


210  *


211  * \param quat quaternion


212  * \param coeff coefficient


213  *


214  * \return coeff*quat


215  */


216  Quaternion operator*(Quaternion const &quaternion, float coeff);


217 


218  } // end namespace core


219  } // end namespace flair


220 


221  #endif // QUATERNION_H

