spring with damping

Hi,

Have been looking through the examples. Can't find one.

How is it possible to use a spring to bring a body back to its original position?
To simulate a spring you should easily be able to apply Hooke's law (http://en.wikipedia.org/wiki/Spring_equation).

In words:
Take distance between the two points minus their original distance to get the amount they've stretched/compressed.
Multiply that amount by the spring's negative spring-/force-constant and you'll have your resulting force.
The same force is applied to both objects (always towards eachother since the formula automatically covers both compression and stretch).

To get damping, I think you can simply add another factor (less than 1) to the formula (constant damping), but I'm not sure there wasn't a quirk somewhere...

Note that systems with springs sometimes get very unstable, especially if you link them like a chain. We did that for a project I was working on a while ago, and we sure learned patience when tweaking the values hehe.
On another thread at viewtopic.php?f=4&t=116&hilit=hooke I posted some Java Box2d code to apply a simple damped spring force (should be simple to translate to C++ or AS3). It has the flaw that the springs are both attached at the body centers of mass. It should be a fairly simple exercise to extend it so that it connects to arbitrary points on each body if you need that functionality.

Original thread: https://box2d.org/forum/viewtopic.php?t=196