error tolerance in GjkPairDetector?

Post Reply
ueckueck
Posts: 2
Joined: Sun Mar 26, 2017 11:42 am

error tolerance in GjkPairDetector?

Post by ueckueck »

I want to use bullet physics to measure the distance between convex objects (boxes) and use the GjkPairDetector with the VoronoiSimplexSolver and the GjkEpaPenetrationDepthSolver.
A simple test case shows results that are not exact enough for my needs.

My test objects:
Box0: center at position (1|0|0), size=(1|1|1)
Box1: center at position (-1|2|0), size=(1|1|1)
Box2: center at position (5|3|0), size=(1|1|1)

expected distances:
d( Box0 | Box1) = 0.0
d( Box0 | Box2) = 2.23606
d( Box1 | Box2) = 4.0

computed distance between Box0 and Box1 is
0.033137 with
point_Box0 = (-0.0117157 | 1.01172 | 0.96)
point_Box1 = (0.0117157 | 0.988284 | 0.96)

computed distance between Box0 and Box2 is
2.26367 with
point_Box0 = (4.0045 | 2.02157 | 0.96)
point_Box2 = (1.9955 | 0.978433 | 0.96)

The distance between Box1 and Box2 is computed correctly.

Is there any way to reduce the error such that getClosestPoints returns results with an accuracy of at least four decimal places?
Any help would be appreciated!
Attachments
collisionDetection.cpp
(8.97 KiB) Downloaded 186 times
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: error tolerance in GjkPairDetector?

Post by Erwin Coumans »

Haven't checked your source code, but by default, Bullet uses a collision margin of about 0.04 units that may influence your results. You could reduce the margin a bit, but best not to put it to zero (box->setMargin(0.0001))

In addition, it is best to use the double precision version: define BT_USE_DOUBLE_PRECISION (cmake -DBT_USE_DOUBLE_PRECISION=ON or premake --double)
ueckueck
Posts: 2
Joined: Sun Mar 26, 2017 11:42 am

Re: error tolerance in GjkPairDetector?

Post by ueckueck »

Erwin Coumans wrote:Haven't checked your source code, but by default, Bullet uses a collision margin of about 0.04 units that may influence your results. You could reduce the margin a bit, but best not to put it to zero (box->setMargin(0.0001))

In addition, it is best to use the double precision version: define BT_USE_DOUBLE_PRECISION (cmake -DBT_USE_DOUBLE_PRECISION=ON or premake --double)

Many thanks for your answer! This works fine, I now get the expected results.
I was a bit afraid to change the margin as the documentation recommends not to change the default value, but in my case the value seems to be too large.
Thanks a lot!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: error tolerance in GjkPairDetector?

Post by Erwin Coumans »

If you are just doing some collision checks, and don't care about performance you are likely fine with a very small margin. If you are using Bullet for physics simulation, it is much better to leave some larger collision margin, both for performance reasons (GJK distance check is faster than EPA penetration check) and quality. You just have to be careful to compensate for the margin, and take into account that a margin makes the edges 'rounded'.
Post Reply