libxr  1.0
Want to be the best embedded framework
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.
 
RotationMatrixoperator= (const RotationMatrix &R)
 赋值运算符,将 RotationMatrix 赋值给当前对象。 Overloaded assignment operator to assign a RotationMatrix to the current object.
 
RotationMatrixoperator= (const Eigen::Matrix< Scalar, 3, 3 > &R)
 
RotationMatrixoperator= (const Eigen::Quaternion< Scalar > &q)
 
RotationMatrixoperator= (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旋转矩阵元素的数据类型,如 floatdouble。 The data type of the rotation matrix elements, such as float or double.

Definition at line 598 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 605 of file transform.hpp.

605 : Eigen::Matrix<Scalar, 3, 3>()
606 {
607 (*this) << 1, 0, 0, 0, 1, 0, 0, 0, 1;
608 }

◆ 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-r22矩阵各元素值。 Elements of the matrix.

Definition at line 616 of file transform.hpp.

618 : Eigen::Matrix<Scalar, 3, 3>()
619 {
620 (*this) << r00, r01, r02, r10, r11, r12, r20, r21, r22;
621 }

◆ 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 629 of file transform.hpp.

629: 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 637 of file transform.hpp.

638 : Eigen::Matrix<Scalar, 3, 3>{q.ToRotationMatrix()}
639 {
640 }

◆ 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 648 of file transform.hpp.

648{ *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 654 of file transform.hpp.

654 : Eigen::Matrix<Scalar, 3, 3>()
655 {
656 (*this) << data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
657 data[8];
658 }

◆ 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 664 of file transform.hpp.

664 : Eigen::Matrix<Scalar, 3, 3>()
665 {
666 (*this) << data[0][0], data[0][1], data[0][2], data[1][0], data[1][1], data[1][2],
667 data[2][0], data[2][1], data[2][2];
668 }

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 742 of file transform.hpp.

743 {
744 return static_cast<Eigen::Matrix<Scalar, 3, 3>>(*this) * p;
745 }

◆ operator*() [2/3]

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

Definition at line 730 of file transform.hpp.

731 {
732 return Position<Scalar>((*this) * Eigen::Matrix<Scalar, 3, 1>(p));
733 }

◆ 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 754 of file transform.hpp.

755 {
756 const Eigen::Matrix<Scalar, 3, 3> &a =
757 static_cast<const Eigen::Matrix<Scalar, 3, 3> &>(*this);
758 const Eigen::Matrix<Scalar, 3, 3> &b =
759 static_cast<const Eigen::Matrix<Scalar, 3, 3> &>(rhs);
760 return RotationMatrix(a * b);
761 }
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 676 of file transform.hpp.

676{ 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 704 of file transform.hpp.

705 {
706 this->data()[0] = R.data()[0];
707 this->data()[1] = R.data()[1];
708 this->data()[2] = R.data()[2];
709 this->data()[3] = R.data()[3];
710 this->data()[4] = R.data()[4];
711 this->data()[5] = R.data()[5];
712 this->data()[6] = R.data()[6];
713 this->data()[7] = R.data()[7];
714 this->data()[8] = R.data()[8];
715 return *this;
716 }

◆ operator=() [2/4]

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

Definition at line 718 of file transform.hpp.

719 {
720 *this = q.ToRotationMatrix();
721 return *this;
722 }

◆ operator=() [3/4]

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

Definition at line 724 of file transform.hpp.

725 {
726 *this = q.ToRotationMatrix();
727 return *this;
728 }

◆ 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 687 of file transform.hpp.

688 {
689 if (this != &R)
690 {
691 this->data()[0] = R.data()[0];
692 this->data()[1] = R.data()[1];
693 this->data()[2] = R.data()[2];
694 this->data()[3] = R.data()[3];
695 this->data()[4] = R.data()[4];
696 this->data()[5] = R.data()[5];
697 this->data()[6] = R.data()[6];
698 this->data()[7] = R.data()[7];
699 this->data()[8] = R.data()[8];
700 }
701 return *this;
702 }

◆ 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 773 of file transform.hpp.

773{ return ToEulerAngleZYX(); }

◆ ToEulerAngleXYZ()

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

Definition at line 830 of file transform.hpp.

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

◆ ToEulerAngleXZY()

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

Definition at line 786 of file transform.hpp.

787 {
788 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
789
790 Scalar roll = std::atan2(r(2, 1), r(1, 1));
791 Scalar yaw = std::asin(-r(0, 1));
792 Scalar pitch = std::atan2(r(0, 2), r(0, 0));
793
794 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
795 }

◆ ToEulerAngleYXZ()

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

Definition at line 808 of file transform.hpp.

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

◆ ToEulerAngleYZX()

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

Definition at line 797 of file transform.hpp.

798 {
799 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
800
801 Scalar pitch = std::atan2(-r(2, 0), r(0, 0));
802 Scalar yaw = std::asin(r(1, 0));
803 Scalar roll = std::atan2(-r(1, 2), r(1, 1));
804
805 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
806 }

◆ ToEulerAngleZXY()

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

Definition at line 819 of file transform.hpp.

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

◆ ToEulerAngleZYX()

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

Definition at line 775 of file transform.hpp.

776 {
777 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
778
779 Scalar roll = std::atan2(r(2, 1), r(2, 2));
780 Scalar yaw = std::atan2(r(1, 0), r(0, 0));
781 Scalar pitch = std::asin(-r(2, 0));
782
783 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
784 }

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