npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

verlet-constraint

1.1.0 • Public • Published

verlet-constraint

stable

Creates a single 2D/3D constraint, useful in a verlet physics system.

var Constraint = require('verlet-constraint')
var Point = require('verlet-point')
 
var points = [ Point(), Point() ]
var c = Constraint(points, { stiffness: 0.05, restingDistance: 15 })
 
//this pulls/pushes the two points 
c.solve()

The points can be bare objects with position and optional mass. Mass defaults to 1.0.

var c = Constraint([ { position: [25, 25] }, { position: [50, 50], mass: 2 } ])
c.solve()

By default, assumes 2D and points with [x, y]. You can require an explicit dimension like so:

var Constraint2D = require('verlet-constraint/2d') //points [x, y]
var Constraint3D = require('verlet-constraint/3d') //points [x, y, z]

Usage

NPM

c = Constraint(points[, opt])

Creates a new constraint that operates on the two point objects given in the points array. Options:

  • restingDistance the desired resting distance between the two points, defaults to using the distance between the two points during construction
  • stiffness the stiffness of the constraint, defaults to 1.0

c.solve()

Solves this constraint by pushing/pulling each point. If one of the points has a mass of zero, that body will be considered "unmovable".

c.points

An array of the point objects that were specified to this constraint.

c.restingDistance

The desired distance

c.stiffness

The desired stiffness

License

MIT, see LICENSE.md for details.

install

npm i verlet-constraint

Downloadsweekly downloads

6

version

1.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
Report a vulnerability