behdad / box2d

Automatically exported from code.google.com/p/box2d
2 stars 12 forks source link

Re: issue 174 #216

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Issue 174 involved an assertion in ResetMassData for small polygon shapes 
attached far from their body's origin: 
http://code.google.com/p/box2d/issues/detail?id=174

The problem was improved a while ago but I still get this fairly regularly, so 
I took a look at the code in a bit more detail. If I understand things 
correctly the problem is due to floating point precision giving slightly 
different results when 'moving' the accumulated inertia for multiple fixtures 
between the CoM and the body origin. It occurred to me that if there is only 
one fixture on the body, the original 'unmoved' inertia as calculated in 
b2PolygonShape::ComputeMass could be used directly instead of moving it twice. 
I tried this and it has been ok so far - of course the problem still remains 
for bodies with more than one fixture but it's a cheap way to cover the most 
common case.

Regarding the problem in general, it's hard to see a solid fix for this 
situation but given that we humans (well, me human anyway) can't accurately 
discern the correct inertia for a complex shape in the first place, some kind 
of approximation might be ok instead of this assert. Here's a couple of wacky 
ideas I had for ResetMassData. Take fixtures in order of descending mass, 
update the inertia in the first loop instead of calculating it at the end, and 
just ignore any fixtures that cause the problem lol - chances are they're the 
small ones with negligible influence on the inertia. A more reasonable but 
slower brute-force way would be to 'sample' the fixtures by doing many 
TestPoint() calls for a grid of points covering the body-space aabb of the 
fixtures. Since resetting a body's mass is not a heavily called function I 
doubt the speed would be a big deal but the quality of the sampling could be 
adjusted to suit if it was.

I'm not suggesting these as ideas for the engine, just ramblin'...

Original issue reported on code.google.com by iforc...@gmail.com on 5 Jul 2011 at 5:13

GoogleCodeExporter commented 9 years ago
Please take a look at this issue: 
http://code.google.com/p/box2d/issues/detail?id=192

I may have already fixed your problem.

Original comment by erinca...@gmail.com on 5 Jul 2011 at 9:27

GoogleCodeExporter commented 9 years ago
Indeed you have! Sorry, somehow I had missed that issue.

fwiw the attached test creates one body with 100 small fixtures, at a large 
distance from the body's origin. With the current source code I now have to 
increase this distance to over 1000 to get the assert to hit - and even then I 
need to hold down the 'R' key for a while. Thanks!

Original comment by iforc...@gmail.com on 10 Jul 2011 at 11:22

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by erinca...@gmail.com on 22 Aug 2011 at 10:53