Issue #25: Division by 0 in CircleShape:support().

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.
This commit is contained in:
Matthias Richter 2013-08-13 15:13:25 +02:00
parent 5d100c703f
commit 0dc1e6c719

14
gjk.lua
View File

@ -136,9 +136,21 @@ local function do_triangle(simplex)
return simplex
end
local function GJK(shape_a, shape_b)
local ax,ay = support(shape_a, shape_b, 1,0)
if ax == 0 and ay == 0 then
-- only true if shape_a and shape_b are touching in a vertex, e.g.
-- .--- .---.
-- | A | .-. | B | support(A, 1,0) = x
-- '---x---. or : A :x---' support(B, -1,0) = x
-- | B | `-' => support(A,B,1,0) = x - x = 0
-- '---'
-- Since CircleShape:support(dx,dy) normalizes dx,dy we have to opt
-- out or the algorithm blows up. In accordance to the cases below
-- choose to judge this situation as not colliding.
return false
end
local simplex = {ax,ay}
local n = 2
local dx,dy = -ax,-ay