inzombiak / Orbitals

WIP 3D Physics Engine
MIT License
8 stars 0 forks source link

Why use SAT instead of GJK? #1

Open WaneOshin opened 1 year ago

WaneOshin commented 1 year ago

Hello there! simple question im struggling to find the answer: why use SAT instead of gjk/epa? isnt SAT slower? does gjk/epa have problems? thanks , nice project btw

inzombiak commented 1 year ago

Hi!

Its been a long time since I've worked on this, but there may be two reasons:

  1. SAT is just a lot simpler to implement and I was in the middle of transitioning from SAT to GJK when I stopped
  2. I couldnt get the manifold generation from EPA to work.

Its probably (1). I havent measured the two in a very long time, but I will ask if its worth the trouble of adding GJK and EPA. If you only need to worry about simple shapes like boxes and triangles then the code complexity of GJK/EPA may now be worth the tiny speedup (if there is one). SAT works fine and its a single function you get both collision and collision info from, while GJK needs EPA for you to be able to solve the collision. Sometimes the complexity added to a system isnt worth the benefit

If I were to add arbitrary shape support then GJK would be necessary since checking all the faces of an n-gon is ridiculous. Usually physics engines solve different shape combos in their own optimized way. You could use SAT for 2 AABBs and GJK for an AABB and a convex shape. For spheres, just do the radius and center test.

WaneOshin commented 1 year ago

thank you, this answered my question