Skip to content

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 ​

cpp
Contact() = default
cpp
explicit 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

ParameterDescription
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 ​

cpp
~Contact() = default

Public member functions ​

getPosition ​

cpp
const Vec<3> &getPosition() const

the contact position

Returns the contact position in the world frame

getSolverPosition ​

cpp
const Vec<3> &getSolverPosition() const

Point 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 ​

cpp
const Vec<3> &getNormal() const

the 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 ​

cpp
const Mat<3, 3> &getContactFrame() const

returns 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 ​

cpp
size_t getIndexContactProblem() const

returns the corresponding index in raisim::World::getContactProblem

Returns contact index

getIndexInObjectContactList ​

cpp
size_t getIndexInObjectContactList() const

returns the corresponding index in raisim::Object::getContacts

Returns contact index

getPairObjectIndex ​

cpp
size_t getPairObjectIndex() const

returns the contacting object index in raisim::World::getObjectList

Returns object index

getPairContactIndexInPairObject ​

cpp
size_t getPairContactIndexInPairObject() const

returns 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 ​

cpp
const Vec<3> *getImpulsePtr() const

returns 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 ​

cpp
const Vec<3> &getImpulse() const

returns 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 ​

cpp
bool isObjectA() const

returns 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 ​

cpp
BodyType getPairObjectBodyType() const

returns 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 ​

cpp
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 ​

cpp
size_t getlocalBodyIndex() const

get local body index of this contact. The local index is assigned to each moving body in an object

Returns the body index.

getDepth ​

cpp
double getDepth() const

The signed separation of the contact along the normal, in meters

Returns the negated penetration depth: negative while the bodies overlap

isSelfCollision ​

cpp
bool isSelfCollision() const

returns 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 ​

cpp
bool skip() const

this 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 ​

cpp
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 ​

cpp
CollisionBodyHandlePtr getCollisionBodyB()

get the collision body handle of objectB (the same in both entries; check isObjectA())

Returns collision body

Static member functions ​

computeFrame static ​

cpp
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

ParameterDescription
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).

RaiSim — physics for robotics and AI.