API Docs for: 0.7.1
Show:

LinearSpring Class

A spring, connecting two bodies.

The Spring explicitly adds force and angularForce to the bodies.

Constructor

LinearSpring

(
  • bodyA
  • bodyB
  • [options]
)

Parameters:

  • bodyA Body
  • bodyB Body
  • [options] Object optional
    • [restLength] Number optional

      A number > 0. Default is the current distance between the world anchor points.

    • [stiffness=100] Number optional

      Spring constant (see Hookes Law). A number >= 0.

    • [damping=1] Number optional

      A number >= 0. Default: 1

    • [worldAnchorA] Array optional

      Where to hook the spring to body A, in world coordinates. Overrides the option "localAnchorA" if given.

    • [worldAnchorB] Array optional
    • [localAnchorA] Array optional

      Where to hook the spring to body A, in local body coordinates. Defaults to the body center.

    • [localAnchorB] Array optional

Methods

applyForce

()

Inherited from Spring but overwritten in src/objects/LinearSpring.js:112

Apply the spring force to the connected bodies.

getWorldAnchorA

(
  • result
)

Get the anchor point on body A, in world coordinates.

Parameters:

  • result Array

    The vector to store the result in.

getWorldAnchorB

(
  • result
)

Get the anchor point on body B, in world coordinates.

Parameters:

  • result Array

    The vector to store the result in.

setWorldAnchorA

(
  • worldAnchorA
)

Set the anchor point on body A, using world coordinates.

Parameters:

  • worldAnchorA Array

setWorldAnchorB

(
  • worldAnchorB
)

Set the anchor point on body B, using world coordinates.

Parameters:

  • worldAnchorB Array

Properties

bodyA

Body

First connected body.

bodyB

Body

Second connected body.

damping

Number

Damping of the spring.

localAnchorA

Array

Anchor for bodyA in local bodyA coordinates.

localAnchorB

Array

Anchor for bodyB in local bodyB coordinates.

restLength

Number

Rest length of the spring.

stiffness

Number

Stiffness of the spring.