MoveG 1.0.0
A modern C++ library for Robotics
Loading...
Searching...
No Matches
rotation_lib.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <eigen3/Eigen/Dense>
12#include <eigen3/Eigen/Geometry>
13
14#include <array>
15#include <cmath>
16#include <iostream>
17#include <stdexcept>
18#include <string>
19#include <vector>
20
21// Additional comments to clarify the behavior of intrinsic and extrinsic rotations
22
40namespace MoveG
41{
42
51{
52public:
58 Rotation();
59
64 Rotation(const Rotation &other);
65
75 Rotation(Rotation &&other) noexcept;
76
81 Rotation(const Eigen::Matrix3d &rotation_matrix);
82
87 Rotation(const Eigen::Quaterniond &quaternion);
88
93 Rotation(const Eigen::AngleAxisd &angle_axis);
94
104 Rotation(double angle1,
105 double angle2,
106 double angle3,
107 bool intrinsic = true,
108 const std::string &sequence = "ZYX",
109 bool degree = false);
110
114 ~Rotation() = default;
115
133 static Rotation fromRotationMatrix(const Eigen::Matrix3d &rotation_matrix);
134
140 static Rotation fromQuaternion(const Eigen::Quaterniond &quaternion);
141
147 static Rotation fromAngleAxis(const Eigen::AngleAxisd &angle_axis);
148
159 static Rotation fromEulerAngles(double angle1,
160 double angle2,
161 double angle3,
162 bool intrinsic = true,
163 const std::string &sequence = "XYZ",
164 bool degree = false);
165
166 // Converters
167
172 Eigen::Matrix3d toRotationMatrix() const;
173
178 Eigen::Quaterniond toQuaternion() const;
179
184 Eigen::AngleAxisd toAngleAxis() const;
185
192 Eigen::Vector3d toEulerAngles(bool intrinsic = true, const std::string &sequence = "ZYX") const;
193
194 // Overloading of operators * and =
195
201 Rotation operator*(const Rotation &other) const;
202
208 Rotation &operator=(const Rotation &other);
209
215 Rotation &operator=(Rotation &&other) noexcept;
216
217 // Angle normalization methods
223 static double normalizeAngle(double angle);
224
232 static double normalizeAngleRange(double angle, double minVal, double maxVal);
233
239 static Eigen::Vector3d normalizeEulerAngles(const Eigen::Vector3d &angles);
240
241 // Static methods for quaternion operations
248 static Eigen::Quaterniond quaternion_difference(const Eigen::Quaterniond &a,
249 const Eigen::Quaterniond &b);
250
256 static Eigen::Quaterniond quaternion_negation(const Eigen::Quaterniond &v);
257
264 static Eigen::Quaterniond scalar_product(const Eigen::Quaterniond &v, double t);
265
272 static Eigen::Quaterniond quaternion_minus(const Eigen::Quaterniond &v1,
273 const Eigen::Quaterniond &v0);
274
281 static Eigen::Quaterniond quaternion_plus(const Eigen::Quaterniond &v1,
282 const Eigen::Quaterniond &v0);
283
289 static double deg2rad(double degree);
290
296 static double rad2deg(double radian);
297
298 // Elementary Rotations Matrices
299
305 static Eigen::Matrix3d rotationX(double angle);
306
312 static Eigen::Matrix3d rotationY(double angle);
313
319 static Eigen::Matrix3d rotationZ(double angle);
320
321 // Definition of Matrix S and R_dot
322
328 static Eigen::Matrix3d matrixS(const Eigen::Vector3d &omega);
329
336 static Eigen::Matrix3d matrixR_dot(const Eigen::Matrix3d &R, const Eigen::Matrix3d &S);
337
344 static Eigen::Matrix3d matrixR_dot(const Eigen::Matrix3d &R, const Eigen::Vector3d &omega);
345
346 // Matrix T Mapping Between Body Angular Velocity Vector and the Euler Angle Rates
347
355 static Eigen::Matrix3d matrixT(const Eigen::Vector3d &angles, const std::string &sequence);
356
357 // Output stream operator
364 friend std::ostream &operator<<(std::ostream &os, const Rotation &rotation);
365
366private:
370 Eigen::Quaterniond q;
371
372 // Auxiliary functions
373
380 static Eigen::AngleAxisd angleAxis(char axis, double angle);
381
388 static int axisToIndex(char axis);
389
396 static int checkSequence(const std::string &sequence);
397};
398
399} // namespace MoveG
Class for representing and managing rotations in three-dimensional space.
Rotation operator*(const Rotation &other) const
Composition of two rotations.
Eigen::Quaterniond q
Internal representation of rotation via quaternion.
static int axisToIndex(char axis)
Converts an axis character to index.
static Eigen::Vector3d normalizeEulerAngles(const Eigen::Vector3d &angles)
Normalizes Euler angles to the range [-π, π].
static Rotation fromRotationMatrix(const Eigen::Matrix3d &rotation_matrix)
Creates a rotation from a rotation matrix.
Rotation()
Default constructor.
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 fromAngleAxis(const Eigen::AngleAxisd &angle_axis)
Creates a rotation from an axis-angle representation.
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.
friend std::ostream & operator<<(std::ostream &os, const Rotation &rotation)
Outputs the rotation to a stream in quaternion format.
static Eigen::Matrix3d rotationY(double angle)
Rotation matrix for a rotation around the Y axis.
static Eigen::Quaterniond quaternion_difference(const Eigen::Quaterniond &a, const Eigen::Quaterniond &b)
Calculates the difference between two quaternions.
Rotation & operator=(const Rotation &other)
Assignment operator.
static double deg2rad(double degree)
Converts degrees to radians.
static double rad2deg(double radian)
Converts radians to degrees.
static Eigen::Quaterniond quaternion_negation(const Eigen::Quaterniond &v)
Negates the quaternion.
static Eigen::Matrix3d matrixS(const Eigen::Vector3d &omega)
Calculates the S matrix.
static Eigen::Quaterniond quaternion_minus(const Eigen::Quaterniond &v1, const Eigen::Quaterniond &v0)
Calculates the difference between two quaternions (v1 - v0).
static double normalizeAngleRange(double angle, double minVal, double maxVal)
Normalizes an angle to a specified range.
static Eigen::Quaterniond scalar_product(const Eigen::Quaterniond &v, double t)
Calculates the scalar product of a quaternion by a scalar.
~Rotation()=default
Default destructor.
static int checkSequence(const std::string &sequence)
Checks the validity of the Euler angle sequence.
static Eigen::Quaterniond quaternion_plus(const Eigen::Quaterniond &v1, const Eigen::Quaterniond &v0)
Calculates the sum of two quaternions.
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.
static Eigen::AngleAxisd angleAxis(char axis, double angle)
Creates an axis-angle representation.
Namespace for movement and manipulation of poses.
Definition pose_lib.cpp:12