Home | History | Annotate | Download | only in examples
      1 #include <unsupported/Eigen/EulerAngles>
      2 #include <iostream>
      3 
      4 using namespace Eigen;
      5 
      6 int main()
      7 {
      8   // A common Euler system by many armies around the world,
      9   //  where the first one is the azimuth(the angle from the north -
     10   //   the same angle that is show in compass)
     11   //  and the second one is elevation(the angle from the horizon)
     12   //  and the third one is roll(the angle between the horizontal body
     13   //   direction and the plane ground surface)
     14   // Keep remembering we're using radian angles here!
     15   typedef EulerSystem<-EULER_Z, EULER_Y, EULER_X> MyArmySystem;
     16   typedef EulerAngles<double, MyArmySystem> MyArmyAngles;
     17 
     18   MyArmyAngles vehicleAngles(
     19     3.14/*PI*/ / 2, /* heading to east, notice that this angle is counter-clockwise */
     20     -0.3, /* going down from a mountain */
     21     0.1); /* slightly rolled to the right */
     22 
     23   // Some Euler angles representation that our plane use.
     24   EulerAnglesZYZd planeAngles(0.78474, 0.5271, -0.513794);
     25 
     26   MyArmyAngles planeAnglesInMyArmyAngles = MyArmyAngles::FromRotation<true, false, false>(planeAngles);
     27 
     28   std::cout << "vehicle angles(MyArmy):     " << vehicleAngles << std::endl;
     29   std::cout << "plane angles(ZYZ):        " << planeAngles << std::endl;
     30   std::cout << "plane angles(MyArmy):     " << planeAnglesInMyArmyAngles << std::endl;
     31 
     32   // Now lets rotate the plane a little bit
     33   std::cout << "==========================================================\n";
     34   std::cout << "rotating plane now!\n";
     35   std::cout << "==========================================================\n";
     36 
     37   Quaterniond planeRotated = AngleAxisd(-0.342, Vector3d::UnitY()) * planeAngles;
     38 
     39   planeAngles = planeRotated;
     40   planeAnglesInMyArmyAngles = MyArmyAngles::FromRotation<true, false, false>(planeRotated);
     41 
     42   std::cout << "new plane angles(ZYZ):     " << planeAngles << std::endl;
     43   std::cout << "new plane angles(MyArmy): " << planeAnglesInMyArmyAngles << std::endl;
     44 
     45   return 0;
     46 }
     47