libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::RotationMatrix< Scalar > Class Template Reference

旋转矩阵类,继承自 Eigen::Matrix<Scalar, 3, 3>。 Rotation matrix class, inheriting from Eigen::Matrix<Scalar, 3, 3>. More...

#include <transform.hpp>

Inheritance diagram for LibXR::RotationMatrix< Scalar >:
[legend]
Collaboration diagram for LibXR::RotationMatrix< Scalar >:
[legend]

Public Member Functions

 RotationMatrix ()
 默认构造函数,初始化单位旋转矩阵。 Default constructor initializing an identity rotation matrix.
 
 RotationMatrix (Scalar r00, Scalar r01, Scalar r02, Scalar r10, Scalar r11, Scalar r12, Scalar r20, Scalar r21, Scalar r22)
 通过 9 个矩阵元素的值构造旋转矩阵。 Constructs a rotation matrix using 9 matrix elements.
 
 RotationMatrix (const Eigen::Matrix< Scalar, 3, 3 > &R)
 通过 Eigen 3x3 矩阵构造旋转矩阵。 Constructs a rotation matrix from an Eigen 3x3 matrix.
 
 RotationMatrix (const Eigen::Quaternion< Scalar > &q)
 通过 Eigen 四元数构造旋转矩阵。 Constructs a rotation matrix from an Eigen quaternion.
 
 RotationMatrix (const Quaternion< Scalar > &q)
 通过 Quaternion 四元数构造旋转矩阵。 Constructs a rotation matrix from a Quaternion object.
 
template<typename T , std::enable_if_t< std::is_same< T, Scalar >::value||std::is_same< T, float >::value||std::is_same< T, double >::value, int > = 0>
 RotationMatrix (const T(&data)[9])
 
template<typename T , std::enable_if_t< std::is_same< T, Scalar >::value||std::is_same< T, float >::value||std::is_same< T, double >::value, int > = 0>
 RotationMatrix (const T(&data)[3][3])
 
Eigen::Matrix< Scalar, 3, 3 > operator- () const
 计算旋转矩阵的转置(逆矩阵)。 Computes the transpose (inverse) of the rotation matrix.
 
RotationMatrix & operator= (const RotationMatrix &R)
 赋值运算符,将 RotationMatrix 赋值给当前对象。 Overloaded assignment operator to assign a RotationMatrix to the current object.
 
RotationMatrix & operator= (const Eigen::Matrix< Scalar, 3, 3 > &R)
 
RotationMatrix & operator= (const Eigen::Quaternion< Scalar > &q)
 
RotationMatrix & operator= (const Quaternion< Scalar > &q)
 
Position< Scalar > operator* (const Position< Scalar > &p) const
 
Eigen::Matrix< Scalar, 3, 1 > operator* (const Eigen::Matrix< Scalar, 3, 1 > &p) const
 计算旋转矩阵与三维向量的乘积。 Computes the product of the rotation matrix and a 3D vector.
 
RotationMatrix operator* (const RotationMatrix &rhs) const
 计算两个旋转矩阵的乘积。 Computes the product of two rotation matrices.
 
Eigen::Matrix< Scalar, 3, 1 > ToEulerAngle () const
 将旋转矩阵转换为欧拉角(默认使用 ZYX 顺序)。 Converts the rotation matrix to Euler angles (default ZYX order).
 
Eigen::Matrix< Scalar, 3, 1 > ToEulerAngleZYX () const
 
Eigen::Matrix< Scalar, 3, 1 > ToEulerAngleXZY () const
 
Eigen::Matrix< Scalar, 3, 1 > ToEulerAngleYZX () const
 
Eigen::Matrix< Scalar, 3, 1 > ToEulerAngleYXZ () const
 
Eigen::Matrix< Scalar, 3, 1 > ToEulerAngleZXY () const
 
Eigen::Matrix< Scalar, 3, 1 > ToEulerAngleXYZ () const
 

Detailed Description

template<typename Scalar>
class LibXR::RotationMatrix< Scalar >

旋转矩阵类,继承自 Eigen::Matrix<Scalar, 3, 3>。 Rotation matrix class, inheriting from Eigen::Matrix<Scalar, 3, 3>.

该类提供 3x3 旋转矩阵的构造、赋值、矩阵运算以及欧拉角转换等功能, 并支持从四元数构造旋转矩阵。 This class provides functionalities for constructing, assigning, operating on rotation matrices, and converting to Euler angles. It also supports constructing rotation matrices from quaternions.

