Page 1 of 1

Margins: added or subtracted

Posted: Mon Oct 07, 2013 6:46 pm
by zenux
Hello,

I'm trying to create a small physics engine for fun.
I have implemented GJK and EPA algorithms.

Now, I would like to use these algorithms: use GJK for small depth penetrations and EPA for the rest (hybrid algorithm). To do that, I need margin on my objects.
When I read the Bullet user manual, we can see that the margins are sometimes subtracted from objects (box shape) or sometimes added to object (convex hull, cylinder, cone).

Why we don't subtract the margin for convex hull ? What are the difficulties ?
Moreover, add the margin to convex hull will "round' the convex hull which will cause some imprecision errors, no ?

Thank you in advance.

Re: Margins: added or subtracted

Posted: Thu Oct 17, 2013 4:11 am
by Erwin Coumans
You could always use internal/embedded margins. For convex shapes, you need to make some effort, to shrink the original convex hull.
In the case of Bullet, there is a utility to shrink the convex hull and recompute its vertices, so you can embed the margin.
In a nutshell:
1) create plane equations, given the vertices of the convex hull
2) move the plane equations inwards, over the collision margin
3) re-compute vertices at the intersection of the new plane equations
(see btGeometryUtil::getPlaneEquationsFromVertices and ConvexDecompositionDemo SHRINK_OBJECT_INWARDS)

And indeed, using margins, either embedded inside the original shape or added/extended outside of the shape, will make the edges and corners rounded,
so it is an approximation (except for spheres obviously). As long as you don't use large margins, the error is not big.