Sometimes the expanding polytype algorithm takes a long time to
terminate, e.g. in situations like this:
.-.
: +-:-+
'-' |
| |
+---+
The issue here is that the EPA adds vertices very close to each other,
which makes the separation distance change very slowly. If this is the
case, consider the current separation distance as approximately correct
and continue.
support(A,B, 1,0) returns 0,0 when A and B are touching in a vertex of
both A and B AND this vertex is on the right of A's center (in direction
(1,0)), e.g. this situation:
.---.
.-.| B |
: A x---'
'-'
Then: support(A,B, 1,0) = A:support(1,0) - B:support(-1,0) = x - x = 0
Since CircleShape:support(dx,dy) normalizes dx,dy this will result in a
division by 0 error in the subsequent execution of the GJK algorithm.
An early out with result 'not colliding' (in accordance to the other
edge cases) prevents this error.
The Gilbert–Johnson–Keerthi collision detection algorithm is
significantly faster than collision detection using the separating axis
theorem. GJK can only determine whether two shapes collide, but not the
penetration vector. The expanding polytype algorithm can use information
from GJK to quickly find the required vector.