libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Inertia< Scalar > Class Template Reference

表示刚体的惯性张量和质量信息的类。Provides a class to represent the inertia tensor and mass of a rigid body. More...

#include <inertia.hpp>

Public Member Functions

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>
 Inertia (Scalar m, const T(&values)[9])
 使用质量和 3x3 惯性张量数组构造惯性对象。Constructs an inertia object using mass and a 3x3 inertia tensor array.
 
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>
 Inertia (Scalar m, const T(&matrix)[3][3])
 使用质量和二维 3x3 数组构造惯性对象。Constructs an inertia object using mass and a 3x3 matrix.
 
 Inertia ()
 默认构造函数,初始化质量为0,惯性张量为零矩阵。Default constructor initializing mass to 0 and inertia tensor to zero.
 
template<typename T , std::enable_if_t< std::is_same< T, float >::value||std::is_same< T, double >::value, int > = 0>
 Inertia (Scalar m, const T(&arr)[6])
 使用质量和 6 维数组(对称惯性矩阵)构造惯性对象。Constructs an inertia object using mass and a 6-element symmetric inertia matrix.
 
 Inertia (Scalar m, Scalar xx, Scalar yy, Scalar zz, Scalar xy, Scalar yz, Scalar xz)
 直接指定质量和惯性张量分量构造惯性对象。Constructs an inertia object with mass and specified inertia tensor elements.
 
 Inertia (Scalar m, const Eigen::Matrix< Scalar, 3, 3 > &R)
 使用 Eigen 3x3 矩阵构造惯性对象。Constructs an inertia object using an Eigen 3x3 matrix.
 
 operator Eigen::Matrix< Scalar, 3, 3 > () const
 转换为 Eigen 3x3 矩阵。Converts to an Eigen 3x3 matrix.
 
Scalar operator() (int i, int j) const
 获取惯性张量中的特定元素。Retrieves a specific element from the inertia tensor.
 
Eigen::Matrix< Scalar, 3, 3 > operator+ (const Eigen::Matrix< Scalar, 3, 3 > &R) const
 将惯性张量与另一个 3x3 矩阵相加。Adds the inertia tensor with another 3x3 matrix.
 
Inertia Translate (const Eigen::Matrix< Scalar, 3, 1 > &p) const
 平移惯性对象。Translates the inertia object.
 
Inertia Rotate (const Eigen::Matrix< Scalar, 3, 3 > &R) const
 旋转惯性张量。Rotates the inertia tensor.
 
Inertia Rotate (const RotationMatrix< Scalar > &R) const
 使用 RotationMatrix 旋转惯性张量。Rotates the inertia tensor using a RotationMatrix.
 
Inertia Rotate (const Eigen::Quaternion< Scalar > &q) const
 使用四元数旋转惯性张量。Rotates the inertia tensor using a quaternion.
 
Inertia Rotate (const Quaternion< Scalar > &q) const
 使用自定义 Quaternion 旋转惯性张量。Rotates the inertia tensor using a custom Quaternion.
 

Static Public Member Functions

static Eigen::Matrix< Scalar, 3, 3 > Rotate (const Eigen::Matrix< Scalar, 3, 3 > &R, const Eigen::Quaternion< Scalar > &q)
 使用四元数旋转 3x3 矩阵。Rotates a 3x3 matrix using a quaternion.
 

Data Fields

Scalar data [9]
 
Scalar mass
 质量值。Mass value.
 

Detailed Description

template<typename Scalar = DefaultScalar>
class LibXR::Inertia< Scalar >

表示刚体的惯性张量和质量信息的类。Provides a class to represent the inertia tensor and mass of a rigid body.

Template Parameters
Scalar数据类型,默认为 DefaultScalar。The data type, defaulting to DefaultScalar.

Definition at line 24 of file inertia.hpp.

Constructor & Destructor Documentation

◆ Inertia() [1/6]

template<typename Scalar = DefaultScalar>
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::Inertia< Scalar >::Inertia ( Scalar m,
const T(&) values[9] )
inlineexplicit

使用质量和 3x3 惯性张量数组构造惯性对象。Constructs an inertia object using mass and a 3x3 inertia tensor array.

Template Parameters
T数据类型,支持 Scalar、float 或 double。Data type, supporting Scalar, float, or double.
Parameters
m质量值。Mass value.
data3x3 惯性张量数组。3x3 inertia tensor array.

Definition at line 43 of file inertia.hpp.

43 : mass(m)
44 {
45 for (int i = 0; i < 3; i++)
46 {
47 for (int j = 0; j < 3; j++)
48 {
49 data[i * 3 + j] = static_cast<Scalar>(values[i * 3 + j]);
50 }
51 }
52 }
Scalar mass
质量值。Mass value.
Definition inertia.hpp:29
Scalar data[9]
Definition inertia.hpp:27

