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

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

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

605 : Eigen::Matrix<Scalar, 3, 3>()
606 {
607 (*this) << r00, r01, r02, r10, r11, r12, r20, r21, r22;
608 }

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

616: 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 624 of file transform.hpp.

625 : Eigen::Matrix<Scalar, 3, 3>{q.ToRotationMatrix()}
626 {
627 }

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

635{ *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 641 of file transform.hpp.

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

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

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

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

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

◆ operator*() [2/2]

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

Definition at line 701 of file transform.hpp.

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

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

663{ 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 683 of file transform.hpp.

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

◆ operator=() [2/4]

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

Definition at line 689 of file transform.hpp.

690 {
691 *this = q.ToRotationMatrix();
692 return *this;
693 }

◆ operator=() [3/4]

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

Definition at line 695 of file transform.hpp.

696 {
697 *this = q.ToRotationMatrix();
698 return *this;
699 }

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

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

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

728{ return ToEulerAngleZYX(); }

◆ ToEulerAngleXYZ()

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

Definition at line 785 of file transform.hpp.

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

◆ ToEulerAngleXZY()

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

Definition at line 741 of file transform.hpp.

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

◆ ToEulerAngleYXZ()

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

Definition at line 763 of file transform.hpp.

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

◆ ToEulerAngleYZX()

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

Definition at line 752 of file transform.hpp.

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

◆ ToEulerAngleZXY()

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

Definition at line 774 of file transform.hpp.

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

◆ ToEulerAngleZYX()

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

Definition at line 730 of file transform.hpp.

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

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