32 #include <Base/Geometry/RMatrixBase.hh>
33 #include <Base/Geometry/Quaternion.hh>
36 # define strcasecmp _strcmpi
43 #define ROT_PARAM_Invalid -1
44 #define ROT_PARAM_Rodrigues 0
45 #define ROT_PARAM_Euler 1
46 #define ROT_PARAM_AxisAngle 2
47 #define ROT_PARAM_Quaternion 3
49 #define ROT_ORDER_XYZ 0
50 #define ROT_ORDER_XZY 1
51 #define ROT_ORDER_YXZ 2
52 #define ROT_ORDER_YZX 3
53 #define ROT_ORDER_ZXY 4
54 #define ROT_ORDER_ZYX 5
59 int main(
int argc,
char *argv[])
62 bool showUsage = (argc < 5);
63 int paramType = ROT_PARAM_Invalid, angleOrder = ROT_ORDER_XYZ;
65 if (strcasecmp(argv[1],
"Rodrigues") == 0)
66 paramType = ROT_PARAM_Rodrigues;
67 else if (strcasecmp(argv[1],
"Euler") == 0)
68 paramType = ROT_PARAM_Euler;
69 else if (strcasecmp(argv[1],
"EulerXYZ") == 0) {
70 paramType = ROT_PARAM_Euler; angleOrder = ROT_ORDER_XYZ;
71 }
else if (strcasecmp(argv[1],
"EulerXZY") == 0) {
72 paramType = ROT_PARAM_Euler; angleOrder = ROT_ORDER_XZY;
73 }
else if (strcasecmp(argv[1],
"EulerYXZ") == 0) {
74 paramType = ROT_PARAM_Euler; angleOrder = ROT_ORDER_YXZ;
75 }
else if (strcasecmp(argv[1],
"EulerYZX") == 0) {
76 paramType = ROT_PARAM_Euler; angleOrder = ROT_ORDER_YZX;
77 }
else if (strcasecmp(argv[1],
"EulerZXY") == 0) {
78 paramType = ROT_PARAM_Euler; angleOrder = ROT_ORDER_ZXY;
79 }
else if (strcasecmp(argv[1],
"EulerZYX") == 0) {
80 paramType = ROT_PARAM_Euler; angleOrder = ROT_ORDER_ZYX;
82 else if (strcasecmp(argv[1],
"AxisAngle") == 0)
83 paramType = ROT_PARAM_AxisAngle;
84 else if (strcasecmp(argv[1],
"Quaternion") == 0)
85 paramType = ROT_PARAM_Quaternion;
87 if (paramType == ROT_PARAM_Invalid)
89 else if ((paramType == ROT_PARAM_AxisAngle ||
90 paramType == ROT_PARAM_Quaternion) && argc < 6)
94 cout <<
"USAGE : ExampleRMatrix Rodrigues <wx> <wy> <wz> [<degree?>]" << endl
95 <<
" or ExampleRMatrix Euler[<order>] <ax> <ay> <az> [<degree?>]" << endl
96 <<
" or ExampleRMatrix AxisAngle <rx> <ry> <rz> <a> [<degree?>]" << endl
97 <<
" or ExampleRMatrix Quaternion <qx> <qy> <qz> <qw>" << endl << endl
98 <<
"Note that rotation angles and the length of the Rodrigues vector" << endl
99 <<
"are given in radians by default. Euler must be followed by order" << endl
100 <<
"of rotation angles (e.g. EulerYZX), otherwise order XYZ is used." << endl
101 <<
"Use parameter degree = 1 to provide angles in degree instead." << endl << endl;
105 bool useDegree =
false;
106 if (argc > ((paramType > 1) ? 6 : 5))
107 useDegree = (atoi(argv[(paramType > 1) ? 6 : 5]) != 0);
108 double factor = useDegree ? (M_PI / 180.0) : 1.0;
112 case ROT_PARAM_Rodrigues:
118 case ROT_PARAM_Euler:
120 double ax = atof(argv[2]) * factor;
121 double ay = atof(argv[3]) * factor;
122 double az = atof(argv[4]) * factor;
125 case ROT_ORDER_XYZ: R.
SetXYZ(ax, ay, az);
break;
126 case ROT_ORDER_XZY: R.
SetXZY(ax, ay, az);
break;
127 case ROT_ORDER_YXZ: R.
SetYXZ(ax, ay, az);
break;
128 case ROT_ORDER_YZX: R.
SetYZX(ax, ay, az);
break;
129 case ROT_ORDER_ZXY: R.
SetZXY(ax, ay, az);
break;
130 case ROT_ORDER_ZYX: R.
SetZYX(ax, ay, az);
break;
132 cerr <<
"ERROR : Invalid Euler angle order!" << endl;
137 case ROT_PARAM_AxisAngle:
141 double a = atof(argv[5]) * factor;
145 case ROT_PARAM_Quaternion:
153 cerr <<
"ERROR : Invalid rotation parameter type!" << endl;
156 if (res < 0)
return res;
158 cout <<
"Rotation matrix is " << R << endl;
162 cout <<
"Rotation angles in order XYZ are ax = " << ax * 180 / M_PI <<
", ay = "
163 << ay * 180 / M_PI <<
", az = " << az * 180 / M_PI <<
" degree" << endl;
165 cerr <<
"ERROR : Failed to get rotation angles in order XYZ!" << endl;
169 cout <<
"Rotation angles in order ZYX are ax = " << ax * 180 / M_PI <<
", ay = "
170 << ay * 180 / M_PI <<
", az = " << az * 180 / M_PI <<
" degree" << endl;
172 cerr <<
"ERROR : Failed to get rotation angles in order ZYX!" << endl;
176 cout <<
"Rotation angles in order YXZ are ax = " << ax * 180 / M_PI <<
", ay = "
177 << ay * 180 / M_PI <<
", az = " << az * 180 / M_PI <<
" degree" << endl;
179 cerr <<
"ERROR : Failed to get rotation angles in order YXZ!" << endl;
183 cout <<
"Rotation angles in order ZXY are ax = " << ax * 180 / M_PI <<
", ay = "
184 << ay * 180 / M_PI <<
", az = " << az * 180 / M_PI <<
" degree" << endl;
186 cerr <<
"ERROR : Failed to get rotation angles in order ZXY!" << endl;
190 cout <<
"Rotation angles in order YZX are ax = " << ax * 180 / M_PI <<
", ay = "
191 << ay * 180 / M_PI <<
", az = " << az * 180 / M_PI <<
" degree" << endl;
193 cerr <<
"ERROR : Failed to get rotation angles in order YZX!" << endl;
197 cout <<
"Rotation angles in order XZY are ax = " << ax * 180 / M_PI <<
", ay = "
198 << ay * 180 / M_PI <<
", az = " << az * 180 / M_PI <<
" degree" << endl;
200 cerr <<
"ERROR : Failed to get rotation angles in order XZY!" << endl;
206 cout <<
"Unit quaternion is " << q << endl;
208 cerr <<
"ERROR : Failed to get unit quaternion!" << endl;
215 cout <<
"Rotation axis is " << r << endl
216 <<
"Rotation angle is " << a * 180.0 / M_PI <<
" degree" << endl;
218 cerr <<
"ERROR : Failed to get rotation axis/angle!" << endl;
224 cout <<
"Rodrigues vector is " << w << endl;
226 cerr <<
"ERROR : Failed to get Rodrigues vector!" << endl;
int GetRotationAnglesZYX(double &PhiX, double &PhiY, double &PhiZ) const
Get Euler angles for this rotation matrix in order ZYX.
void SetXYZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XYZ.
void SetXZY(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order XZY.
void SetZYX(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order ZYX.
int GetRotationAnglesYZX(double &PhiX, double &PhiY, double &PhiZ) const
Get Euler angles for this rotation matrix in order YZX.
int SetFromQuaternion(const Quaternion< ROTATION_MATRIX_TYPE > &q)
Set rotation matrix from a quaternion.
void SetYXZ(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order YXZ.
void SetZXY(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order ZXY.
int GetQuaternion(Quaternion< ROTATION_MATRIX_TYPE > &quat) const
Calculates quaternion representation for this rotation matrix.
int GetRotationAnglesXZY(double &PhiX, double &PhiY, double &PhiZ) const
Get Euler angles for this rotation matrix in order XZY.
int GetRotationAnglesZXY(double &PhiX, double &PhiY, double &PhiZ) const
Get Euler angles for this rotation matrix in order ZXY.
void SetFromAxisAngle(Vector3< ROTATION_MATRIX_TYPE > w)
Set from rotation axis * angle (modified Rodrigues vector)
int GetRotationAnglesXYZ(double &PhiX, double &PhiY, double &PhiZ) const
Get Euler angles for this rotation matrix in order XYZ.
Implements a 3D rotation matrix.
int GetRotationAxisAngle(Vector3< ROTATION_MATRIX_TYPE > &axis, ROTATION_MATRIX_TYPE &angle) const
Calculates angle and rotation axis representation for this rotation matrix.
int GetRotationAnglesYXZ(double &PhiX, double &PhiY, double &PhiZ) const
Get Euler angles for this rotation matrix in order YXZ.
void SetYZX(ROTATION_MATRIX_TYPE PhiX, ROTATION_MATRIX_TYPE PhiY, ROTATION_MATRIX_TYPE PhiZ)
Set Euler angles (in rad) in order YZX.