◆ Inertia() [2/6]

template<typename Scalar = DefaultScalar>
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::Inertia< Scalar >::Inertia ( Scalar m,
const T(&) matrix[3][3] )
inlineexplicit

使用质量和二维 3x3 数组构造惯性对象。Constructs an inertia object using mass and a 3x3 matrix.

Template Parameters
T数据类型,支持 Scalar、float 或 double。Data type, supporting Scalar, float, or double.
Parameters
m质量值。Mass value.
data3x3 惯性张量矩阵。3x3 inertia tensor matrix.

Definition at line 66 of file inertia.hpp.

66 : mass(m)
67 {
68 for (int i = 0; i < 3; i++)
69 {
70 for (int j = 0; j < 3; j++)
71 {
72 data[i * 3 + j] = static_cast<Scalar>(matrix[i][j]);
73 }
74 }
75 }

◆ Inertia() [3/6]

template<typename Scalar = DefaultScalar>
LibXR::Inertia< Scalar >::Inertia ( )
inline

默认构造函数,初始化质量为0,惯性张量为零矩阵。Default constructor initializing mass to 0 and inertia tensor to zero.

Definition at line 81 of file inertia.hpp.

81: mass(0) { memset(data, 0, sizeof(data)); }

◆ Inertia() [4/6]

template<typename Scalar = DefaultScalar>
template<typename T , std::enable_if_t< std::is_same< T, float >::value||std::is_same< T, double >::value, int > = 0>
LibXR::Inertia< Scalar >::Inertia ( Scalar m,
const T(&) arr[6] )
inlineexplicit

使用质量和 6 维数组(对称惯性矩阵)构造惯性对象。Constructs an inertia object using mass and a 6-element symmetric inertia matrix.

Template Parameters
T数据类型,支持 float 或 double。Data type, supporting float or double.
Parameters
m质量值。Mass value.
data6 维惯性张量数据。6-element inertia tensor data.

Definition at line 93 of file inertia.hpp.

94 : data{arr[0], -arr[3], -arr[5], -arr[3], arr[1],
95 -arr[4], -arr[5], -arr[4], arr[2]},
96 mass(m)
97 {
98 }

◆ Inertia() [5/6]

template<typename Scalar = DefaultScalar>
LibXR::Inertia< Scalar >::Inertia ( Scalar m,
Scalar xx,
Scalar yy,
Scalar zz,
Scalar xy,
Scalar yz,
Scalar xz )
inline

直接指定质量和惯性张量分量构造惯性对象。Constructs an inertia object with mass and specified inertia tensor elements.

Parameters
m质量值。Mass value.
xx,yy,zz主惯性矩。Principal moments of inertia.
xy,yz,xz交叉惯性矩。Cross moments of inertia.

Definition at line 107 of file inertia.hpp.

108 : data{xx, -xy, -xz, -xy, yy, -yz, -xz, -yz, zz}, mass(m)
109 {
110 }

◆ Inertia() [6/6]

template<typename Scalar = DefaultScalar>
LibXR::Inertia< Scalar >::Inertia ( Scalar m,
const Eigen::Matrix< Scalar, 3, 3 > & R )
inline

使用 Eigen 3x3 矩阵构造惯性对象。Constructs an inertia object using an Eigen 3x3 matrix.

Parameters
m质量值。Mass value.
R3x3 惯性张量矩阵。3x3 inertia tensor matrix.

Definition at line 118 of file inertia.hpp.

118 : mass(m)
119 {
120 memcpy(data, R.data(), 9 * sizeof(Scalar));
121 }

Member Function Documentation

◆ operator Eigen::Matrix< Scalar, 3, 3 >()

template<typename Scalar = DefaultScalar>
LibXR::Inertia< Scalar >::operator Eigen::Matrix< Scalar, 3, 3 > ( ) const
inline

转换为 Eigen 3x3 矩阵。Converts to an Eigen 3x3 matrix.

Definition at line 124 of file inertia.hpp.

125 {
126 return Eigen::Map<const Eigen::Matrix<Scalar, 3, 3>>(data);
127 }

◆ operator()()

template<typename Scalar = DefaultScalar>
Scalar LibXR::Inertia< Scalar >::operator() ( int i,
int j ) const
inline

获取惯性张量中的特定元素。Retrieves a specific element from the inertia tensor.

Definition at line 131 of file inertia.hpp.

131{ return data[i + j * 3]; }

◆ operator+()

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

将惯性张量与另一个 3x3 矩阵相加。Adds the inertia tensor with another 3x3 matrix.

Definition at line 136 of file inertia.hpp.

137 {
138 return Eigen::Map<const Eigen::Matrix<Scalar, 3, 3>>(data) + R;
139 }

◆ Rotate() [1/5]

