9#include "transform.hpp"
14using DefaultScalar = LIBXR_DEFAULT_SCALAR;
23template <
typename Scalar = DefaultScalar>
39 template <typename T, std::enable_if_t<std::is_same<T, Scalar>::value ||
40 std::is_same<T, float>::value ||
41 std::is_same<T, double>::value,
45 for (
int i = 0; i < 3; i++)
47 for (
int j = 0; j < 3; j++)
49 data[i * 3 + j] =
static_cast<Scalar
>(values[i * 3 + j]);
62 template <typename T, std::enable_if_t<std::is_same<T, Scalar>::value ||
63 std::is_same<T, float>::value ||
64 std::is_same<T, double>::value,
68 for (
int i = 0; i < 3; i++)
70 for (
int j = 0; j < 3; j++)
72 data[i * 3 + j] =
static_cast<Scalar
>(matrix[i][j]);
92 std::is_same<T, float>::value || std::is_same<T, double>::value,
int> = 0>
93 explicit Inertia(Scalar m,
const T (&arr)[6])
94 :
data{arr[0], -arr[3], -arr[5], -arr[3], arr[1],
95 -arr[4], -arr[5], -arr[4], arr[2]},
107 Inertia(Scalar m, Scalar xx, Scalar yy, Scalar zz, Scalar xy, Scalar yz, Scalar xz)
108 :
data{xx, -xy, -xz, -xy, yy, -yz, -xz, -yz, zz},
mass(m)
120 memcpy(
data, R.data(), 9 *
sizeof(Scalar));
124 operator Eigen::Matrix<Scalar, 3, 3>()
const
126 return Eigen::Map<const Eigen::Matrix<Scalar, 3, 3>>(
data);
136 Eigen::Matrix<Scalar, 3, 3>
operator+(
const Eigen::Matrix<Scalar, 3, 3> &R)
const
138 return Eigen::Map<const Eigen::Matrix<Scalar, 3, 3>>(
data) + R;
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;
153 return Inertia(
mass, Eigen::Map<
const Eigen::Matrix<Scalar, 3, 3>>(
data) +
154 mass * translation_matrix);
165 mass, R * Eigen::Map<
const Eigen::Matrix<Scalar, 3, 3>>(
data) * R.transpose());
176 return Rotate(Eigen::Map<
const Eigen::Matrix<Scalar, 3, 3>>(R.data_));
187 mass, q * Eigen::Map<
const Eigen::Matrix<Scalar, 3, 3>>(
data) * q.conjugate());
196 static Eigen::Matrix<Scalar, 3, 3>
Rotate(
const Eigen::Matrix<Scalar, 3, 3> &R,
197 const Eigen::Quaternion<Scalar> &q)
199 return q * R * q.conjugate();
210 return Rotate(Eigen::Quaternion<Scalar>(q));
219template <
typename Scalar = DefaultScalar>
质心信息表示类。Represents the center of mass information.
CenterOfMass()
默认构造函数,初始化质心位置为 (0,0,0),质量为 0。Default constructor initializing position to (0,0,0) and mass to 0.
CenterOfMass(Scalar m, const Eigen::Matrix< Scalar, 3, 1 > &p)
使用质量和 Eigen 3D 向量构造质心对象。Constructs a center of mass object using mass and Eigen 3D vector.
Eigen::Matrix< Scalar, 3, 1 > position
质心位置。Center of mass position.
CenterOfMass & operator+=(const CenterOfMass &m)
质心累加运算符。Accumulation operator for center of mass.
CenterOfMass(const Inertia< Scalar > &m, const Transform< Scalar > &p)
从惯性对象和变换构造质心对象。Constructs a center of mass object from inertia and transformation.
CenterOfMass(Scalar m, const LibXR::Position< Scalar > &p)
使用质量和位置构造质心对象。Constructs a center of mass object using mass and position.
Scalar mass
质量值。Mass value.
CenterOfMass operator+(const CenterOfMass &m) const
计算两个质心的合成。Computes the combined center of mass.
表示刚体的惯性张量和质量信息的类。Provides a class to represent the inertia tensor and mass of a rigid body.
Inertia(Scalar m, const T(&values)[9])
使用质量和 3x3 惯性张量数组构造惯性对象。Constructs an inertia object using mass and a 3x3 inertia tensor array.
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 Rotate(const Quaternion< Scalar > &q) const
使用自定义 Quaternion 旋转惯性张量。Rotates the inertia tensor using a custom Quaternion.
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.
Scalar mass
质量值。Mass value.
Inertia Rotate(const RotationMatrix< Scalar > &R) const
使用 RotationMatrix 旋转惯性张量。Rotates the inertia tensor using a RotationMatrix.
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.
Inertia(Scalar m, const T(&arr)[6])
使用质量和 6 维数组(对称惯性矩阵)构造惯性对象。Constructs an inertia object using mass and a 6-element symmetric inertia m...
Inertia Rotate(const Eigen::Quaternion< Scalar > &q) const
使用四元数旋转惯性张量。Rotates the inertia tensor using a quaternion.
Scalar operator()(int i, int j) const
获取惯性张量中的特定元素。Retrieves a specific element from the inertia tensor.
Inertia Rotate(const Eigen::Matrix< Scalar, 3, 3 > &R) const
旋转惯性张量。Rotates the inertia tensor.
Inertia Translate(const Eigen::Matrix< Scalar, 3, 1 > &p) const
平移惯性对象。Translates the inertia object.
Eigen::Matrix< Scalar, 3, 3 > operator+(const Eigen::Matrix< Scalar, 3, 3 > &R) const
将惯性张量与另一个 3x3 矩阵相加。Adds the inertia tensor with another 3x3 matrix.
Inertia(Scalar m, const Eigen::Matrix< Scalar, 3, 3 > &R)
使用 Eigen 3x3 矩阵构造惯性对象。Constructs an inertia object using an Eigen 3x3 matrix.
三维空间中的位置向量 / 3D position vector
四元数表示与运算,继承自 Eigen::Quaternion / Quaternion representation and operations, inheriting from Eigen::Qua...
旋转矩阵类,继承自 Eigen::Matrix<Scalar, 3, 3>。 Rotation matrix class, inheriting from Eigen::Matrix<Scalar,...