EulerAngles.cpp 1.8 KB

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