Template Parameters
Scalar旋转矩阵元素的数据类型,如 float 或 double。 The data type of the rotation matrix elements, such as float or double.

Definition at line 622 of file transform.hpp.

Constructor & Destructor Documentation

◆ RotationMatrix() [1/7]

template<typename Scalar >
LibXR::RotationMatrix< Scalar >::RotationMatrix ( )
inline

默认构造函数,初始化单位旋转矩阵。 Default constructor initializing an identity rotation matrix.

Definition at line 629 of file transform.hpp.

629 : Eigen::Matrix<Scalar, 3, 3>()
630 {
631 (*this) << 1, 0, 0, 0, 1, 0, 0, 0, 1;
632 }

◆ RotationMatrix() [2/7]

template<typename Scalar >
LibXR::RotationMatrix< Scalar >::RotationMatrix ( Scalar r00,
Scalar r01,
Scalar r02,
Scalar r10,
Scalar r11,
Scalar r12,
Scalar r20,
Scalar r21,
Scalar r22 )
inline

通过 9 个矩阵元素的值构造旋转矩阵。 Constructs a rotation matrix using 9 matrix elements.

Parameters
r00第 0 行第 0 列元素 / Element at row 0, column 0
r01第 0 行第 1 列元素 / Element at row 0, column 1
r02第 0 行第 2 列元素 / Element at row 0, column 2
r10第 1 行第 0 列元素 / Element at row 1, column 0
r11第 1 行第 1 列元素 / Element at row 1, column 1
r12第 1 行第 2 列元素 / Element at row 1, column 2
r20第 2 行第 0 列元素 / Element at row 2, column 0
r21第 2 行第 1 列元素 / Element at row 2, column 1
r22第 2 行第 2 列元素 / Element at row 2, column 2

Definition at line 648 of file transform.hpp.

650 : Eigen::Matrix<Scalar, 3, 3>()
651 {
652 (*this) << r00, r01, r02, r10, r11, r12, r20, r21, r22;
653 }

◆ RotationMatrix() [3/7]

template<typename Scalar >
LibXR::RotationMatrix< Scalar >::RotationMatrix ( const Eigen::Matrix< Scalar, 3, 3 > & R)
inline

通过 Eigen 3x3 矩阵构造旋转矩阵。 Constructs a rotation matrix from an Eigen 3x3 matrix.

Parameters
R3x3 旋转矩阵 / The 3x3 rotation matrix.

Definition at line 661 of file transform.hpp.

661: Eigen::Matrix<Scalar, 3, 3>{R} {}

◆ RotationMatrix() [4/7]

template<typename Scalar >
LibXR::RotationMatrix< Scalar >::RotationMatrix ( const Eigen::Quaternion< Scalar > & q)
inline

通过 Eigen 四元数构造旋转矩阵。 Constructs a rotation matrix from an Eigen quaternion.

Parameters
qEigen 四元数 / The Eigen quaternion.

Definition at line 669 of file transform.hpp.

670 : Eigen::Matrix<Scalar, 3, 3>{q.toRotationMatrix()}
671 {
672 }

◆ RotationMatrix() [5/7]

template<typename Scalar >
LibXR::RotationMatrix< Scalar >::RotationMatrix ( const Quaternion< Scalar > & q)
inline

通过 Quaternion 四元数构造旋转矩阵。 Constructs a rotation matrix from a Quaternion object.

Parameters
qQuaternion 四元数 / The Quaternion object.

Definition at line 680 of file transform.hpp.

680{ *this = q.ToRotationMatrix(); }

◆ RotationMatrix() [6/7]

template<typename Scalar >
template<typename T , std::enable_if_t< std::is_same< T, Scalar >::value||std::is_same< T, float >::value||std::is_same< T, double >::value, int > = 0>
LibXR::RotationMatrix< Scalar >::RotationMatrix ( const T(&) data[9])
inline

Definition at line 686 of file transform.hpp.

686 : Eigen::Matrix<Scalar, 3, 3>()
687 {
688 (*this) << data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
689 data[8];
690 }

◆ RotationMatrix() [7/7]

template<typename Scalar >
template<typename T , std::enable_if_t< std::is_same< T, Scalar >::value||std::is_same< T, float >::value||std::is_same< T, double >::value, int > = 0>
LibXR::RotationMatrix< Scalar >::RotationMatrix ( const T(&) data[3][3])
inline

