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  namespace flair {


16  namespace core {


17  class Euler;


18  class Vector3D;


19  class RotationMatrix;


20 


21  /*! \class Quaternion


22  *


23  * \brief Class defining a quaternion


24  */


25  class Quaternion {


26  public:


27  /*!


28  * \brief Constructor


29  *


30  * Construct a quaternion using specified values.


31  *


32  * \param q0, scalar part


33  * \param q1


34  * \param q2


35  * \param q3


36  */


37  Quaternion(float q0 = 1, float q1 = 0, float q2 = 0, float q3 = 0);


38 


39  /*!


40  * \brief Destructor


41  *


42  */


43  ~Quaternion();


44 


45  /*!


46  * \brief Norm


47  *


48  * \return norm


49  */


50  float GetNorm(void) const;


51 


52  /*!


53  * \brief Normalize


54  */


55  void Normalize(void);


56 


57  /*!


58  * \brief Logarithm


59  *


60  * This method also Normalize the quaternion.


61  *


62  * \param logarithm output logarithm


63  */


64  void GetLogarithm(Vector3D &logarithm);


65 


66  /*!


67  * \brief Logarithm


68  *


69  * This method also Normalize the quaternion.


70  *


71  * \return output logarithm


72  */


73  Vector3D GetLogarithm(void);


74 


75  /*!


76  * \brief Conjugate


77  */


78  void Conjugate(void);


79 


80  /*!


81  * \brief Conjugate


82  *


83  * \return Conjugate


84  */


85  Quaternion GetConjugate(void);


86 


87  /*!


88  * \brief Derivative


89  *


90  * \param w angular speed


91  *


92  * \return derivative


93  */


94  Quaternion GetDerivative(const Vector3D &angularSpeed) const;


95 


96  /*!


97  * \brief Derivate


98  *


99  * \param w rotationonal speed


100  */


101  void Derivate(const Vector3D &angularSpeed);


102 


103  /*!


104  * \brief Convert to euler angles


105  *


106  * \param euler output euler angles


107  */


108  void ToEuler(Euler &euler) const;


109 


110  /*!


111  * \brief Convert to euler angles


112  *


113  * \return euler angles


114  */


115  Euler ToEuler(void) const;


116 


117  /*!


118  * \brief Convert to rotation matrix


119  *


120  * \param m output matrix


121  */


122  void ToRotationMatrix(RotationMatrix &matrix) const;


123 


124  /*!


125  * \brief q0


126  */


127  float q0;


128 


129  /*!


130  * \brief q1


131  */


132  float q1;


133 


134  /*!


135  * \brief q2


136  */


137  float q2;


138 


139  /*!


140  * \brief q3


141  */


142  float q3;


143 


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


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


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


147  };


148 


149  /*! Add


150  *


151  * \brief Add


152  *


153  * \param quaterniontA quaternion


154  * \param quaterniontB quaternion


155  *


156  * \return quaterniontA+quaterniontB


157  */


158  Quaternion operator+(Quaternion const &quaterniontA,


159  Quaternion const &quaterniontB);


160 


161  /*! Substract


162  *


163  * \brief Substract


164  *


165  * \param quaterniontA quaternion


166  * \param quaterniontB quaternion


167  *


168  * \return quaterniontAquaterniontB


169  */


170  Quaternion operator(Quaternion const &quaternionA,


171  Quaternion const &quaterniontB);


172 


173  /*! Minus


174  *


175  * \brief Minus


176  *


177  * \param quaternion quaternion


178  *


179  * \return quaternion


180  */


181  Quaternion operator(const Quaternion &quaternion);


182 


183  /*! Multiply


184  *


185  * \brief Multiply


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  /*! Multiply


196  *


197  * \brief Multiply


198  *


199  * \param coeff coefficient


200  * \param quat quaternion


201  *


202  * \return coeff*quat


203  */


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


205 


206  /*! Multiply


207  *


208  * \brief Multiply


209  *


210  * \param quat quaternion


211  * \param coeff coefficient


212  *


213  * \return coeff*quat


214  */


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


216 


217  } // end namespace core


218  } // end namespace flair


219 


220  #endif // QUATERNION_H

