Class GSSolver

Iterative Gauss-Seidel constraint equation solver.




equationSortFunction?: ((a, b) => number)

Type declaration

    • (a, b): number
    • Function that is used to sort all equations before each solve.


      Returns number

equations: Equation[]

Current equations in the solver.

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.


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.


type: 1 = Solver.GS

The type of solver.

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.

GS: 1

Gauss-Seidel solver.


  • Add an equation to be solved.


    Returns void

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


    Returns void

  • Removes all currently added equations

    Returns void

  • Removes an equation


    Returns void

  • Method to be implemented in each subclass


    Returns void

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

    Returns void