AGX Dynamics  2.37.3.2
MassProperties.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 #pragma once
18 
19 #include <agx/agx.h>
20 #include <agx/Vec3.h>
21 #include <agx/SPDMatrix3x3.h>
22 #include <agxStream/Serializable.h>
24 
25 
26 namespace 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 
186  Vec3 getEffectiveInvMassVector() const;
187 
191  SPDMatrix3x3 getEffectiveInvMassMatrix() const;
192 
203  void setEffectiveMassTransformDiagonal( const Vec3& effectiveMassTransformDiagonal );
204 
208  const Vec3& getEffectiveMassTransformDiagonal() const;
209 
210 
212  MassProperties& operator= (const MassProperties& copy);
213 
215  virtual ~MassProperties();
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:
235  MassProperties();
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 
285  {
286  agxAssert(m_entity.isValid());
287  return m_entity.effectiveMass();
288  }
289 
291  {
292  agxAssert(m_entity.isValid());
293  return m_entity.effectiveMassCoefficients();
294  }
295 
297  {
298  agxAssert(m_entity.isValid());
299  return m_entity.effectiveInertiaCoefficients();
300  }
301 
303  {
304  return m_autoGenerateMask;
305  }
306 
308  {
309  agxAssert(m_entity.isValid());
310  return m_entity.inertia();
311  }
312 
314  {
315  agxAssert(m_entity.isValid());
316  return m_entity.effectiveInertia();
317  }
318 
320  {
321  agxAssert(m_entity.isValid());
322  return m_entity.effectiveMassTransformDiagonal();
323  }
324 
325 
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 
339  {
340  agxAssert(m_entity.isValid());
341  return Vec3(m_entity.invMass(), m_entity.invMass(), m_entity.invMass());
342  }
343 
345  {
346  agxAssert(m_entity.isValid());
347  return SPDMatrix3x3( Vec3(m_entity.invMass(), m_entity.invMass(), m_entity.invMass()) );
348  }
349 
350 } // namespace agx
AutoGenerateFlags
Specifies a bit mask for controlling what should be automatically calculated when a body/geometry is ...
SPDMatrix3x3 getInvMassMatrix() const
Vec3 getPrincipalInertiae() const
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
const Vec3 & getEffectiveMassTransformDiagonal() const
const Vec3 & getEffectiveMass() const
const Real & getInvMass() const
#define AGXPHYSICS_EXPORT
const SPDMatrix3x3 & getEffectiveInertiaTensor() const
agx::UInt32 getAutoGenerateMask() const
const Vec3 & getMassCoefficients() const
Pointer to a entity instance of type Physics.RigidBody.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
Class for rigid body inertia tensor and mass.
#define agxAssert(expr)
Definition: debug.h:143
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
const Vec3 & getInertiaTensorCoefficients() const
#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
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
double Real
Definition: Real.h:42
Vec3 getInvMassVector() const
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
const SPDMatrix3x3 & getInertiaTensor() const
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97