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 >:
Collaboration diagram for LibXR::RotationMatrix< Scalar >:

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< Scalaroperator* (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.
 
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 583 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 590 of file transform.hpp.

590 : Eigen::Matrix<Scalar, 3, 3>()
591 {
592 (*this) << 1, 0, 0, 0, 1, 0, 0, 0, 1;
593 }

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

603 : Eigen::Matrix<Scalar, 3, 3>()
604 {
605 (*this) << r00, r01, r02, r10, r11, r12, r20, r21, r22;
606 }
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

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

614: 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 622 of file transform.hpp.

623 : Eigen::Matrix<Scalar, 3, 3>{q.toRotationMatrix()}
624 {
625 }

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

633{ *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 639 of file transform.hpp.

639 : Eigen::Matrix<Scalar, 3, 3>()
640 {
641 (*this) << data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
642 data[8];
643 }

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

649 : Eigen::Matrix<Scalar, 3, 3>()
650 {
651 (*this) << data[0][0], data[0][1], data[0][2], data[1][0], data[1][1], data[1][2],
652 data[2][0], data[2][1], data[2][2];
653 }

Member Function Documentation

◆ operator*() [1/2]

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

712 {
713 return static_cast<Eigen::Matrix<Scalar, 3, 3>>(*this) * p;
714 }

◆ operator*() [2/2]

Definition at line 699 of file transform.hpp.

700 {
701 return Position<Scalar>((*this) * Eigen::Matrix<Scalar, 3, 1>(p));
702 }

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

661{ 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 681 of file transform.hpp.

682 {
683 memcpy(this->data(), R.data(), 9 * sizeof(Scalar));
684 return *this;
685 }

◆ operator=() [2/4]

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

Definition at line 687 of file transform.hpp.

688 {
689 *this = q.ToRotationMatrix();
690 return *this;
691 }

◆ operator=() [3/4]

Definition at line 693 of file transform.hpp.

694 {
695 *this = q.ToRotationMatrix();
696 return *this;
697 }

◆ operator=() [4/4]

赋值运算符,将 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 672 of file transform.hpp.

673 {
674 if (this != &R)
675 {
676 memcpy(this->data(), R.data(), 9 * sizeof(Scalar));
677 }
678 return *this;
679 }

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

726{ return ToEulerAngleZYX(); }

◆ ToEulerAngleXYZ()

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

Definition at line 783 of file transform.hpp.

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

◆ ToEulerAngleXZY()

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

Definition at line 739 of file transform.hpp.

740 {
741 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
742
743 Scalar roll = std::atan2(r(2, 1), r(1, 1));
744 Scalar yaw = std::asin(-r(0, 1));
745 Scalar pitch = std::atan2(r(0, 2), r(0, 0));
746
747 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
748 }

◆ ToEulerAngleYXZ()

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

Definition at line 761 of file transform.hpp.

762 {
763 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
764
765 Scalar pitch = std::atan2(r(0, 2), r(2, 2));
766 Scalar roll = std::asin(-r(1, 2));
767 Scalar yaw = std::atan2(r(1, 0), r(1, 1));
768
769 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
770 }

◆ ToEulerAngleYZX()

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

Definition at line 750 of file transform.hpp.

751 {
752 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
753
754 Scalar pitch = std::atan2(-r(2, 0), r(0, 0));
755 Scalar yaw = std::asin(r(1, 0));
756 Scalar roll = std::atan2(-r(1, 2), r(1, 1));
757
758 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
759 }

◆ ToEulerAngleZXY()

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

Definition at line 772 of file transform.hpp.

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

◆ ToEulerAngleZYX()

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

Definition at line 728 of file transform.hpp.

729 {
730 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
731
732 Scalar roll = std::atan2(r(2, 1), r(2, 2));
733 Scalar yaw = std::atan2(r(1, 0), r(0, 0));
734 Scalar pitch = std::asin(-r(2, 0));
735
736 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
737 }

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