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

602 : Eigen::Matrix<Scalar, 3, 3>()
603 {
604 (*this) << 1, 0, 0, 0, 1, 0, 0, 0, 1;
605 }

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

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

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

626: 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 634 of file transform.hpp.

635 : Eigen::Matrix<Scalar, 3, 3>{q.ToRotationMatrix()}
636 {
637 }

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

645{ *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 651 of file transform.hpp.

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

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

661 : Eigen::Matrix<Scalar, 3, 3>()
662 {
663 (*this) << data[0][0], data[0][1], data[0][2], data[1][0], data[1][1], data[1][2],
664 data[2][0], data[2][1], data[2][2];
665 }

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

740 {
741 return static_cast<Eigen::Matrix<Scalar, 3, 3>>(*this) * p;
742 }

◆ operator*() [2/2]

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

Definition at line 727 of file transform.hpp.

728 {
729 return Position<Scalar>((*this) * Eigen::Matrix<Scalar, 3, 1>(p));
730 }

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

673{ 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 701 of file transform.hpp.

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

◆ operator=() [2/4]

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

Definition at line 715 of file transform.hpp.

716 {
717 *this = q.ToRotationMatrix();
718 return *this;
719 }

◆ operator=() [3/4]

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

Definition at line 721 of file transform.hpp.

722 {
723 *this = q.ToRotationMatrix();
724 return *this;
725 }

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

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

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

754{ return ToEulerAngleZYX(); }

◆ ToEulerAngleXYZ()

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

Definition at line 811 of file transform.hpp.

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

◆ ToEulerAngleXZY()

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

Definition at line 767 of file transform.hpp.

768 {
769 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
770
771 Scalar roll = std::atan2(r(2, 1), r(1, 1));
772 Scalar yaw = std::asin(-r(0, 1));
773 Scalar pitch = std::atan2(r(0, 2), r(0, 0));
774
775 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
776 }

◆ ToEulerAngleYXZ()

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

Definition at line 789 of file transform.hpp.

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

◆ ToEulerAngleYZX()

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

Definition at line 778 of file transform.hpp.

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

◆ ToEulerAngleZXY()

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

Definition at line 800 of file transform.hpp.

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

◆ ToEulerAngleZYX()

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

Definition at line 756 of file transform.hpp.

757 {
758 const Eigen::Matrix<Scalar, 3, 3> &r = (*this);
759
760 Scalar roll = std::atan2(r(2, 1), r(2, 2));
761 Scalar yaw = std::atan2(r(1, 0), r(0, 0));
762 Scalar pitch = std::asin(-r(2, 0));
763
764 return Eigen::Matrix<Scalar, 3, 1>(roll, pitch, yaw);
765 }

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