API Docs for: 0.7.1
Show:

GSSolver Class

Extends Solver

Iterative Gauss-Seidel constraint equation solver.

Constructor

GSSolver

(
  • [options]
)

Parameters:

  • [options] Object optional
    • [iterations=10] Number optional
    • [tolerance=0] Number optional

Methods

addEquation

(
  • eq
)

Add an equation to be solved.

Parameters:

addEquations

(
  • eqs
)

Add equations. Same as .addEquation, but this time the argument is an array of Equations

Parameters:

  • eqs Array

emit

(
  • event
)
EventEmitter

Emit an event.

Parameters:

  • event Object
    • type String

Returns:

EventEmitter:

The self object, for chainability.

has

(
  • type
  • listener
)
Boolean

Check if an event listener is added

Parameters:

  • type String
  • listener Function

Returns:

Boolean:

off

(
  • type
  • listener
)
EventEmitter

Remove an event listener

Parameters:

  • type String
  • listener Function

Returns:

EventEmitter:

The self object, for chainability.

on

(
  • type
  • listener
)
EventEmitter

Add an event listener

Parameters:

  • type String
  • listener Function

Returns:

EventEmitter:

The self object, for chainability.

removeAllEquations

()

Remove all currently added equations.

removeEquation

(
  • eq
)

Remove an equation.

Parameters:

solve

(
  • h
  • world
)

Inherited from Solver but overwritten in src/solver/GSSolver.js:77

Solve the system of equations

Parameters:

  • h Number

    Time step

  • world World

    World to solve

solveIsland

(
  • dt
  • island
)

Solves all constraints in an island.

Parameters:

sortEquations

()

Sort all equations using the .equationSortFunction. Should be called by subclasses before solving.

Properties

equations

Array

Current equations in the solver.

equationSortFunction

Function | Boolean

Function that is used to sort all equations before each solve.

frictionIterations

Number

Number of solver iterations that are used to approximate normal forces used for friction (F_friction = mu * F_normal). These friction forces will override any other friction forces that are set. If you set frictionIterations = 0, then this feature will be disabled.

Use only frictionIterations > 0 if the approximated normal force (F_normal = mass * gravity) is not good enough. Examples of where it can happen is in space games where gravity is zero, or in tall stacks where the normal force is large at bottom but small at top.

Default: 0

iterations

Number

The max number of iterations to do when solving. More gives better results, but is more expensive.

tolerance

Number

The error tolerance, per constraint. If the total error is below this limit, the solver will stop iterating. Set to zero for as good solution as possible, but to something larger than zero to make computations faster.

Default: 1e-7

usedIterations

Number

The number of iterations that were made during the last solve. If .tolerance is zero, this value will always be equal to .iterations, but if .tolerance is larger than zero, and the solver can quit early, then this number will be somewhere between 1 and .iterations.

useZeroRHS

Boolean

Set to true to set all right hand side terms to zero when solving. Can be handy for a few applications.