14 const std::string &description,
15 const std::string &sequence)
17 std::cout << description <<
" (" << sequence <<
"): [" << std::fixed << std::setprecision(2)
23void printQuaternion(
const Eigen::Quaterniond &quat,
const std::string &description)
25 std::cout << description <<
" [w, x, y, z]: [" << std::fixed << std::setprecision(4) << quat.w()
26 <<
", " << quat.x() <<
", " << quat.y() <<
", " << quat.z() <<
"]" << std::endl;
31 std::cout <<
"==============================================" << std::endl;
32 std::cout <<
"MoveG Rotation Library Example Usage" << std::endl;
33 std::cout <<
"==============================================" << std::endl;
36 std::cout <<
"\n1. Creating rotations using different constructors:" << std::endl;
40 std::cout <<
"Identity rotation matrix:\n" << identity.
toRotationMatrix() << std::endl;
47 Rotation rot_euler(yaw, pitch, roll,
true,
"ZYX",
false);
48 std::cout <<
"Rotation from Euler angles (ZYX, intrinsic):\n"
52 Eigen::Matrix3d R = Eigen::AngleAxisd(M_PI / 4, Eigen::Vector3d::UnitZ()).toRotationMatrix();
54 std::cout <<
"Rotation from matrix (45° around Z):\n"
58 Eigen::Quaterniond q =
59 Eigen::Quaterniond(Eigen::AngleAxisd(M_PI / 3, Eigen::Vector3d::UnitY()));
61 std::cout <<
"Rotation from quaternion (60° around Y):\n"
65 Eigen::AngleAxisd aa(M_PI / 6, Eigen::Vector3d::UnitX());
67 std::cout <<
"Rotation from angle-axis (30° around X):\n"
71 std::cout <<
"\n2. Using static methods to create rotations:" << std::endl;
74 std::cout <<
"Static method Euler angles rotation:\n"
78 std::cout <<
"Static method quaternion rotation:\n"
82 std::cout <<
"\n3. Converting between different rotation representations:" << std::endl;
85 Rotation rot_convert(M_PI / 4, M_PI / 6, M_PI / 3,
true,
"ZYX",
false);
90 Eigen::AngleAxisd rot_aa_convert = rot_convert.
toAngleAxis();
91 Eigen::Vector3d rot_euler_angles = rot_convert.
toEulerAngles(
true,
"ZYX");
93 std::cout <<
"Original rotation from Euler angles (ZYX):" << std::endl;
94 printEulerAngles(Eigen::Vector3d(M_PI / 4, M_PI / 6, M_PI / 3),
"Input angles",
"ZYX");
96 std::cout <<
"\nAs a rotation matrix:\n" << rot_mat << std::endl;
101 <<
"° around axis [" << rot_aa_convert.axis().x() <<
", " << rot_aa_convert.axis().y()
102 <<
", " << rot_aa_convert.axis().z() <<
"]" << std::endl;
107 std::cout <<
"\n4. Composition of rotations:" << std::endl;
114 Rotation rot_combined = rot1 * rot2;
116 std::cout <<
"Rotation 1 (90° around Z):\n" << rot1.
toRotationMatrix() << std::endl;
117 std::cout <<
"Rotation 2 (90° around Y):\n" << rot2.
toRotationMatrix() << std::endl;
118 std::cout <<
"Combined rotation (rot1 * rot2):\n"
122 Rotation rot_combined2 = rot2 * rot1;
123 std::cout <<
"Different order (rot2 * rot1):\n"
127 std::cout <<
"\n5. Utility functions:" << std::endl;
130 double angle_deg = 45.0;
132 std::cout << angle_deg <<
"° = " << angle_rad <<
" radians" << std::endl;
133 std::cout << angle_rad <<
" radians = " <<
Rotation::rad2deg(angle_rad) <<
"°" << std::endl;
136 double big_angle = 5 * M_PI;
138 std::cout <<
"Normalizing " << big_angle <<
" radians to [-π, π]: " << normalized
142 std::cout <<
"\nElementary rotation matrices:" << std::endl;
148 Eigen::Vector3d omega(0.1, 0.2, 0.3);
149 std::cout <<
"\nMatrix S for angular velocity [0.1, 0.2, 0.3]:\n"
152 Eigen::Matrix3d R_current = Eigen::Matrix3d::Identity();
154 std::cout <<
"Matrix R_dot:\n" << R_dot << std::endl;
159 Eigen::Vector3d angles_for_T(M_PI / 4, M_PI / 6, M_PI / 3);
161 std::cout <<
"\nMatrix T for ZYX Euler angles [" <<
Rotation::rad2deg(angles_for_T[0])
166 catch (
const std::exception &e)
168 std::cerr <<
"Error calculating matrix T: " << e.what() << std::endl;
171 std::cout <<
"==============================================" << std::endl;
Class for representing and managing rotations in three-dimensional space.
static double normalizeAngle(double angle)
Normalizes an angle to the range [-π, π].
static Eigen::Matrix3d matrixT(const Eigen::Vector3d &angles, const std::string &sequence)
Calculates the T matrix.
Eigen::Quaterniond toQuaternion() const
Converts the rotation to a quaternion.
Eigen::Matrix3d toRotationMatrix() const
Converts the rotation to a rotation matrix.
static Rotation fromEulerAngles(double angle1, double angle2, double angle3, bool intrinsic=true, const std::string &sequence="XYZ", bool degree=false)
Creates a rotation from Euler angles.
Eigen::AngleAxisd toAngleAxis() const
Converts the rotation to an axis-angle representation.
static Rotation fromQuaternion(const Eigen::Quaterniond &quaternion)
Creates a rotation from a quaternion.
static Eigen::Matrix3d rotationY(double angle)
Rotation matrix for a rotation around the Y axis.
static double deg2rad(double degree)
Converts degrees to radians.
static double rad2deg(double radian)
Converts radians to degrees.
static Eigen::Matrix3d matrixS(const Eigen::Vector3d &omega)
Calculates the S matrix.
static Eigen::Matrix3d rotationZ(double angle)
Rotation matrix for a rotation around the Z axis.
static Eigen::Matrix3d rotationX(double angle)
Rotation matrix for a rotation around the X axis.
static Eigen::Matrix3d matrixR_dot(const Eigen::Matrix3d &R, const Eigen::Matrix3d &S)
Calculates the R_dot matrix.
Eigen::Vector3d toEulerAngles(bool intrinsic=true, const std::string &sequence="ZYX") const
Converts the rotation to Euler angles.
Namespace for movement and manipulation of poses.
void printQuaternion(const Eigen::Quaterniond &quat, const std::string &description)
void printEulerAngles(const Eigen::Vector3d &angles, const std::string &description, const std::string &sequence)
Class for representing and manipulating 3D rotations.