Newton's Cradle

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
BabaJustin
Posts: 30
Joined: Mon Apr 25, 2011 6:07 pm

Newton's Cradle

Post by BabaJustin »

I am probably missing something obvious, but how would one go about setting up something similar to a Newton's Cradle effect? Where one object collides with another, and transfers it's momentum and stops moving itself. None of the changes I have tried have provided quite the effect I'm going for, the colliding object is maintaining most of it's velocity.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newton's Cradle

Post by Norbo »

The Newton's Cradle momentum transfer requires that the objects undergo elastic collision. In elastic collision, the magnitude of relative velocity is about the same as it was before the collision. In inelastic collision, the objects have a relative velocity near zero (they are just sliding along with each other). So, ensure that the interaction properties between the entities has a bounciness of 1 (or close to it).

Note that you don't have to set the bounciness of all the objects to 1 for this to work. Instead, it is possible to assign a specific material-material relationship using the MaterialManager (requires the development fork version to work properly: http://bepuphysics.codeplex.com/SourceC ... evelopment). Note that entities can share materials.

To get a proper result, the masses should be identical.

Finally, the objects must not be in contact. They can be very close, but if there exists a contact constraint between the objects, the momentum transfer will not work quite as expected due to a quirk of the solving method.
BabaJustin
Posts: 30
Joined: Mon Apr 25, 2011 6:07 pm

Re: Newton's Cradle

Post by BabaJustin »

That .... was incredibly easy. Not only that, but now I have tons of great ideas on what to do with the MaterialManager!

Thanks a ton!!
BabaJustin
Posts: 30
Joined: Mon Apr 25, 2011 6:07 pm

Re: Newton's Cradle

Post by BabaJustin »

Is there a way to prevent the objects from flipping up when they collide though?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newton's Cradle

Post by Norbo »

That depends on the context. There's one sure fire way to stop them from flipping- set the LocalInertiaTensorInverse to all zeroes, or only one or two of the rows. That gives them infinite rotational inertia, so nothing can make them rotate around the zeroed-out axes. Obviously that may cause some unwanted side effects, but I'd need more information to create a more targeted solution.

Modifying the inertia without going all the way to infinities might work too. Scaling a row down will increases the inertia around that axis.
BabaJustin
Posts: 30
Joined: Mon Apr 25, 2011 6:07 pm

Re: Newton's Cradle

Post by BabaJustin »

Two cylinders colliding with each other on a flat surface. When they collide sometimes (but not all the time) they flip over.

I don't want to completely disable rotational inertia on them though.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newton's Cradle

Post by Norbo »

Two cylinders colliding with each other on a flat surface. When they collide sometimes (but not all the time) they flip over.
Completely eliminating that will be difficult. The incremental manifold creates a single contact point per frame. If that is at the very bottom or top of the cylinder, it will impart a significant angular velocity to the objects and could cause a flip. Decreasing the time step duration will lessen the effect. Using shapes which have a special case that generates a full manifold, like box-box, will also mostly avoid the issue.

Changing the dimensions of the cylinders or modifying the inertia tensor without completely disabling rotation could help mitigate it, though.

It could also be something else, though I'd probably need a video to make the distinction.
BabaJustin
Posts: 30
Joined: Mon Apr 25, 2011 6:07 pm

Re: Newton's Cradle

Post by BabaJustin »

I have the time step ( 90 hz ) about as low as the frame rate will support.

What shape would you recommend I use instead of a Cylinder?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newton's Cradle

Post by Norbo »

Judging by the way it behaves, simply changing it to another shape probably won't help much. Using Boxes instead would help a little bit sometimes, but it couldn't completely eliminate the issue because it's still possible for the box to generate a contact manifold on impact which doesn't evenly transmit momentum. In fact, in some scenarios, doing so wouldn't even be the physically correct option.

I would recommend playing around with the LocalInertiaTensorInverse a bit more, and possibly thinning the the shape vertically so that impact points above or below center can't generate as much angular momentum. Here's an example of how thinning could help:
angularimpulse.jpg
angularimpulse.jpg (47.62 KiB) Viewed 9574 times
Due to the inertia tensor and smaller impact offset, the thinner shapes generate very little angular momentum compared to the fatter objects.

Getting too thin will cause other problems. Also note that cylinders use internal margins in v0.16.0, which means that instead of the collision margin expanding outward beyond the shape, it actually is built into the dimensions. If the cylinder height is set to less than 2 times the collision margin, or the radius is set to less than the margin, the shape will be partially inverted.

Scaling down the inverse will result in a rotationally 'heavy' appearance, but you can scale individual rows to see if you can improve the behavior a bit. Scaling upwards makes it rotationally 'lighter,' which may help landings from ramps appear more natural.
BabaJustin
Posts: 30
Joined: Mon Apr 25, 2011 6:07 pm

Re: Newton's Cradle

Post by BabaJustin »

Would it be possible to move the impact point when a collision is detected based on which objects are colliding?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Newton's Cradle

Post by Norbo »

Technically, yes. The immediate version (present tense) of the contact created or pair updated events would let you modify the contact objects directly. Care would need to be taken not to move the contact when it shouldn't be moved, or else collisions would behave very weirdly.
BabaJustin
Posts: 30
Joined: Mon Apr 25, 2011 6:07 pm

Re: Newton's Cradle

Post by BabaJustin »

Ok, so I think we settled on a solution I'm happy with now.

In addition to tuning the Inertia, I created a SingleEntityAngularMotor to push the objects back to their default orientation. It still allows for some rotation, but ultimately the objects end up sitting flat.
Post Reply