Physics:2D Physics Engine:Springs

From GPWiki

Files:GUITutorial_warn.gif The Game Programming Wiki has moved! Files:GUITutorial_warn.gif

The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server.

However, the GPWiki forums are still active! Come say hello.

This article is part of a series:

Files:GUITutorial_warn.gif This wiki page is under construction!

This page may be incomplete, missing information, or inaccurate!

Contents

Explanation

A spring is a connection between two objects that will use impulses to put it back to the correct position instead of constraining it.

Description

Hooke's Law

Hooke's Law states that the the force to move two objects together with a spring is proportional to the distance apart, or

  • \vec{F}: Force vector to restore the objects to the correct position
  • k: Spring constant, a number describing how fast the objects will move to get to the correct position
  • \vec{x}: A vector equal to the difference in position of the two bodies' positions

\vec{F} = -k\vec{x}

Hooke's Law with Damping

Using the plain version of Hooke's Law will cause the spring to oscillate forever. However, a modified version with damping causes the objects eventually stop.

  • \vec{F}: Force vector to restore the objects to the correct position
  • k: Spring constant, a number describing how fast the objects will move to get to the correct position
  • \vec{x}: A vector equal to the difference in position of the two bodies' positions
  • \vec{v}: A vector equal to the difference in velocity of the two bodies
  • b: Damping constant, a number describing how quickly the objects will slow to a stop. Negative values will cause the objects to accelerate

\vec{F} = -k\vec{x} - b\vec{v}

Alternate Spring Equations

There are more possible equations than Hooke's Law. A rather useful one keeps the bodies a certain distance apart.

Length Spring

This type of spring will keep the two objects a certain distance apart.

  • \vec{F}: Force vector to restore the objects to the correct position
  • k: Spring constant, a number describing how fast the objects will move to get to the correct position
  • \vec{x}: A vector equal to the difference in position of the two bodies' positions
  • |\vec{x}|: The magnitude of \vec{x}
  • d: The distance to keep the bodies apart (the desired length of the spring)
  • \vec{v}: A vector equal to the difference in velocity of the two bodies
  • b: Damping constant, a number describing how quickly the objects will slow to a stop. Negative values will cause the objects to accelerate

\vec{F} = -k(|\vec{x}|-d)(\vec{x}/|\vec{x}|) - b\vec{v}