Difference between revisions of "NewtonBodySetCentreOfMass"

From Newton Wiki
Jump to: navigation, search
m (1 revision imported)
(typos, sync with header text)
 
Line 21: Line 21:
  
 
  Matrix matrix; Vector centre;
 
  Matrix matrix; Vector centre;
NewtonGetMetrix(body, matrix) NewtonGetCentreOfMass(body, centre);
+
* NewtonGetMatrix(body, matrix)
for global space torque. Vector localForce (fx, fy, fz); Vector localPosition (x, y, z);
+
* NewtonGetCentreOfMass(body, center);
Vector localTorque (crossproduct ((localPosition - centre). localForce); Vector globalTorque (matrix.RotateVector (localTorque));
+
* //for global space torque.
for global space torque. Vector globalCentre (matrix.TranformVector (centre)); Vector globalPosition (x, y, z); Vector globalForce (fx, fy, fz);
+
* Vector localForce (fx, fy, fz);
Vector globalTorque (crossproduct ((globalPosition - globalCentre). globalForce);
+
* 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 ==
 
== See also ==

Latest revision as of 05:35, 18 June 2019

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