Hooke Spring

From Box2D Wiki

The Hooke Spring

Hooke's law shows that F = -kx for a spring (where F is the force, k is the spring constant, and x is the distance stretched from equilibrium).

Example

A Hooke spring can be found in the main distribution's ElasticBody test (C++, Python).

The function to be used is AddSpringForce:

void AddSpringForce(b2Body& bA, b2Vec2& localA, b2Body& bB, b2Vec2& localB, float32 k, float32 friction, float32 desiredDist);

Where:

  • bA is the first body
  • localA the local point on the first body to attach the spring
  • bB is the second body
  • localB the local point on the second body to attach the spring
  • k is the spring constant (N/m, see wikipedia entry)
  • friction is the friction coefficient
  • desiredDist is the equilibrium point to oscillate around

See Also

  • Hooke spring forum post
TOOLBOX
LANGUAGES