NewtonBodySetCentreOfMass

From Newton Wiki
Revision as of 05:35, 18 June 2019 by WikiSysop (talk | contribs) (typos, sync with header text)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

NewtonBodySetCentreOfMass

void NewtonBodySetCentreOfMass( const NewtonBody* bodyPtr, const dFloat* comPtr)

Usage

Set the relative position of the center of mass of a rigid body.

Parameters

  • const NewtonBody *bodyPtr - pointer to the body.
  • const dFloat *comPtr - pointer to an array of 3 floats containing the relative offset of the centre of mass of the body.

Return

  • Nothing.

Remarks

  • This function can be used to set the relative offset of the centre of mass of a rigid body. When a rigid body is created the centre of mass is set to the point c(0, 0, 0), and normally this is the best setting for a rigid body. However, there are situations in which an object does not have symmetry, or simply some kind of special effect is desired, and this origin needs to be changed.
  • Care must be taken when offsetting the centre of mass of a body. The application must make sure that the external torques resulting from forces applied at a point relative to the centre of mass are calculated properly. this could be done in the Transform and Torque callback function as the following pseudo code fragment shows:
Matrix matrix; Vector centre;
  • NewtonGetMatrix(body, matrix)
  • NewtonGetCentreOfMass(body, center);
  • //for global space torque.
  • Vector localForce (fx, fy, fz);
  • Vector localPosition (x, y, z);
  • Vector localTorque (crossproduct ((localPosition - center). localForce);
  • Vector globalTorque (matrix.RotateVector (localTorque));
  • //for global space torque.
  • Vector globalCentre (matrix.TranformVector (center));
  • Vector globalPosition (x, y, z);
  • Vector globalForce (fx, fy, fz);
  • Vector globalTorque (crossproduct ((globalPosition - globalCentre). globalForce);

See also

NewtonConvexCollisionCalculateInertialMatrix NewtonBodyGetCentreOfMass