Fix triangle-triangle collision detection for stability and deep penetration handling #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR addresses two critical issues in the
checkTriangleTriangleOverlapmethod that affect the stability and correctness of triangle-triangle collision detection in mesh simulations.Problem 1: Inconsistent Separation Direction
When two triangles contact face-to-face (especially vertically), the Separating Axis Theorem (SAT) algorithm could oscillate between choosing face normals or edge-edge cross products as the separation axis. This led to:
Example scenario: Two triangular mesh faces approaching each other vertically would sometimes report separation along the face normal (small overlap) and other times along an edge-edge axis (potentially large overlap), causing the solver to flip back and forth.
Problem 2: Missing Deep Penetration Case
The algorithm did not handle the case where all 3 vertices of one triangle are on the opposite side of the other triangle's plane. This represents a deeply penetrated configuration where the triangle is considered completely inside the other mesh, but the standard SAT approach would treat it as a regular contact with potentially incorrect contact information.
Solution
Stability Fix (Issue 1)
Introduced a 5% bias factor that gives face normals priority during axis selection when their overlap is comparable to edge-edge overlaps:
Key design choice: The bias is only applied during axis selection; the actual overlap depth stored remains unbiased to maintain physics accuracy.
Deep Penetration Handling (Issue 2)
Added early detection and specialized handling before running the full SAT algorithm:
Detection: Check if all vertices of one triangle have negative signed distance to the other triangle's plane
Contact Computation:
snap_to_face()utility to check which projections fall inside the reference triangletri_plane_penetration)Early Return: Avoids unnecessary SAT calculations, improving performance in deeply penetrated scenarios
Changes
Modified File:
src/kernel/DEMCollisionKernels.cuhcheckTriangleTriangleOverlap()Compatibility
snap_to_face)Expected Benefits
Testing Recommendations
DEMdemo_MeshCollideto verify basic mesh-mesh collision behaviorRelated
This addresses stability and correctness issues observed in mesh-mesh collision detection, particularly in scenarios with complex mesh interactions or significant mesh overlap.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.