Starting with chipmunk2d

Official forum for the Chipmunk2D Physics Library.
Post Reply
jhneves
Posts: 9
Joined: Thu Jul 25, 2013 12:42 pm
Contact:

Starting with chipmunk2d

Post by jhneves »

Hi I am just getting started with chipmunk2d (I am using the josephg's js version). I don't understand why I have to provide the moment of inertia when creating a body and what is it used for?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Starting with chipmunk2d

Post by slembcke »

So the extra short answer is that mass is how hard it is to make an object accelerate and the moment of inertia is how hard it is to get it spinning. So just think of it as rotational mass.

So inertia is how hard it is to make an object move. Mass and inertia are basically the same thing. When something has more mass, it has more inertia. A "moment" in physics and engineering describes a force that causes something to turn. Also sort of another name for torque. So that's where the terminology comes from. Not the clearest naming, but I didn't make them up. ;)

So why do you need to calculate the moment of inertia? Shouldn't the rotational mass be closely related to it's regular mass? Sadly it's not that simple. Like with torque where a wrench with a handle that is twice as long gives you twice as much torque, spreading the mass farther from the center of gravity of an object gives it a higher moment of inertia. So you need to estimate the moment of inertia using the mass of the object, it's shape and some calculus. Since the mass distribution in real life objects is so varied, the moment value doesn't really need to be that close to "perfect". The cpMomentFor*() functions give you a bunch of basic formulas to work with for filled shapes. You can add them together if you have a shape made out of several of them.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jhneves
Posts: 9
Joined: Thu Jul 25, 2013 12:42 pm
Contact:

Re: Starting with chipmunk2d

Post by jhneves »

great.. I am starting to get it...

so, if I have a body that has only a box shape attached to it, I would have to do this:

Code: Select all

body = new cp.Body(1, cp.momentForBox(1, 30, 30));
shape = new cp.BoxShape(body, 30, 30));
right?

but what happens if my body has more than 1 shape? For example... 2 boxes and 1 circle?
would I have to do this:

Code: Select all

momentOfIntertia = (cp.momentForBox(1,30,30)) * 2 ) + cp.momentForCircle(10, 0, 15, cp.v(0,0));
??
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Starting with chipmunk2d

Post by slembcke »

So offsets from the center of gravity are important when calculating moment of inertia. Your code has all of the shapes centered on the center of gravity. Probably not what you mean. What offsets are you using when attaching them, they should be the same.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jhneves
Posts: 9
Joined: Thu Jul 25, 2013 12:42 pm
Contact:

Re: Starting with chipmunk2d

Post by jhneves »

I think I still don't get it. I am coming from box2d, so please help me understand....

in box2d when I wanted to create a body with many shapes I just needed to add them to the body... I didn't need to provide a moment of inertia for the body...

in chipmunk2d, how can I provide the "correct" moment of inertia if I want a body with many shapes?
or
can I configure chipmunk2d to automatically calculate it?
jhneves
Posts: 9
Joined: Thu Jul 25, 2013 12:42 pm
Contact:

Re: Starting with chipmunk2d

Post by jhneves »

bump :geek:
Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests