AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
MassProperties.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agx/agx.h>
20#include <agx/Vec3.h>
21#include <agx/SPDMatrix3x3.h>
24
25
26namespace agx
27{
28
40 {
41 public:
42
48 AUTO_GENERATE_NONE = 0x0,
49 MASS = 0x1,
50 CM_OFFSET = 0x2,
51 INERTIA = 0x4,
52 AUTO_GENERATE_ALL = MASS | CM_OFFSET | INERTIA
53 };
54
55
60
71 bool setMass( Real m, bool autoGenerate = false );
72
76 inline Real getMass() const;
77
81 inline const Real& getInvMass() const;
82
92 bool setInertiaTensor( const SPDMatrix3x3& m, bool autoGenerate = false);
93
103 bool setInertiaTensor( const Vec3& inertiaDiagonal, bool autoGenerate = false);
104
108 Vec3 getInvMassVector() const;
109
113 SPDMatrix3x3 getInvMassMatrix() const;
114
118 const SPDMatrix3x3& getInertiaTensor() const;
119
128 void setAutoGenerateMask(uint32_t mask);
129
133 agx::UInt32 getAutoGenerateMask() const;
134
138 Vec3 getPrincipalInertiae() const;
139
149 bool setMassCoefficients( const Vec3& coefficients );
150
154 const Vec3& getMassCoefficients( ) const;
155
159 const Vec3& getEffectiveMass() const;
160
170 bool setInertiaTensorCoefficients( const Vec3& coefficients );
171
175 const Vec3& getInertiaTensorCoefficients() const;
176
181 const SPDMatrix3x3& getEffectiveInertiaTensor() const;
182
187
192
203 void setEffectiveMassTransformDiagonal( const Vec3& effectiveMassTransformDiagonal );
204
208 const Vec3& getEffectiveMassTransformDiagonal() const;
209
210
212 MassProperties& operator= (const MassProperties& copy);
213
216
218
219
221
222
223 public:
227 static Matrix3x3 calculateOffsetTensor( const Matrix3x3& matrix, const Vec3& v, Real mass );
228
230 void setDefaultValues();
231
233
234 private:
236 friend class RigidBody;
237
238 MassProperties(const MassProperties& copy);
239
240
241 private:
242
243 agx::UInt32 m_autoGenerateMask;
244 agx::Physics::RigidBodyPtr m_entity;
245 };
246
247
248 /* Implementation */
249
250
252 inline Matrix3x3 MassProperties::calculateOffsetTensor(const Matrix3x3& matrix, const Vec3& v, Real mass)
253 {
254 Real xx, xy, xz, yz, yy, zz, xtx;
255
256 xx = v[0] * v[0];
257 xy = v[0] * v[1];
258 xz = v[0] * v[2];
259
260 yy = v[1] * v[1];
261 yz = v[1] * v[2];
262
263 zz = v[2] * v[2];
264
265 xtx = v.length2();
266
267 Matrix3x3 tmp(xtx - xx, -xy, -xz,
268 -xy, xtx - yy, -yz,
269 -xz, -yz, xtx - zz);
270
271 tmp *= mass;
272
273 return matrix + tmp;
274 }
276
277 inline Real MassProperties::getMass() const
278 {
279 agxAssert(m_entity.isValid());
280 return m_entity.mass();
281 }
282
283
284 inline const Vec3& MassProperties::getEffectiveMass() const
285 {
286 agxAssert(m_entity.isValid());
287 return m_entity.effectiveMass();
288 }
289
290 inline const Vec3& MassProperties::getMassCoefficients( ) const
291 {
292 agxAssert(m_entity.isValid());
293 return m_entity.effectiveMassCoefficients();
294 }
295
296 inline const Vec3& MassProperties::getInertiaTensorCoefficients() const
297 {
298 agxAssert(m_entity.isValid());
299 return m_entity.effectiveInertiaCoefficients();
300 }
301
302 inline agx::UInt32 MassProperties::getAutoGenerateMask() const
303 {
304 return m_autoGenerateMask;
305 }
306
307 inline const SPDMatrix3x3& MassProperties::getInertiaTensor() const
308 {
309 agxAssert(m_entity.isValid());
310 return m_entity.inertia();
311 }
312
313 inline const SPDMatrix3x3& MassProperties::getEffectiveInertiaTensor() const
314 {
315 agxAssert(m_entity.isValid());
316 return m_entity.effectiveInertia();
317 }
318
319 inline const Vec3& MassProperties::getEffectiveMassTransformDiagonal() const
320 {
321 agxAssert(m_entity.isValid());
322 return m_entity.effectiveMassTransformDiagonal();
323 }
324
325
326 inline Vec3 MassProperties::getPrincipalInertiae() const
327 {
328 agxAssert(m_entity.isValid());
329 return m_entity.inertia().getDiagonal();
330 }
331
332 inline const Real& MassProperties::getInvMass() const
333 {
334 agxAssert(m_entity.isValid());
335 return m_entity.invMass();
336 }
337
338 inline Vec3 MassProperties::getInvMassVector() const
339 {
340 agxAssert(m_entity.isValid());
341 return Vec3(m_entity.invMass(), m_entity.invMass(), m_entity.invMass());
342 }
343
344 inline SPDMatrix3x3 MassProperties::getInvMassMatrix() const
345 {
346 agxAssert(m_entity.isValid());
347 return SPDMatrix3x3( Vec3(m_entity.invMass(), m_entity.invMass(), m_entity.invMass()) );
348 }
349
350} // namespace agx
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
#define AGXPHYSICS_EXPORT
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Class for rigid body inertia tensor and mass.
MassProperties(agx::Physics::RigidBodyPtr entity)
Constructor (for internal use) which associates this object to the storage for a RigidBody.
bool setMass(Real m, bool autoGenerate=false)
Set the mass.
Vec3 getEffectiveInvMassVector() const
void setAutoGenerateMask(uint32_t mask)
Specify which parameters should be automatically calculated from the geometries of the body given a b...
bool setMassCoefficients(const Vec3 &coefficients)
Set mass coefficients.
bool setInertiaTensorCoefficients(const Vec3 &coefficients)
Set inertia tensor coefficients.
SPDMatrix3x3 getEffectiveInvMassMatrix() const
void setEffectiveMassTransformDiagonal(const Vec3 &effectiveMassTransformDiagonal)
Set the transform to transform the effective coefficients to the body/mass frame.
bool setInertiaTensor(const Vec3 &inertiaDiagonal, bool autoGenerate=false)
Set the inertia tensor given the diagonal.
virtual ~MassProperties()
Destructor.
bool setInertiaTensor(const SPDMatrix3x3 &m, bool autoGenerate=false)
Set the inertia tensor as a full 3x3 tensor matrix.
AutoGenerateFlags
Specifies a bit mask for controlling what should be automatically calculated when a body/geometry is ...
Pointer to a entity instance of type Physics.RigidBody.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:49
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
double Real
Definition: Real.h:41