title: Little help with implementing Hookes law/elastic rope?
body: <p>Please refer to the video at</p>
  
  <p><a href="http://www.youtube.com/watch?v=_DyzwZJaDfM" rel="nofollow">http://www.youtube.com/watch?v=_DyzwZJaDfM</a></p>
  
  <p>The "brown" body is controlled with mouse and when mouse is pressed I calculate force using  Hookes law (refereed  to <a href="http://www.box2d.org/forum/viewtopic.php?f=4&amp;t=116" rel="nofollow">http://www.box2d.org/forum/viewtopic.php?f=4&amp;t=116</a> ) and the "blue" body should attract to the "brown" body.</p>
  
  <p>But as seen in the video,"blue" body keep orbiting around and doesn't come stop.What I wanted to implement is "elastic rope" like thing.
  First I tried using DistanceJoint ,but I cannot give a static distance to the joint.</p>
  
  <p>here is my implementation for hookes law -</p>
  
  <pre><code>-(void)applyHookesLaw:(b2Body*)bodyA:(b2Body*)bodyB:(float) k:(float) friction:(float)desiredDist
  {
      b2Vec2 pA=bodyA-&gt;GetPosition();
      b2Vec2 pB=bodyB-&gt;GetPosition();
      b2Vec2 diff=pB- pA;
      b2Vec2 vA=bodyA-&gt;GetLinearVelocity();
      b2Vec2 vB=bodyB-&gt;GetLinearVelocity();
      b2Vec2 vdiff=vB-vA;
      float dx=diff.Normalize();
      float vrel=vdiff.x * diff.x + vdiff.y * diff.y;
      float forceMag= -k*(dx-desiredDist);//-friction*vrel;
      diff*=forceMag;
      bodyA-&gt;ApplyForce(-1*diff,bodyB-&gt;GetPosition());
  
      //bodyA-&gt;wakeUp() 
  
  }
  </code></pre>
  
  <p>Any tips please?</p>
  
  <p>PS - gravity of the world is 0.0</p>