-
Notifications
You must be signed in to change notification settings - Fork 27
Replace SAT with bidirectional projection and axis hygiene check in triangle-triangle collision detection #21
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
base: Mesh_Particles
Are you sure you want to change the base?
Conversation
…h instead of SAT Co-authored-by: Ruochun <24469442+Ruochun@users.noreply.github.com>
…safety, and use named constant Co-authored-by: Ruochun <24469442+Ruochun@users.noreply.github.com>
Co-authored-by: Ruochun <24469442+Ruochun@users.noreply.github.com>
…ulation Co-authored-by: Ruochun <24469442+Ruochun@users.noreply.github.com>
|
@copilot I am dealing with a classic artifact: when two big, flat faces barely interpenetrate, tiny “side strips” (from edges/adjacent faces) can produce large penalty responses if we treat every local penetration direction equally. Can you apply this to the triangle-triangle penetration calculation: limit the penetration/overlap to be no larger than the minimum length required to move the projection of the projected triangle away from the reference triangle. This is similar to a "2D MTV" idea, and since we produce force only when this projection intersects with the reference triangle on its plane, this minimum length is always a positive value. |
…rip artifacts Co-authored-by: Ruochun <24469442+Ruochun@users.noreply.github.com>
Implemented 2D MTV calculation to limit penetration depth. Instead of using the maximum 3D distance of submerged vertices, the depth is now computed as the minimum 2D distance required to move the clipped polygon away from the reference triangle on its plane. This is calculated by testing each edge of the reference triangle and finding the minimum penetration distance needed for separation. Commit: 7277124 |
|
@copilot I've undone your last commit, sorry. That's because I thought about a better way of restricting the last penetration for side strips. I think any projected overlap needs to satisfy an "axis hygiene" check, if the projected area is lower than a small percentage of the area of the reference triangle. Such an overlap is called suspicious and it has to go through a check: If we rotate the plane of the reference triangle by a bit (potentially 4 trials: the two orthogonal directions about the original normal direction of the plane, increase or decrease angles), this area needs to still exist to be considered a stable area, and the smallest overlap among these 4 trial projections (minimal is 0) will be used as the final overlap area for these pairs. |
…side strip artifacts Co-authored-by: Ruochun <24469442+Ruochun@users.noreply.github.com>
Implemented axis hygiene check with stability trials. When projected overlap area is < 5% of the reference triangle area (suspicious), the algorithm now performs 4 trial projections with the reference plane rotated slightly (±5.7° around two orthogonal in-plane axes). The final overlap area is the minimum from all trials, or 0 if any trial shows no contact. This ensures only stable overlaps that persist under small plane rotations are considered valid, effectively filtering side strip artifacts. Commit: 9bd78bf |
|
@copilot This is good. But before the check is carried out, in addition to rotating the plane, the reference triangle's nodes should change along with this rotation, right? This should be added to the code. Also, when you break in the inner loop of the 4 checks, I think you forgot to also break out of the outer loop. |
…from outer loop Co-authored-by: Ruochun <24469442+Ruochun@users.noreply.github.com>
Fixed both issues. The reference triangle vertices now rotate along with the plane normal using Rodrigues formula around the triangle centroid. Also added a |
Summary
Successfully redesigned
checkTriangleTriangleOverlapfrom SAT-based to projection-based approach using Sutherland-Hodgman clipping algorithm.Completed Tasks
projectTriangleOntoTrianglefor projecting triangle onto plane and calculating clipping areaMAX_CLIPPING_VERTICESinstead of magic numbersImplementation Details
Code Metrics
Algorithm
Axis Hygiene Feature (Corrected)
The axis hygiene check now properly rotates the entire reference frame:
foundZeroAreaensures both outer and inner loops exit when zero area is foundRobustness
Benefits
✅ Simplicity: Conceptually simpler than SAT
✅ Consistency: Asymptotically equivalent to contact surface projection for shallow contacts
✅ Maintainability: ~21% code reduction improves readability
✅ Robustness: Comprehensive edge case handling including proper axis hygiene implementation
✅ Compatibility: Function signature unchanged, existing code unaffected
✅ Physical Accuracy: Axis hygiene check properly validates contacts under rigid body rotations
Next Steps (Requires CUDA Environment)
The implementation is ready for review and testing in a CUDA-enabled environment.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.