iMSTK
Interactive Medical Simulation Toolkit
Collision Detection

A collision detection method in iMSTK is defined through the CollisionDetectionAlgorithm base class. This class assumes two input geometries and produces a CollisionData output. CollisionDetectionAlgorithm accepts geometries in either order, the output will be flipped if inputs are flipped. For example:

SurfaceMeshToSphereCD myCollisionDetection;
myCollisionDetection.setInput(myGeomA, 0);
myCollisionDetection.setInput(myGeomB, 1);
myCollisionDetection.update();
std::shared_ptr<CollisionData> cdData = myCollisionDetection.getCollisionData();
cdData->elementsA; // Refers to input 0 geometry/myGeomA
cdData->elementsB; // Refers to input 1 geometry/myGeomB

## Supported Collision Detection

Legend

Matrix

Capsule Cylinder ImplicitGeometry LineMesh OrientedBox Plane PointSet Sphere SurfaceMesh
Capsule X
Cylinder - -
ImplicitGeometry - - -
LineMesh X - - X
OrientedBox - - - - -
Plane X - - - - N/A
PointSet X X X N/A X X N/A
Sphere X X - X - X X X
SurfaceMesh X - - X - X X X X

Notes

There are two approaches to collision detection.

Static Collision Detection

Given a snapshot of two already overlapping geometries, find the best solution to separate them. This normally involves resolving the geometry along directions that produce minimal movement. Often objects in physics simulations move small amounts so one can reliably resolve along this direction to get believable behavior.

Dynamic Collision Detection

Given two overlapping geometries and their dynamics (or two cached snapshots of them over time). Find the intersections a-priori and deal with them. Almost 100% of the time dynamic CD methods are paired with static CD methods as a fallback. This allows solvers to not guarantee non-intersecting states at the end of a timestep which may be difficult (for example, in an over constrained system).

Continuous Collision Detection

Continuous collision detection is a form of dynamic CD. It uses the dynamics of the object to compute exact time of impact. The usual solution is to linear interpolate elements of a geometry over time and find the time at which the elements are coplanar. For example, a vertex and a triangle moving. When the vertex and triangle are coplanar they intersect so long as the vertex still lies in the triangle. CCD can often be hard to tune and deal with floating point error. This can be alleviated with static CD as a fallback.

Collision Manifolds

Collision manifolds define the areas/points/patches of contact should two bodies be separated and just touch. From contacts or whatever is needed for the solver to separate may be computed. These manifolds are made up of N or more types of contacts. With various types of contacts for shapes.

various contact manifolds

How a collision manifold is specified varies a lot among collision systems. The solution can get ambigious when only looking at a snapshot of overlapping geometries. It may not be clear what the best manifold would be.

manifold when overlapping
manifold when separated

It becomes of a problem of specifying this to the solver. Some collision systems report intersecting elements (ie: This triangle touched this edge, or this edge touched this point). Others report per contact points where N point-based contacts need to be used to support a face.

Two point,direction,depth contacts required to support the box

Instead of subbing points for faces though, a constraint can be formulated between two elements in contact. For example, Vertex-Triangle as mentioned earlier, shown below:

vertex triangle manifold

## Collision Data

With this approach it is required to store contact pairs of elements. Vertex-triangle, edge-edge. Whereas in the previous approach the system can only store point-based contacts. iMSTK supports both methods providing the following element types.

iMSTK collision methods prefer to produce contact element pairs over point-based contacts. This is because point-based contacts can be computed from element pairs when needed. But element pairs cannot so easily be computed from point-based contacts.

Collision Resolution

Resolving collision can be classified into two categories.

Collision Constraints

The matrix ones are often "constraint based". The constraints giving a single scalar and gradient for which to solve. Often represented as a single row in a system. For a non-penetration constraint the scalar should be 0 when separated. The gradient then gives the direction to change the inputs such that the scalar becomes 0 (the root). This gives a bit better generalization to apply to a lot of things, perhaps not even non-penetration constraints (springs, joints, etc).

A pbd constraint to keep a point to a plane:

.. image:: Collision_Detection/constraintEx1.png :width: 300 :alt: Alternative text :align: center

A rbd constraint to keep a box above a plane by adding a constraint per vertex corner.

A useful function of these constraints is reprojection. In the PbdConstraint example, as the vertex resolves closer to the triangle the distance to the triangle is recomputed. While this isn't as foolproof as recomputing collision, it does allow better solutions at a cheaper cost (especially on overconstrained systems).

Lastly the signs of the constraints matter. Unsigned constraints gradients flip.

## Persistent Contacts

Persistent contacts are those that persist over time. Often these are brought up with resting contacts keeping track of the same contacts frame-to-frame. The schemes for persistent contacts vary.

Collision Detection Types

### BidirectionalPlaneToSphereCD

Method

Additional Notes

### UnidirectionalPlaneToSphereCD

Method

Additional Notes

### ImplicitGeometryToPointSetCCD

Method

Additional Notes

### ImplicitGeometryToPointSetCD

Method

Additional Notes

### ClosedSurfaceMeshToMeshCD

Method

For a curved surface this point in polygon strategy works well.

For meshes using the normal of the element will produce incorrect results (see above where point is inside according to one face, outside according to the other). This is where the angle-weighted pseudonormal comes in.

Additional Notes

### PointSetToCapsuleCD

Method

Additional Notes

### PointSetToOrientedBoxCD

Method

Additional Notes

### PointSetToPlaneCD

Method

Additional Notes

### PointSetToSphereCD

Method

Additional Notes

### SphereToCylinderCD

Method

For the other two cases, look at the projected distance along the orthogonal axes. If the orthogonal distance is larger than the radius of the cylinder then the nearest point must be on the edge/rim of the cylinder. If smaller then the nearest point must be on the cap.

Additional Notes

### SphereToSphereCD

Method

Additional Notes

### CapsuleToCapsuleCD

Method

### BidirectionalSurfaceMeshToSphereCD

Method

Additional Notes

### TetraToLineMeshCD

Method

Additional Notes

### TetraToPointSetCD

Method

Additional Notes

### SurfaceMeshToCapsuleCD

Method

Additional Notes

### LineMeshToLineMeshCCD

References & Resources

Much of the math for geometric intersections can be derived from SAT and GJK.

[gpp] den, B. G. van. (2010). Game physics pearls. A.K. Peters.

[rcd] Ericson, C. (n.d.). Real-time collision detection. Elsevier.

[lfs] Qi, Di, Karthikeyan Panneerselvam, Woojin Ahn, Venkata Arikatla, Andinet Enquobahrie, and Suvranu De. "Virtual interactive suturing for the Fundamentals of Laparoscopic Surgery (FLS)." Journal of biomedical informatics 75 (2017): 48-62.