Strange behaviour of long rotating bodies

Post Reply
Adam27
Posts: 4
Joined: Sun Nov 18, 2012 3:22 pm

Strange behaviour of long rotating bodies

Post by Adam27 »

Hi,

I develop an engine and try to use the Bullet Physics Library in order to add physics to the engine. However, the simulation looks very unrealistic when I create some long bodies, such as cylinders or capsules, and make them rotate. They will rotate all the time and will never fall down to the ground. Here's how it looks like:

http://youtu.be/-zU_o9ry6w0

This bug is really annoying and I have no idea what might cause it. I use the code from Bullet's demos. Do you know what I could have done wrong and how to fix it? I'll post the code if it's necessary.

Thanks in advance,
Adam
mdias
Posts: 12
Joined: Thu Jun 28, 2012 2:21 pm

Re: Strange behaviour of long rotating bodies

Post by mdias »

Looks like a wrong local inertia is set.

Are you using cylinders alone or using compound shapes? I get similar results if using compound shapes and the shapes aren't centered.
DannyChapman
Posts: 84
Joined: Sun Jan 07, 2007 4:29 pm
Location: Oxford, England
Contact:

Re: Strange behaviour of long rotating bodies

Post by DannyChapman »

There are two things I think:

1. It's quite usual to drop one of the terms from the integration of rotational motion, because it helps with numerical stability. Without checking, I don't know if Bullet does this. As a result angular velocity gets conserved, but not necessarily angular momentum, and you don't (I think) get the property that objects don't "like" to rotate around their long principle axis of inertia. (I'm a bit hazy on the details... it's been a while!).

2. It looks like you've got huge cylindrical objects on a perfectly flat plane. The rotation of the cylinders is what is stopping them from falling down - in reality you just don't get these situations. Objects deform, lumps and bumps in the ground will prevent the friction maintaining the rotation etc, so your intuition about what is right/wrong may not be correct. Often physics demos have much larger objects than are found in real life - so effectively they run in a situation where gravity is reduced.
Adam27
Posts: 4
Joined: Sun Nov 18, 2012 3:22 pm

Re: Strange behaviour of long rotating bodies

Post by Adam27 »

@mdias: I'm using cylinder shapes. Here's my code, could the local inertia be wrongly calculated? (d - diameter, h - height, mass is 10)

Code: Select all

btCollisionShape* shape = new btCylinderShape(btVector3(d/2, h/2, d/2));

btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3(pos.x, pos.y, pos.z));

btVector3 localInertia(0, 0, 0);
if (mass>0)
	shape->calculateLocalInertia(mass, localInertia);

btDefaultMotionState* motionState = new btDefaultMotionState(transform);
body = new btRigidBody(mass, motionState, shape, localInertia);
@DannyChapman: I know the gyroscopic effect, but for me it doesn't look like that. On the video cylinders aren't rotating very fast, but won't fall to the ground anyway. The force of gravity still works and should make them fall down after several seconds. I could be wrong, but I think it's a bug either in Bullet or somewhere in my code.
marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am
Contact:

Re: Strange behaviour of long rotating bodies

Post by marios »

Could you provide information about exact dimensions of cylinder shapes? Bullet is very bad in simulating shapes that are bigger than 10 units
Adam27
Posts: 4
Joined: Sun Nov 18, 2012 3:22 pm

Re: Strange behaviour of long rotating bodies

Post by Adam27 »

Diameter is 0.5, height is 8. The shorter the cylinders (or capsules, I've tested them as well) are, the less the effect is visible.
DannyChapman
Posts: 84
Joined: Sun Jan 07, 2007 4:29 pm
Location: Oxford, England
Contact:

Re: Strange behaviour of long rotating bodies

Post by DannyChapman »

Adam27 wrote:Diameter is 0.5, height is 8. The shorter the cylinders (or capsules, I've tested them as well) are, the less the effect is visible.
What's your gravity value? If it's around 10, then your objects are absolutely massive - unlike anything you've seen in reality...
Adam27
Posts: 4
Joined: Sun Nov 18, 2012 3:22 pm

Re: Strange behaviour of long rotating bodies

Post by Adam27 »

What's your gravity value? If it's around 10, then your objects are absolutely massive - unlike anything you've seen in reality...
It is 15, but no matter to what value I set the gravity, bodies still behave the same, except for the fact then everything moves slower of course. I also tried changing mass of the bodies, but to no avail.
zarlox
Posts: 31
Joined: Tue Apr 26, 2011 5:52 pm

Re: Strange behaviour of long rotating bodies

Post by zarlox »

Modify one of the basic demo that come with bullet in order to reproduce the issue and attach it to your post. its gonna be easier for others to test
anthrax11
Posts: 72
Joined: Wed Feb 24, 2010 9:49 pm

Re: Strange behaviour of long rotating bodies

Post by anthrax11 »

btCylinderShape returns the correct local inertia as of r2235. With m=1, r=0.25 and h=8:
Iy = m * r*r / 2 = 0.25*0.25 / 2 = 0.03125
Ix = Iz = m * (3*r*r + h*h) / 12 = (0.1875 + 64) / 12 = 5.265625

I don't know what the mass is, but I think you should try to increase it, because as Danny said, there's not often a wildly spinning solid 8-meter cylinder weighing just 1 kg in the real world.
DannyChapman
Posts: 84
Joined: Sun Jan 07, 2007 4:29 pm
Location: Oxford, England
Contact:

Re: Strange behaviour of long rotating bodies

Post by DannyChapman »

Adam27 wrote:
What's your gravity value? If it's around 10, then your objects are absolutely massive - unlike anything you've seen in reality...
It is 15, but no matter to what value I set the gravity, bodies still behave the same, except for the fact then everything moves slower of course. I also tried changing mass of the bodies, but to no avail.
Actually... mass cancels out completely, so there shouldn't be any difference in behaviour depending on the mass...

I'm still uncertain what it is you're trying to simulate. If this is a real world object, like a table, then set the dimensions to sensible values (including gravity), and check against reality. I almost guarantee it won't look like what you're seeing here.

I'm still pretty sure you have three problems:

1. Using huge dimensions - what you have now is like a table in a tiny fraction of Earth's gravity

2. Using "perfect" interactions - i.e. no lumps and bumps that in the real world would result in rolling friction which would remove energy from the system, and also your friction looks like it's stopping the objects just slipping down, to some extent.

3. Possibly approximations in the Bullet integrator that show up with fast rotations.

I've seen things similar what you're seeing before (not with Bullet) - but in practice, when you represent realistic objects and make sure they don't have super-perfect properties, the problems actually go away.
Post Reply