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