raisim::Contact
class · #include <raisim/contact/Contact.hpp>
A contact point between two collision bodies, as stored in Object::getContacts().
Every contact has two participants, objectA and objectB (assigned by the collision detector). A Contact entry is stored in each participant's contact list, except on STATIC objects. Both entries share the same position, normal, contact frame, depth, impulse and collision-body handles; use isObjectA() to tell which side the entry belongs to.
Conventions:
- getNormal() is a unit vector pointing from objectB toward objectA (in both entries).
- getContactFrame() is a rotation matrix whose rows are the contact-frame axes expressed in the world frame; its third row equals the normal.
- getImpulse() is the impulse acting on objectA, expressed in the contact frame. objectB receives the negated impulse. The world-frame impulse on objectA is getContactFrame().transpose() * getImpulse().
Constructors & destructor
Contact
Contact() = defaultexplicit Contact(
const Vec<3> &position,
const Vec<3> &normal,
const Mat<3, 3> &frame,
bool objectA,
size_t contactProblemIndex,
size_t contactIndexInObject,
size_t pairObjectIndex,
BodyType pairObjectBodyType,
size_t pairContactIndexInPairObject,
size_t localBodyIndex,
double depth,
CollisionBodyHandlePtr colA,
CollisionBodyHandlePtr colB)Created by the World during collision detection; users normally only read contacts.
Parameters
| Parameter | Description |
|---|---|
position (in) | Contact position in the world frame. |
normal (in) | Unit normal pointing from objectB to objectA. |
frame (in) | Contact frame (see getContactFrame()). |
objectA (in) | True if this entry belongs to objectA. |
contactProblemIndex (in) | Index in World::getContactProblem(). |
contactIndexInObject (in) | Index of this entry in its object's contact list. |
pairObjectIndex (in) | World index of the other object. |
pairObjectBodyType (in) | Body type of the other object. |
pairContactIndexInPairObject (in) | Index of the paired entry in the other object's contact list. |
localBodyIndex (in) | Local index of the body (within this object) that is in contact. |
depth (in) | Signed separation (negative when penetrating), see getDepth(). |
colA (in) | Collision body of objectA. |
colB (in) | Collision body of objectB. |
~Contact
~Contact() = defaultPublic member functions
getPosition
const Vec<3> &getPosition() constthe contact position
Returns the contact position in the world frame
getSolverPosition
const Vec<3> &getSolverPosition() constPoint used for the contact Jacobian. It can be the body witness while getPosition() remains the reported terrain-surface point.
Returns the solver contact position in the world frame (usually equal to getPosition())
getNormal
const Vec<3> &getNormal() constthe contact normal vector, pointing from objectB to objectA. The same vector is stored in the entries of both objects, so check isObjectA() before using it as "this object's" normal.
Returns unit normal in the world frame
getContactFrame
const Mat<3, 3> &getContactFrame() constreturns a TRANSPOSE of the frame that the impulse is expressed: each row is a contact-frame axis in world coordinates and the third row is the normal. A world-frame vector v is expressed in the contact frame as getContactFrame() * v.
Returns contact frame
getIndexContactProblem
size_t getIndexContactProblem() constreturns the corresponding index in raisim::World::getContactProblem
Returns contact index
getIndexInObjectContactList
size_t getIndexInObjectContactList() constreturns the corresponding index in raisim::Object::getContacts
Returns contact index
getPairObjectIndex
size_t getPairObjectIndex() constreturns the contacting object index in raisim::World::getObjectList
Returns object index
getPairContactIndexInPairObject
size_t getPairContactIndexInPairObject() constreturns the contact index in the contacting (the paired) object in raisim::Object::getContacts This does not work if the pair body is STATIC because contacts on static bodies are not stored. First check the pair body type with getPairObjectBodyType
Returns contact index
getImpulsePtr
const Vec<3> *getImpulsePtr() constreturns the impulse pointer. You have to divide this number by the time step to get the force
Returns pointer to the impulse on objectA in the contact frame (N*s); see getImpulse(). nullptr until the World binds it in World::integrate(), which it does only for contacts of awake DYNAMIC objects (e.g. contacts stored on KINEMATIC objects keep nullptr).
getImpulse
const Vec<3> &getImpulse() constreturns the impulse. You have to divide this number by the time step to get the force
Returns impulse (N*s) acting on objectA, expressed in the contact frame (z component along the normal). Negate it for objectB. Dereferences getImpulsePtr() without a check, so it must only be called when that pointer is non-null.
isObjectA
bool isObjectA() constreturns if the object is objectA. When there is a contact, the two paired objects are assigned to be objectA and objectB arbitrarily. The contact frame is defined such that its z-axis is pointing towards the objectA. The contact impulse is defined as an external force that objectA experiences.
Returns true if this entry belongs to objectA
getPairObjectBodyType
BodyType getPairObjectBodyType() constreturns the body type of the paired object. Please read https://raisim.com/sections/Object.html#body-types to learn about it
Returns the body type
getInvInertia
Mat<3, 3> &getInvInertia()returns the inverse apparent inertia of the contacting point of this object
Returns inverse apparent inertia, expressed in the contact frame
getlocalBodyIndex
size_t getlocalBodyIndex() constget local body index of this contact. The local index is assigned to each moving body in an object
Returns the body index.
getDepth
double getDepth() constThe signed separation of the contact along the normal, in meters
Returns the negated penetration depth: negative while the bodies overlap
isSelfCollision
bool isSelfCollision() constreturns if the contact is self collision (two bodies of the same articulated system). Only the objectA entry is flagged; the objectB entry has skip() == true instead.
Returns if this is a self collision
skip
bool skip() constthis is set true for the objectB entry of a self-collision point so that you don't count them twice
Returns if you can skip this contact point while iterating contact points
getCollisionBodyA
CollisionBodyHandlePtr getCollisionBodyA()get the collision body handle of objectA (the same in both entries, so it is not necessarily this object's body; check isObjectA())
Returns collision body
getCollisionBodyB
CollisionBodyHandlePtr getCollisionBodyB()get the collision body handle of objectB (the same in both entries; check isObjectA())
Returns collision body
Static member functions
computeFrame static
static void computeFrame(const Vec<3> &zAxis, Mat<3, 3> &frame)Build a contact frame from a normal: the third row of frame is the normalized zAxis, the first two rows are orthonormal tangent directions (all expressed in the world frame).
Parameters
| Parameter | Description |
|---|---|
zAxis (in) | Contact normal (need not be normalized; must be non-zero). |
frame (out) | Rotation matrix whose rows are the contact axes (world-to-contact rotation). |