Skeletal Animation Multithread Face
Classes | Static Public Member Functions | List of all members
EulerRotations Class Reference

Class EulerRotations. More...

#include <euler_rotations.h>

Classes

struct  Euler
 Custom Euler angles struct. More...
 
struct  Quaternions
 Custom quaternions struct: $w + x \vec{i} + y \vec{j} + z \vec{k}$. More...
 

Static Public Member Functions

static Quaternions euler_to_quaternions (double phi, double theta, double psi)
 Convert Euler angles to quaternions. More...
 
static Euler quaternions_to_euler (double w, double x, double y, double z)
 Convert quaternions to Euler angles. More...
 
static Eigen::Matrix3d basic_rotation_x (double x)
 Basic rotation matrix wrt x axis. More...
 
static Eigen::Matrix3d basic_rotation_y (double x)
 Basic rotation matrix wrt y axis. More...
 
static Eigen::Matrix3d basic_rotation_z (double x)
 Basic rotation matrix wrt z axis. More...
 
static Eigen::Matrix3d rotation (double phi, double theta, double psi)
 Euler rotation matrix z-y'-x''. More...
 
static Eigen::Matrix3d rotation (Eigen::Vector3d euler_angles)
 
static Eigen::Matrix3d rotation (std::vector< double > euler_angles)
 
static Eigen::Matrix3d rotation (Euler euler_angles)
 

Detailed Description

Class EulerRotations.

This class contains definitions of rotation matrices and useful functionality for rotation releated operations.

Definition at line 12 of file euler_rotations.h.

Member Function Documentation

◆ basic_rotation_x()

Eigen::Matrix3d EulerRotations::basic_rotation_x ( double  x)
static

Basic rotation matrix wrt x axis.

Return the basic rotation matrix around x axis by a given angle x.

Parameters
xThe rotation angle.
Returns
Eigen::Matrix3d The basic rotation matrix around x axis.

Definition at line 9 of file euler_rotations.cpp.

10{
11 // Matrix initialization
12 Eigen::Matrix3d m;
13
14 m << 1.0f, 0.0f, 0.0f,
15 0.0f, cos(x), -sin(x),
16 0.0f, sin(x), cos(x);
17 return m;
18}
Here is the caller graph for this function:

◆ basic_rotation_y()

Eigen::Matrix3d EulerRotations::basic_rotation_y ( double  x)
static

Basic rotation matrix wrt y axis.

Return the basic rotation matrix around y axis by a given angle x.

Parameters
xThe rotation angle.
Returns
Eigen::Matrix3d The basic rotation matrix around y axis.

Definition at line 26 of file euler_rotations.cpp.

27{
28 // Matrix initialization
29 Eigen::Matrix3d m;
30
31 m << cos(x), 0.0f, sin(x),
32 0.0f, 1.0f, 0.0f,
33 -sin(x), 0.0f, cos(x);
34 return m;
35}
Here is the caller graph for this function:

◆ basic_rotation_z()

Eigen::Matrix3d EulerRotations::basic_rotation_z ( double  x)
static

Basic rotation matrix wrt z axis.

Return the basic rotation matrix around z axis by a given angle x.

Parameters
xThe rotation angle.
Returns
Eigen::Matrix3d The basic rotation matrix around z axis.

Definition at line 43 of file euler_rotations.cpp.

44{
45 // Matrix initialization
46 Eigen::Matrix3d m;
47
48 m << cos(x), -sin(x), 0.0f,
49 sin(x), cos(x), 0.0f,
50 0.0f, 0.0f, 1.0f;
51 return m;
52}
Here is the caller graph for this function:

◆ euler_to_quaternions()

EulerRotations::Quaternions EulerRotations::euler_to_quaternions ( double  phi,
double  theta,
double  psi 
)
static

Convert Euler angles to quaternions.

This method will return a custom Quaternions struct from a set of Euler angles. Euler angles follow the post multiply sequence zyx. Rotate "psi" around Z (yaw), "theta" around y (pitch) and "phi" around x (roll).

Parameters
phiRoll angle around x axis. (rad)
thetaPitch angle around y axis. (rad)
psiYaw angle around z axis. (rad)
Returns
EulerRotations::Quaternions Quaterinos struct.

Definition at line 117 of file euler_rotations.cpp.

