5 #ifndef LIB_ALMATH_SCENEGRAPH_BODYMASS_H
6 #define LIB_ALMATH_SCENEGRAPH_BODYMASS_H
9 #include <boost/math/special_functions/pow.hpp>
16 template <
typename Scalar,
typename Derived0,
typename Derived1>
18 const Eigen::MatrixBase<Derived0> &position,
19 Eigen::MatrixBase<Derived1> &output) {
20 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived0, 3, 1)
21 EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived1, 3, 3)
23 (Eigen::internal::is_same<Scalar, typename Derived0::Scalar>::value),
24 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
26 (Eigen::internal::is_same<Scalar, typename Derived1::Scalar>::value),
27 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
28 typedef Eigen::Array<Scalar, 3, 1> Array3;
29 Array3 position2 = position.array().square();
30 output(0, 0) += mass * (position2[1] + position2[2]);
31 output(1, 1) += mass * (position2[0] + position2[2]);
32 output(2, 2) += mass * (position2[0] + position2[1]);
34 output(0, 1) += -mass * position[0] * position[1];
35 output(1, 0) += -mass * position[0] * position[1];
37 output(0, 2) += -mass * position[0] * position[2];
38 output(2, 0) += -mass * position[0] * position[2];
40 output(1, 2) += -mass * position[1] * position[2];
41 output(2, 1) += -mass * position[1] * position[2];
48 typedef Eigen::Matrix<Scalar, 3, 1, Eigen::DontAlign>
Vector3;
49 typedef Eigen::Matrix<Scalar, 3, 3, Eigen::DontAlign>
Matrix3;
59 return BodyMass{0, Vector3::Zero(), Matrix3::Zero()};
85 template <
typename T,
typename BodyMassRange>
93 mass += bodymass.mass;
94 center_of_mass += bodymass.mass * bodymass.center_of_mass;
96 if (mass != static_cast<Scalar>(0))
97 center_of_mass /=
mass;
101 rotational_inertia += bodymass.rotational_inertia;
103 center_of_mass - bodymass.center_of_mass,
110 template <
typename T>
118 if (mass != static_cast<Scalar>(0))
119 center_of_mass /=
mass;
125 center_of_mass - bodymass.center_of_mass,
void addPointMassInertia(Scalar mass, const Eigen::MatrixBase< Derived0 > &position, Eigen::MatrixBase< Derived1 > &output)
Matrix3 get_rotational_inertia_at(const Vector3 &point) const
BodyMass< T > operator+(const BodyMass< T > &lhs, const BodyMass< T > &rhs)
Eigen::Matrix< Scalar, 3, 3, Eigen::DontAlign > Matrix3
Eigen::Matrix< Scalar, 3, 1, Eigen::DontAlign > Vector3
BodyMass< S > cast() const
BodyMass< T > squashBodyMasses(const BodyMassRange &bodymasses)
bool operator==(const BodyMass< T > &lhs, const BodyMass< T > &rhs)
Matrix3 rotational_inertia