Go to the documentation of this file.00001 #include <iostream>
00002 #include <math.h>
00003 #include <vector>
00004 #include <Eigen/Core>
00005
00006 #define PI 3.14159265
00007 using namespace std;
00008
00009 float
00010 toDegrees (float radians)
00011 {
00012 return radians * (180 / PI);
00013 }
00014
00015 float
00016 toRadians (float degrees)
00017 {
00018 return degrees * (PI / 180);
00019 }
00020 struct euler
00021 {
00022 double x;
00023 double y;
00024 double z;
00025 };
00026 struct quart
00027 {
00028 double q1;
00029 double q2;
00030 double q3;
00031 double q4;
00032 };
00033 using namespace std;
00034
00035 int
00036 main ()
00037 {
00038 Eigen::Vector3f v1 (-0.33, 0.33, -0.34);
00039 cout << "vector v1 : \n" << v1 << endl;
00040
00041
00042
00043
00044
00045
00046
00047
00048 v1.normalize ();
00049
00050
00051 cout << "normalized vector v1 :\n" << v1 << endl;
00052
00053 float cos_x, cos_y, cos_z;
00054 cos_x = acos (v1[0]);
00055 cos_y = acos (v1[1]);
00056 cos_z = acos (v1[2]);
00057 cout << " cos_x: " << toDegrees (cos_x) << " cos_y: " << toDegrees (cos_y) << " cos_z: " << toDegrees (cos_z) << endl;
00058
00059 euler a;
00060 quart b;
00061 a.x = toRadians(50);
00062 a.y = toRadians(90);
00063 a.z = toRadians(0);
00064
00065 cout << endl << "Euler1:" << endl;
00066 cout << a.x << endl << a.y << endl << a.z << endl;
00067
00068 cout << "Quart:" << endl;
00069
00070 b.q1 = cos (a.x / 2) * cos (a.y / 2)* cos (a.z / 2) + sin (a.x / 2) * sin (a.y / 2)* sin (a.z / 2);
00071
00072
00073
00074 b.q2 = sin (a.x / 2) * cos (a.y / 2)* cos (a.z / 2) - cos (a.x / 2) * sin (a.y / 2)* sin (a.z / 2);
00075
00076
00077
00078 b.q3 = cos (a.x / 2) * sin (a.y / 2)* cos (a.z / 2) + sin (a.x / 2) * cos (a.y / 2)* sin (a.z / 2);
00079
00080
00081
00082 b.q4 = cos (a.x / 2) * cos (a.y / 2)* sin (a.z / 2) - sin (a.x / 2) * sin (a.y / 2)* cos (a.z / 2);
00083
00084
00085 cout << "q1 : " << b.q1 << endl;
00086 cout << "q2 : " << b.q2 << endl;
00087 cout << "q3 : " << b.q3 << endl;
00088 cout << "q4 : " << b.q4 << endl;
00089
00090
00091 a.x = atan2 ((b.q1 * b.q3 + b.q2 * b.q4), (b.q2 * b.q3 - b.q1 * b.q4));
00092 a.y = acos (pow (-b.q1, 2) + pow (-b.q2, 2) + pow (-b.q3, 2) + pow (-b.q4, 2));
00093 a.z = -atan2 ((b.q1 * b.q3 - b.q2 * b.q4), (b.q2 * b.q3 + b.q1 * b.q4));
00094
00095
00096
00097
00098
00099
00100 cout << endl << "Euler2:" << endl;
00101 cout << toDegrees (a.x) << endl << toDegrees (a.y) << endl << toDegrees (a.z) << endl;
00102
00103 Eigen::Vector3f v(1,0,0);
00104 cout << endl << "v.unitOrthogonal :: \n" <<v.unitOrthogonal()<< endl;
00105
00106 return 0;
00107 }