mirror of
https://github.com/vrld/HC.git
synced 2024-11-18 12:54:23 +00:00
Issue #25 (2): Collision detection sometimes hangs.
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.
This commit is contained in:
parent
0dc1e6c719
commit
adfe9a9a5d
5
gjk.lua
5
gjk.lua
@ -65,14 +65,17 @@ local function EPA(shape_a, shape_b, simplex)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- the expanding polytype algorithm
|
-- the expanding polytype algorithm
|
||||||
|
local last_diff_dist = math.huge
|
||||||
while true do
|
while true do
|
||||||
local e = closest_edge(simplex)
|
local e = closest_edge(simplex)
|
||||||
local px,py = support(shape_a, shape_b, e.nx, e.ny)
|
local px,py = support(shape_a, shape_b, e.nx, e.ny)
|
||||||
local d = vector.dot(px,py, e.nx, e.ny)
|
local d = vector.dot(px,py, e.nx, e.ny)
|
||||||
|
|
||||||
if d - e.dist < 1e-6 then
|
local diff_dist = d - e.dist
|
||||||
|
if diff_dist < 1e-6 or last_diff_dist - diff_dist < 1e-10 then
|
||||||
return -d*e.nx, -d*e.ny
|
return -d*e.nx, -d*e.ny
|
||||||
end
|
end
|
||||||
|
last_diff_dist = diff_dist
|
||||||
|
|
||||||
-- simplex = {..., simplex[e.i-1], px, py, simplex[e.i]
|
-- simplex = {..., simplex[e.i-1], px, py, simplex[e.i]
|
||||||
table.insert(simplex, e.i, py)
|
table.insert(simplex, e.i, py)
|
||||||
|
Loading…
Reference in New Issue
Block a user