How to simulate gears?

Discuss new features and future development.

How to simulate gears?

Postby JoeStrout » Sun Nov 30, 2008 6:48 pm

Any suggestions on how to efficiently simulate gears with Chipmunk?

Ideally, I'd like to use two circle bodies, and when they're in contact, have a rotation of one cause a corresponding rotation of the other. But I don't suppose there's anything that would do that automatically. I could model each gear as a big set of polygons (one for each gear tooth, perhaps plus a circle for the inner part), and let Chipmunk simulate it from first principles — I would expect this to work, but it'd be pretty inefficient.

Any suggestions or recommendations?

Thanks,
- Joe
JoeStrout
 
Posts: 7
Joined: Fri Nov 28, 2008 11:46 pm

Re: How to simulate gears?

Postby slembcke » Sun Nov 30, 2008 9:17 pm

It is possible to simulate gears using actual shapes, but it would awfully inefficient yes.

Zany Doodle uses Chipmunk and does just that. It's performance seems to be just dandy.
http://www.youtube.com/watch?v=Gk9o2zxKPbM

The good news is that I've created a new joint type for gears in trunk. You'll have to wait for it if you want to get it in a stable release though.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: How to simulate gears?

Postby JoeStrout » Sun Nov 30, 2008 11:34 pm

Thanks. I should have added that I also need to simulate two wheels connected by a belt. Would the new gear joint type handle that as well?

If I can't wait for the next stable release, and want to avoid using actual shapes, is there any other way to fake it? In the case of two wheels connected by a belt, I wonder if a set of (say) three pin joints between the wheels would do the trick. Seems like it should, if the wheels are the same size, but not if they differ in size (since in that case one should spin faster than the other). And this wouldn't work for gears.

But what about manually doing something on each update? Maybe using cpDampedSpring, modeling a spring between (say) the top of each wheel in the case of a belt, or at the contact point in the case of two gears? Hmm, but the cpBody docs warn that it's likely to be unstable with large damping values. Perhaps there's some way to calculate the force each gear (or wheel) should apply to the other — but my physics is too rusty to see it. Any pointers?

Thanks,
- Joe
JoeStrout
 
Posts: 7
Joined: Fri Nov 28, 2008 11:46 pm

Re: How to simulate gears?

Postby slembcke » Mon Dec 01, 2008 12:12 am

Using a pair of pin joints would probably work OK if the ratio is 1:1.

I'm not quite sure how you'd do it otherwise. Applying torques to the objects is not very stable. I've tried that before with limited success. Creating a constraint for it was the "correct" way to do it, and wasn't too hard to implement once I had refactored the way that joints worked internally. Backporting the code would be pretty difficult.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Features/Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron