Spiral springs

Official forum for the Chipmunk2D Physics Library.
Post Reply
ioannis
Posts: 6
Joined: Fri May 29, 2009 3:09 pm
Contact:

Spiral springs

Post by ioannis »

Is there a way to model spiral springs, like those in mechanical watches ?

thanks
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Spiral springs

Post by slembcke »

The trunk code has damped rotary springs. If you are using 4.x, it's pretty easy to calculate and apply the rotary forces.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ioannis
Posts: 6
Joined: Fri May 29, 2009 3:09 pm
Contact:

Re: Spiral springs

Post by ioannis »

thanks.

Since cpDampedRotarySpringNew doesn't specify anchors, does it apply to the centre of the bodies? Also, I want it to be fairly stiff, so it gets back to its resting angle quickly and stops oscillating quickly (high dampening). However, even with dampening is set to 1.0, it keeps on oscillating for a long time. If I'm not mistaken, dampening values higher than 1.0 are a bad idea, right? What can I do about that?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Spiral springs

Post by slembcke »

The rotary spring constraint only changes rotational properties. If you want them pinned together as well, you'll need to add a separate pivot joint. It is quite normal to use a damping value greater than 1.0 unless your objects have a very low moment of inertia.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ioannis
Posts: 6
Joined: Fri May 29, 2009 3:09 pm
Contact:

Re: Spiral springs

Post by ioannis »

Thanks. I did the following:

Code: Select all

	cpBody* staticBody = cpBodyNew(INFINITY, INFINITY);

	cpFloat radius = 100.0f;
	cpBody* body = cpSpaceAddBody(space, cpBodyNew(1.0, cpMomentForCircle(1.0, 0.0, radius/10.0, cpvzero)));
	cpBodySetPos(body,cpv(0.0,0.0));
	cpShape* shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
	
	cpFloat stiff = 3000.0f, damp = 20.0f;
	cpSpaceAddConstraint(space, cpDampedRotarySpringNew(body, staticBody, 0.0f, stiff, damp));
	cpSpaceAddConstraint(space, cpPivotJointNew2(body, staticBody, cpvzero, cpvzero));
which behaves close to what I want. I've played with the moment of inertia as you can see. I hope these sort of values will not cause any problems (instabilities?)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Spiral springs

Post by slembcke »

The problem with the moment of inertia is that it's really hard to guess good values for because it's based on not only the mass, but the distribution of weight around the center of gravity. The helper function Chipmunk provides are really just helping you estimate based on perfect shapes.

The real problem is when somebody has a square that they want to guess the mass and moment of inertia for. It has a width of 100 pixels (and they are using pixels as the Chipmunk units), and they think it doesn't matter what the mass is as long as it's relatable to other objects. This is a good assumption. They just use a mass of 1.0, and then move on to guess a good moment of inertia. Trying 1.0 for that is going to be disastrous! A more correct value is going to be over 1000, and even more if it's an empty crate. This is also a reason why using non-pixel coords is a good idea, but it hasn't really ever turned out to be a problem. Chipmunk uses double precision floating point numbers by default as they tend to be faster on non-mobile processors.

Now back to your comment about futzing with the moment. It's fine to do so, but you are doing this:

Code: Select all

 cpMomentForCircle(1.0, 0.0, radius/10.0, cpvzero)
I would do this instead:

Code: Select all

 cpMomentForCircle(1.0, 0.0, radius, cpvzero)/someValue
That way if you change the radius later you will preserve the ratio that you found that you liked. As the size of an object changes, the ratio of it's moment to the moment of one of the simple shapes that Chipmunk can calculate will stay the same.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 2 guests