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(&data)[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(&data)[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(&data)[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 22 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(&)  data[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 41 of file inertia.hpp.

41 : mass(m)
42 {
43 for (int i = 0; i < 3; i++)
44 {
45 for (int j = 0; j < 3; j++)
46 {
47 data[i * 3 + j] = static_cast<Scalar>(data[i + j + 3]);
48 }
49 }
50 }
Scalar mass
质量值。Mass value.
Definition inertia.hpp:27
Scalar data[9]
Definition inertia.hpp:25
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

◆ 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(&)  data[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 64 of file inertia.hpp.

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

◆ 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 79 of file inertia.hpp.

79: 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(&)  data[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 91 of file inertia.hpp.

92 : data{data[0], -data[3], -data[5], -data[3], data[2],
93 -data[4], -data[5], -data[4], data[2]},
94 mass(m)
95 {
96 }

◆ 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 105 of file inertia.hpp.

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

◆ 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 116 of file inertia.hpp.

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

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 122 of file inertia.hpp.

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

◆ 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 129 of file inertia.hpp.

129{ 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 134 of file inertia.hpp.

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

◆ 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 160 of file inertia.hpp.

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

◆ 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 194 of file inertia.hpp.

196 {
197 return q * R * q.conjugate();
198 }

◆ 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 182 of file inertia.hpp.

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

◆ 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 206 of file inertia.hpp.

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

◆ 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 172 of file inertia.hpp.

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

◆ 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 144 of file inertia.hpp.

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

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 25 of file inertia.hpp.

◆ mass

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

质量值。Mass value.

Definition at line 27 of file inertia.hpp.


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