bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.35k stars 272 forks source link

Consider improving convex hull representative face selection #67

Open RossNordby opened 5 years ago

RossNordby commented 5 years ago

Convex hull face selection for contact generation clipping works using a simple heuristic:

  1. Find the face planes which contain the closest point on the hull.
  2. Of those face planes, choose the one which has a normal closest to the collision normal.

This works reasonably well, but if the hulls are poorly authored or were automatically generated (without a quality-guaranteeing processing phase), they may have multiple faces with very similar normals. This poses a problem for manifold stability- it takes very little motion to swap the representative from frame to frame. That's a recipe for jitter.

While little tricks like bias based on face index help, there are pathological cases where it can't help much. Consider a sliverlike face on a bottom edge that is very nearly coplanar with a larger bottom face. Trivial biases might end up preferring the sliverlike face. Other heuristics, like face area, may help more.

Also, for users reading this: avoid near coplanar faces. Try for at least 10 degrees between face normals. If possible, run your content through a convex hull simplifier (#61) of some sort to prune out unnecessary complexity. It's good for performance and stability!