template<typename Scalar = DefaultScalar>
Inertia LibXR::Inertia< Scalar >::Rotate ( const Eigen::Matrix< Scalar, 3, 3 > & R) const
inline

旋转惯性张量。Rotates the inertia tensor.

Parameters
R旋转矩阵。Rotation matrix.
Returns
旋转后的惯性张量。Rotated inertia tensor.

Definition at line 162 of file inertia.hpp.

163 {
164 return Inertia(
165 mass, R * Eigen::Map<const Eigen::Matrix<Scalar, 3, 3>>(data) * R.transpose());
166 }
Inertia()
默认构造函数,初始化质量为0,惯性张量为零矩阵。Default constructor initializing mass to 0 and inertia tensor to zero.
Definition inertia.hpp:81

◆ Rotate() [2/5]

template<typename Scalar = DefaultScalar>
static Eigen::Matrix< Scalar, 3, 3 > LibXR::Inertia< Scalar >::Rotate ( const Eigen::Matrix< Scalar, 3, 3 > & R,
const Eigen::Quaternion< Scalar > & q )
inlinestatic

使用四元数旋转 3x3 矩阵。Rotates a 3x3 matrix using a quaternion.

Parameters
R3x3 矩阵。3x3 matrix.
q四元数。Quaternion.
Returns
旋转后的矩阵。Rotated matrix.

Definition at line 196 of file inertia.hpp.

198 {
199 return q * R * q.conjugate();
200 }

◆ Rotate() [3/5]

template<typename Scalar = DefaultScalar>
Inertia LibXR::Inertia< Scalar >::Rotate ( const Eigen::Quaternion< Scalar > & q) const
inline

使用四元数旋转惯性张量。Rotates the inertia tensor using a quaternion.

Parameters
q四元数。Quaternion.
Returns
旋转后的惯性张量。Rotated inertia tensor.

Definition at line 184 of file inertia.hpp.

185 {
186 return Inertia(
187 mass, q * Eigen::Map<const Eigen::Matrix<Scalar, 3, 3>>(data) * q.conjugate());
188 }

◆ Rotate() [4/5]

template<typename Scalar = DefaultScalar>
Inertia LibXR::Inertia< Scalar >::Rotate ( const Quaternion< Scalar > & q) const
inline

使用自定义 Quaternion 旋转惯性张量。Rotates the inertia tensor using a custom Quaternion.

Parameters
q自定义四元数对象。Custom quaternion object.
Returns
旋转后的惯性张量。Rotated inertia tensor.

Definition at line 208 of file inertia.hpp.

209 {
210 return Rotate(Eigen::Quaternion<Scalar>(q));
211 }
Inertia Rotate(const Eigen::Matrix< Scalar, 3, 3 > &R) const
旋转惯性张量。Rotates the inertia tensor.
Definition inertia.hpp:162

◆ Rotate() [5/5]

template<typename Scalar = DefaultScalar>
Inertia LibXR::Inertia< Scalar >::Rotate ( const RotationMatrix< Scalar > & R) const
inline

使用 RotationMatrix 旋转惯性张量。Rotates the inertia tensor using a RotationMatrix.

Parameters
R旋转矩阵对象。Rotation matrix object.
Returns
旋转后的惯性张量。Rotated inertia tensor.

Definition at line 174 of file inertia.hpp.

175 {
176 return Rotate(Eigen::Map<const Eigen::Matrix<Scalar, 3, 3>>(R.data_));
177 }

◆ Translate()

template<typename Scalar = DefaultScalar>
Inertia LibXR::Inertia< Scalar >::Translate ( const Eigen::Matrix< Scalar, 3, 1 > & p) const
inline

平移惯性对象。Translates the inertia object.

Parameters
p平移向量。Translation vector.
Returns
平移后的惯性对象。Translated inertia object.

Definition at line 146 of file inertia.hpp.

147 {
148 Scalar dx = p(0), dy = p(1), dz = p(2);
149 Eigen::Matrix<Scalar, 3, 3> translation_matrix;
150 translation_matrix << dy * dy + dz * dz, -dx * dy, -dx * dz, -dx * dy,
151 dx * dx + dz * dz, -dy * dz, -dx * dz, -dy * dz, dx * dx + dy * dy;
152
153 return Inertia(mass, Eigen::Map<const Eigen::Matrix<Scalar, 3, 3>>(data) +
154 mass * translation_matrix);
155 }

Field Documentation

◆ data

template<typename Scalar = DefaultScalar>
Scalar LibXR::Inertia< Scalar >::data[9]

惯性张量数据,3x3 矩阵存储为一维数组。Inertia tensor data stored as a 3x3 matrix in a 1D array.

Definition at line 27 of file inertia.hpp.

◆ mass

template<typename Scalar = DefaultScalar>
Scalar LibXR::Inertia< Scalar >::mass

质量值。Mass value.

Definition at line 29 of file inertia.hpp.


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