119{
121
122 double cy = cos(psi * 0.5); double sy = sin(psi * 0.5);
123 double cp = cos(theta * 0.5); double sp = sin(theta * 0.5);
124 double cr = cos(phi * 0.5); double sr = sin(phi * 0.5);
125
126 quatern.w = cr * cp * cy + sr * sp * sy;
127 quatern.x = sr * cp * cy - cr * sp * sy;
128 quatern.y = cr * sp * cy + sr * cp * sy;
129 quatern.z = cr * cp * sy - sr * sp * cy;
130
131 // Return Quaternions
132 return quatern;
133}
Custom quaternions struct: .
Here is the caller graph for this function:

◆ quaternions_to_euler()

EulerRotations::Euler EulerRotations::quaternions_to_euler ( double  w,
double  x,
double  y,
double  z 
)
static

Convert quaternions to Euler angles.

This method will return a custom Euler struct from a set of Quaternions. Euler angles follow the post multiply sequence zyx. Rotate "psi" around Z (yaw), "theta" around y (pitch) and "phi" around x (roll).

Parameters
wQuaternion parameter w.
xQuaternion parameter x.
yQuaternion parameter y.
zQuaternion parameter z.
Returns
EulerRotations::Euler Euler angles given in radians.

Definition at line 148 of file euler_rotations.cpp.

150{
151 EulerRotations::Euler euler_angles;
152
153 // Roll (x-axis rotation)
154 double sinr_cosp = 2.0 * (w * x + y * z);
155 double cosr_cosp = 1.0 - 2.0 * (x * x + y * y);
156 euler_angles.phi = std::atan2(sinr_cosp, cosr_cosp);
157
158 // Pitch (y-axis rotation)
159 double sinp = 2.0 * (w * y - z * x);
160 if (std::abs(sinp) >= 1.0)
161 {
162 euler_angles.theta = std::copysign(M_PI / 2.0, sinp); // use 90 degrees if out of range
163 }
164 else
165 {
166 euler_angles.theta = std::asin(sinp);
167 }
168
169 // Yaw (z-axis rotation)
170 double siny_cosp = 2.0 * (w * z + x * y);
171 double cosy_cosp = 1.0 - 2.0 * (y * y + z * z);
172 euler_angles.psi = std::atan2(siny_cosp, cosy_cosp);
173
174 // Return Euler angles
175 return euler_angles;
176}
Custom Euler angles struct.

◆ rotation() [1/4]

Eigen::Matrix3d EulerRotations::rotation ( double  phi,
double  theta,
double  psi 
)
static

Euler rotation matrix z-y'-x''.

Compound rotation matrix given three Euler angles The Euler angles follow the post multiply * sequence zyx. Rotate "psi" around Z (yaw), "theta" around y (pitch) and "phi" around x (roll). Return the basic rotation matrix around z axis by a given angle x.

Parameters
phiRoll angle around x axis. (rad)
thetaPitch angle around y axis. (rad)
psiYaw angle around z axis. (rad)
Returns
Eigen::Matrix3d The compound rotation matrix.

Definition at line 66 of file euler_rotations.cpp.

67{
68 // Matrix initialization
69 Eigen::Matrix3d m;
70
71 // Basic rotations
72 Eigen::Matrix3d rotx = basic_rotation_x(phi);
73 Eigen::Matrix3d roty = basic_rotation_y(theta);
74 Eigen::Matrix3d rotz = basic_rotation_z(psi);
75
76 // Total rotation matrix
77 m = rotz * roty * rotx;
78
79 return m;
80}
static Eigen::Matrix3d basic_rotation_y(double x)
Basic rotation matrix wrt y axis.
static Eigen::Matrix3d basic_rotation_x(double x)
Basic rotation matrix wrt x axis.
static Eigen::Matrix3d basic_rotation_z(double x)
Basic rotation matrix wrt z axis.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotation() [2/4]

Eigen::Matrix3d EulerRotations::rotation ( Eigen::Vector3d  euler_angles)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 85 of file euler_rotations.cpp.

86{
87 return rotation(euler_angles(0), euler_angles(1), euler_angles(2));
88}
static Eigen::Matrix3d rotation(double phi, double theta, double psi)
Euler rotation matrix z-y'-x''.
Here is the call graph for this function:

◆ rotation() [3/4]

Eigen::Matrix3d EulerRotations::rotation ( Euler  euler_angles)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 101 of file euler_rotations.cpp.

102{
103 return rotation(euler_angles.phi, euler_angles.theta, euler_angles.psi);
104}
Here is the call graph for this function:

◆ rotation() [4/4]

Eigen::Matrix3d EulerRotations::rotation ( std::vector< double >  euler_angles)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 93 of file euler_rotations.cpp.

94{
95 return rotation(euler_angles[0], euler_angles[1], euler_angles[2]);
96}
Here is the call graph for this function:

The documentation for this class was generated from the following files: