AGXDynamics  2.35.0.3
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 
187  Vec3 getEffectiveInvMassVector() const;
188 
192  SPDMatrix3x3 getEffectiveInvMassMatrix() const;
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
SPDMatrix3x3.h
agx::MassProperties::getInertiaTensor
const SPDMatrix3x3 & getInertiaTensor() const
Definition: MassProperties.h:308
agx::Real
double Real
Definition: Real.h:42
agx::MassProperties::AutoGenerateFlags
AutoGenerateFlags
Specifies a bit mask for controlling what should be automatically calculated when a body/geometry is ...
Definition: MassProperties.h:48
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agx::MassProperties::getMassCoefficients
const Vec3 & getMassCoefficients() const
Definition: MassProperties.h:291
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agx::Physics::RigidBodyPtr
Pointer to a entity instance of type Physics.RigidBody.
Definition: RigidBodyEntity.h:371
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
Vec3.h
agx::MassProperties::getEffectiveMass
const Vec3 & getEffectiveMass() const
Definition: MassProperties.h:285
agx::Vec3
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
agx::MassProperties::getAutoGenerateMask
agx::UInt32 getAutoGenerateMask() const
Definition: MassProperties.h:303
agx::MassProperties
Class for rigid body inertia tensor and mass.
Definition: MassProperties.h:40
agx::MassProperties::getInvMassMatrix
SPDMatrix3x3 getInvMassMatrix() const
Definition: MassProperties.h:345
agx::MassProperties::getEffectiveMassTransformDiagonal
const Vec3 & getEffectiveMassTransformDiagonal() const
Definition: MassProperties.h:320
agx::SPDMatrix3x3
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
Serializable.h
agx.h
RigidBodyEntity.h
agx::MassProperties::getEffectiveInertiaTensor
const SPDMatrix3x3 & getEffectiveInertiaTensor() const
Definition: MassProperties.h:314
agx::MassProperties::getInvMassVector
Vec3 getInvMassVector() const
Definition: MassProperties.h:339
agx::Vec3T
A class holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3Template.h:45
agx::MassProperties::getInvMass
const Real & getInvMass() const
Definition: MassProperties.h:333
agx::MassProperties::getPrincipalInertiae
Vec3 getPrincipalInertiae() const
Definition: MassProperties.h:327
agx::MassProperties::getInertiaTensorCoefficients
const Vec3 & getInertiaTensorCoefficients() const
Definition: MassProperties.h:297
agx::Matrix3x3T< Real >
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40