-
Notifications
You must be signed in to change notification settings - Fork 27
Implement SAT-based triangle-triangle collision detection and split contact force kernels by type #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement SAT-based triangle-triangle collision detection and split contact force kernels by type #11
Conversation
Co-authored-by: Ruochun <[email protected]>
Co-authored-by: Ruochun <[email protected]>
Co-authored-by: Ruochun <[email protected]>
|
@copilot This is good. But due to the nature of this solver, I need you to make the following changes to checkTriangleTriangleOverlap. 1. The contact penetration is evaluated as the max penetration depth, which we already do; but the contact point needs to be roughly at the center of the "penetrating polygon", that is similar to the implementation in "tri_plane_penetration" function. This contact point does not need to be stable (but best if it is), but should be roughly representing the center of the penetrating volume. 2. Even in the case of no-contact, if a flag is set to true (this should be extra function argument), we will need the function to output the penetration depth, contact point and contact normal. This depth in this case should be negative and roughly represents the distance "before contact happens". This contact point should be some representation of the midpoint of this "expected contact trajectory" and the normal is the direction of this trajectory. You can decide how this can be implemented and this can be a estimation and does not need to be extremely accurate. |
…ct flag and improve contact point calculation Co-authored-by: Ruochun <[email protected]>
I've made both requested changes in commit 90901bd:
The implementation tracks both |
|
@copilot Now, can you split the force calculation kernel (calculateContactForces) into 5, based on the 5 contact types? The types, and their corresponding starts and numbers of elements in the contact array is already stored in typeStartCountMap. The split kernels can still live in the same kernel file, but obviously the 5 different kernels should all be called in each time step, and each of them only takes care of one type of contact. |
Co-authored-by: Ruochun <[email protected]>
I've split the force calculation kernel into 5 specialized kernels in commit 0bb471f: Kernel Structure:
Calling Code (dT.cpp):
The contact type is now known at compile time (via template parameter), enabling better compiler optimization and eliminating runtime branching for type checks. |
Overview
This PR implements the
checkTriangleTriangleOverlapCUDA function for narrow-phase collision detection between two triangles, based on the Separating Axis Theorem (SAT). The function was previously a stub that always returnedfalse. Additionally, this PR refactors the force calculation system by splitting the monolithiccalculateContactForceskernel into 5 specialized kernels based on contact types.Triangle-Triangle Collision Detection Implementation
The function implements a complete SAT-based collision detection algorithm with support for both contact and no-contact scenarios:
Separating Axis Tests
Minimum Translation Vector (MTV) and Separation Tracking
The implementation tracks both overlap and separation across all 11 tested axes to determine:
outputNoContactflag is true, provides information even when triangles don't overlapContact Point Calculation
The contact point is computed as the centroid of the penetrating polygon, similar to
tri_plane_penetration:outputNoContact=true):Robustness Features
DEME_TINY_FLOATepsilonfalseif no valid separating axis can be determinedFunction Signature
Contact Force Kernel Refactoring
Split the monolithic
calculateContactForceskernel into 5 specialized kernels for improved performance:Kernel Architecture
calculateContactForcesImpl<CONTACT_TYPE>contains the core force calculation logiccalculateContactForces_SphSph- Sphere-Sphere contactscalculateContactForces_SphTri- Sphere-Triangle contactscalculateContactForces_SphAnal- Sphere-Analytical contactscalculateContactForces_TriTri- Triangle-Triangle contactscalculateContactForces_TriAnal- Triangle-Analytical contactsBenefits of Split Kernels
Kernel Invocation
dT.cppto call all 5 kernels conditionally based ontypeStartCountMapstartOffsetandnContactPairsfor its specific contact type rangeTechnical Details
Template Parameters
T1: Vector type (typicallydouble3)T2: Scalar type (typicallydouble)Utility Functions Used
Leverages existing functions from
DEMHelperKernels.cuhandCUDAMathHelpers.cuh:cross(),dot(),normalize(),clamp(),sqrt()DEME_MIN(),DEME_TINY_FLOAT,DEME_HUGE_FLOATCode Quality
tri_plane_penetrationclang-formataccording to project standardsTesting
While CUDA is not available in the development environment for compilation testing, the implementation:
calc_prism_contact,tri_plane_penetration)Use Cases
This PR enables:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.