Definition at line 696 of file transform.hpp.

696 : Eigen::Matrix<Scalar, 3, 3>()
697 {
698 (*this) << data[0][0], data[0][1], data[0][2], data[1][0], data[1][1], data[1][2],
699 data[2][0], data[2][1], data[2][2];
700 }

Member Function Documentation

◆ operator*() [1/3]

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::RotationMatrix< Scalar >::operator* ( const Eigen::Matrix< Scalar, 3, 1 > & p) const
inline

计算旋转矩阵与三维向量的乘积。 Computes the product of the rotation matrix and a 3D vector.

Parameters
p输入的三维位置向量 / The input 3D position vector.
Returns
旋转后的三维向量 / The rotated 3D vector.

Definition at line 774 of file transform.hpp.

775 {
776 return static_cast<Eigen::Matrix<Scalar, 3, 3>>(*this) * p;
777 }

◆ operator*() [2/3]

template<typename Scalar >
Position< Scalar > LibXR::RotationMatrix< Scalar >::operator* ( const Position< Scalar > & p) const
inline

Definition at line 762 of file transform.hpp.

763 {
764 return Position<Scalar>((*this) * Eigen::Matrix<Scalar, 3, 1>(p));
765 }

◆ operator*() [3/3]

template<typename Scalar >
RotationMatrix LibXR::RotationMatrix< Scalar >::operator* ( const RotationMatrix< Scalar > & rhs) const
inline

计算两个旋转矩阵的乘积。 Computes the product of two rotation matrices.

Parameters
rhs另一个旋转矩阵 / The second rotation matrix.
Returns
两个旋转矩阵的乘积 / The product of the two rotation matrices.

Definition at line 786 of file transform.hpp.

787 {
788 const Eigen::Matrix<Scalar, 3, 3>& a =
789 static_cast<const Eigen::Matrix<Scalar, 3, 3>&>(*this);
790 const Eigen::Matrix<Scalar, 3, 3>& b =
791 static_cast<const Eigen::Matrix<Scalar, 3, 3>&>(rhs);
792 return RotationMatrix(a * b);
793 }
RotationMatrix()
默认构造函数,初始化单位旋转矩阵。 Default constructor initializing an identity rotation matrix.

◆ operator-()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 3 > LibXR::RotationMatrix< Scalar >::operator- ( ) const
inline

计算旋转矩阵的转置(逆矩阵)。 Computes the transpose (inverse) of the rotation matrix.

Returns
旋转矩阵的转置 / The transposed rotation matrix.

Definition at line 708 of file transform.hpp.

708{ return this->transpose(); }

◆ operator=() [1/4]

template<typename Scalar >
RotationMatrix & LibXR::RotationMatrix< Scalar >::operator= ( const Eigen::Matrix< Scalar, 3, 3 > & R)
inline

Definition at line 736 of file transform.hpp.

737 {
738 this->data()[0] = R.data()[0];
739 this->data()[1] = R.data()[1];
740 this->data()[2] = R.data()[2];
741 this->data()[3] = R.data()[3];
742 this->data()[4] = R.data()[4];
743 this->data()[5] = R.data()[5];
744 this->data()[6] = R.data()[6];
745 this->data()[7] = R.data()[7];
746 this->data()[8] = R.data()[8];
747 return *this;
748 }

◆ operator=() [2/4]

template<typename Scalar >
RotationMatrix & LibXR::RotationMatrix< Scalar >::operator= ( const Eigen::Quaternion< Scalar > & q)
inline

Definition at line 750 of file transform.hpp.

751 {
752 *this = q.toRotationMatrix();
753 return *this;
754 }

◆ operator=() [3/4]

template<typename Scalar >
RotationMatrix & LibXR::RotationMatrix< Scalar >::operator= ( const Quaternion< Scalar > & q)
inline

Definition at line 756 of file transform.hpp.

757 {
758 *this = q.ToRotationMatrix();
759 return *this;
760 }

◆ operator=() [4/4]

template<typename Scalar >
RotationMatrix & LibXR::RotationMatrix< Scalar >::operator= ( const RotationMatrix< Scalar > & R)
inline

赋值运算符,将 RotationMatrix 赋值给当前对象。 Overloaded assignment operator to assign a RotationMatrix to the current object.

Parameters
R需要赋值的旋转矩阵 / The rotation matrix to be assigned.
Returns
返回赋值后的 RotationMatrix 对象引用。 Returns a reference to the assigned RotationMatrix object.

