DavidKimYongRak / box2d

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

Rotational inertia of polygons is not computed correctly causing crashes in some cases #192

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Make a dynamic body with a polygon fixture with the following vertices:
(-2.625452, 4.425248)
(-3.101252, 8.107347)
(-4.639852, 5.767548)
(-4.937052, 4.040548)
(-3.365452, 3.517048)

What is the expected output? What do you see instead?
Box2D crashes with Assertion failed: (m_I > 0.0f) at function ResetMassData, 
file Box2D/Dynamics/b2Body.cpp, line 315

What version of the product are you using? On what operating system?
Version 2.2.0 on Mac OS X 10.6.6

Please provide any additional information below.
Rotational inertia of a polygon is computed relative to a point s that is 
chosen to be inside the polygon but is not the center of the mass. Then the 
rotational inertia relative to the body origin is computed by misusing the 
formula expressing the Parallel axis theorem, I=Icm + m * r * r,  since instead 
of Icm (rotational inertia relative to the center of mass) Is is used 
(rotational inertia relative to point s). The last line of method 
b2PolygonShape::ComputeMass(b2MassData* massData, float32 density) should be:

massData->I = density * I + massData->mass * (b2Dot(massData->center, 
massData->center) - b2Dot(center, center));

instead of

massData->I = density * I + massData->mass * b2Dot(s, s);

Original issue reported on code.google.com by peri.co...@gmail.com on 19 Apr 2011 at 1:01

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r192.

Original comment by erinca...@gmail.com on 26 Jun 2011 at 10:36

GoogleCodeExporter commented 9 years ago
Nice find! I'm impressed.

Fixed in Rev 192.

Original comment by erinca...@gmail.com on 26 Jun 2011 at 10:37

GoogleCodeExporter commented 9 years ago
Issue 200 has been merged into this issue.

Original comment by erinca...@gmail.com on 26 Jun 2011 at 10:47

GoogleCodeExporter commented 9 years ago
Issue 216 has been merged into this issue.

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