AGX Dynamics  2.35.0.1
MassProperties.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGX_MASSPROPERTIES_H
18 #define AGX_MASSPROPERTIES_H
19 
20 #include <agx/agx.h>
21 #include <agx/Vec3.h>
22 #include <agx/SPDMatrix3x3.h>
23 #include <agxStream/Serializable.h>
25 
26 
27 namespace agx
28 {
29 
41  {
42  public:
43 
49  AUTO_GENERATE_NONE = 0x0,
50  MASS = 0x1,
51  CM_OFFSET = 0x2,
52  INERTIA = 0x4,
53  AUTO_GENERATE_ALL = MASS | CM_OFFSET | INERTIA
54  };
55 
56 
61 
72  bool setMass( Real m, bool autoGenerate = false );
73 
77  inline Real getMass() const;
78 
82  inline const Real& getInvMass() const;
83 
93  bool setInertiaTensor( const SPDMatrix3x3& m, bool autoGenerate = false);
94 
104  bool setInertiaTensor( const Vec3& inertiaDiagonal, bool autoGenerate = false);
105 
109  Vec3 getInvMassVector() const;
110 
114  SPDMatrix3x3 getInvMassMatrix() const;
115 
119  const SPDMatrix3x3& getInertiaTensor() const;
120 
129  void setAutoGenerateMask(uint32_t mask);
130 
134  agx::UInt32 getAutoGenerateMask() const;
135 
139  Vec3 getPrincipalInertiae() const;
140 
150  bool setMassCoefficients( const Vec3& coefficients );
151 
155  const Vec3& getMassCoefficients( ) const;
156 
160  const Vec3& getEffectiveMass() const;
161 
171  bool setInertiaTensorCoefficients( const Vec3& coefficients );
172 
176  const Vec3& getInertiaTensorCoefficients() const;
177 
182  const SPDMatrix3x3& getEffectiveInertiaTensor() const;
183 
188 
193 
204  void setEffectiveMassTransformDiagonal( const Vec3& effectiveMassTransformDiagonal );
205 
209  const Vec3& getEffectiveMassTransformDiagonal() const;
210 
211 
213  MassProperties& operator= (const MassProperties& copy);
214 
216  virtual ~MassProperties();
217 
219 
220 
222 
223 
224  public:
228  static Matrix3x3 calculateOffsetTensor( const Matrix3x3& matrix, const Vec3& v, Real mass );
229 
231  void setDefaultValues();
232 
234 
235  private:
236  MassProperties();
237  friend class RigidBody;
238 
239  MassProperties(const MassProperties& copy);
240 
241 
242  private:
243 
244  agx::UInt32 m_autoGenerateMask;
245  agx::Physics::RigidBodyPtr m_entity;
246  };
247 
248 
249  /* Implementation */
250 
251 
253  inline Matrix3x3 MassProperties::calculateOffsetTensor(const Matrix3x3& matrix, const Vec3& v, Real mass)
254  {
255  Real xx, xy, xz, yz, yy, zz, xtx;
256 
257  xx = v[0] * v[0];
258  xy = v[0] * v[1];
259  xz = v[0] * v[2];
260 
261  yy = v[1] * v[1];
262  yz = v[1] * v[2];
263 
264  zz = v[2] * v[2];
265 
266  xtx = v.length2();
267 
268  Matrix3x3 tmp(xtx - xx, -xy, -xz,
269  -xy, xtx - yy, -yz,
270  -xz, -yz, xtx - zz);
271 
272  tmp *= mass;
273 
274  return matrix + tmp;
275  }
277 
278  inline Real MassProperties::getMass() const
279  {
280  agxAssert(m_entity.isValid());
281  return m_entity.mass();
282  }
283 
284 
286  {
287  agxAssert(m_entity.isValid());
288  return m_entity.effectiveMass();
289  }
290 
292  {
293  agxAssert(m_entity.isValid());
294  return m_entity.effectiveMassCoefficients();
295  }
296 
298  {
299  agxAssert(m_entity.isValid());
300  return m_entity.effectiveInertiaCoefficients();
301  }
302 
304  {
305  return m_autoGenerateMask;
306  }
307 
309  {
310  agxAssert(m_entity.isValid());
311  return m_entity.inertia();
312  }
313 
315  {
316  agxAssert(m_entity.isValid());
317  return m_entity.effectiveInertia();
318  }
319 
321  {
322  agxAssert(m_entity.isValid());
323  return m_entity.effectiveMassTransformDiagonal();
324  }
325 
326 
328  {
329  agxAssert(m_entity.isValid());
330  return m_entity.inertia().getDiagonal();
331  }
332 
333  inline const Real& MassProperties::getInvMass() const
334  {
335  agxAssert(m_entity.isValid());
336  return m_entity.invMass();
337  }
338 
340  {
341  agxAssert(m_entity.isValid());
342  return Vec3(m_entity.invMass(), m_entity.invMass(), m_entity.invMass());
343  }
344 
346  {
347  agxAssert(m_entity.isValid());
348  return SPDMatrix3x3( Vec3(m_entity.invMass(), m_entity.invMass(), m_entity.invMass()) );
349  }
350 
351 } // namespace agx
352 #endif
#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:45
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.
const Vec3 & getEffectiveMassTransformDiagonal() const
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...
SPDMatrix3x3 getInvMassMatrix() const
bool setMassCoefficients(const Vec3 &coefficients)
Set mass coefficients.
bool setInertiaTensorCoefficients(const Vec3 &coefficients)
Set inertia tensor coefficients.
SPDMatrix3x3 getEffectiveInvMassMatrix() const
const Real & getInvMass() 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.
Vec3 getPrincipalInertiae() const
const Vec3 & getInertiaTensorCoefficients() const
const Vec3 & getEffectiveMass() const
virtual ~MassProperties()
Destructor.
bool setInertiaTensor(const SPDMatrix3x3 &m, bool autoGenerate=false)
Set the inertia tensor as a full 3x3 tensor matrix.
const Vec3 & getMassCoefficients() const
AutoGenerateFlags
Specifies a bit mask for controlling what should be automatically calculated when a body/geometry is ...
const SPDMatrix3x3 & getEffectiveInertiaTensor() const
Vec3 getInvMassVector() const
const SPDMatrix3x3 & getInertiaTensor() const
agx::UInt32 getAutoGenerateMask() const
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:55
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:49
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:40
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
double Real
Definition: Real.h:42