Definition at line 719 of file transform.hpp.

720 {
721 if (this != &R)
722 {
723 this->data()[0] = R.data()[0];
724 this->data()[1] = R.data()[1];
725 this->data()[2] = R.data()[2];
726 this->data()[3] = R.data()[3];
727 this->data()[4] = R.data()[4];
728 this->data()[5] = R.data()[5];
729 this->data()[6] = R.data()[6];
730 this->data()[7] = R.data()[7];
731 this->data()[8] = R.data()[8];
732 }
733 return *this;
734 }

◆ ToEulerAngle()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::RotationMatrix< Scalar >::ToEulerAngle ( ) const
inline

将旋转矩阵转换为欧拉角(默认使用 ZYX 顺序)。 Converts the rotation matrix to Euler angles (default ZYX order).

该方法调用 ToEulerAngleZYX() 方法,使用 ZYX(航向-俯仰-横滚)顺序转换欧拉角。 This method calls ToEulerAngleZYX(), converting to Euler angles in the ZYX (yaw-pitch-roll) order.

Returns
三个欧拉角(roll, pitch, yaw) / The three Euler angles (roll, pitch, yaw).

Definition at line 805 of file transform.hpp.

805{ return ToEulerAngleZYX(); }

◆ ToEulerAngleXYZ()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::RotationMatrix< Scalar >::ToEulerAngleXYZ ( ) const
inline

Definition at line 862 of file transform.hpp.

863 {
864 const Eigen::Matrix<Scalar, 3, 3>& r = (*this);
865
866 Scalar yaw = std::atan2(-r(0, 1), r(0, 0));
867 Scalar pitch = std::asin(r(0, 2));
868 Scalar roll = std::atan2(-r(1, 2), r(2, 2));
869
870 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
871 }

◆ ToEulerAngleXZY()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::RotationMatrix< Scalar >::ToEulerAngleXZY ( ) const
inline

Definition at line 818 of file transform.hpp.

819 {
820 const Eigen::Matrix<Scalar, 3, 3>& r = (*this);
821
822 Scalar roll = std::atan2(r(2, 1), r(1, 1));
823 Scalar yaw = std::asin(-r(0, 1));
824 Scalar pitch = std::atan2(r(0, 2), r(0, 0));
825
826 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
827 }

◆ ToEulerAngleYXZ()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::RotationMatrix< Scalar >::ToEulerAngleYXZ ( ) const
inline

Definition at line 840 of file transform.hpp.

841 {
842 const Eigen::Matrix<Scalar, 3, 3>& r = (*this);
843
844 Scalar pitch = std::atan2(r(0, 2), r(2, 2));
845 Scalar roll = std::asin(-r(1, 2));
846 Scalar yaw = std::atan2(r(1, 0), r(1, 1));
847
848 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
849 }

◆ ToEulerAngleYZX()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::RotationMatrix< Scalar >::ToEulerAngleYZX ( ) const
inline

Definition at line 829 of file transform.hpp.

830 {
831 const Eigen::Matrix<Scalar, 3, 3>& r = (*this);
832
833 Scalar pitch = std::atan2(-r(2, 0), r(0, 0));
834 Scalar yaw = std::asin(r(1, 0));
835 Scalar roll = std::atan2(-r(1, 2), r(1, 1));
836
837 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
838 }

◆ ToEulerAngleZXY()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::RotationMatrix< Scalar >::ToEulerAngleZXY ( ) const
inline

Definition at line 851 of file transform.hpp.

852 {
853 const Eigen::Matrix<Scalar, 3, 3>& r = (*this);
854
855 Scalar roll = std::asin(r(2, 1));
856 Scalar yaw = std::atan2(-r(0, 1), r(1, 1));
857 Scalar pitch = std::atan2(-r(2, 0), r(2, 2));
858
859 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
860 }

◆ ToEulerAngleZYX()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::RotationMatrix< Scalar >::ToEulerAngleZYX ( ) const
inline

Definition at line 807 of file transform.hpp.

808 {
809 const Eigen::Matrix<Scalar, 3, 3>& r = (*this);
810
811 Scalar roll = std::atan2(r(2, 1), r(2, 2));
812 Scalar yaw = std::atan2(r(1, 0), r(0, 0));
813 Scalar pitch = std::asin(-r(2, 0));
814
815 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
816 }

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