constraint-solver-js
Version:
2D rigid body constraint solver written in typescript.
60 lines (59 loc) • 1.83 kB
TypeScript
import { Body } from "./body.js";
import { FixedConstraint } from "./fixed-constraint.js";
import { RotConstraint } from "./rot-constraint.js";
import { Solver } from "./solver.js";
/**
* Set of bodies, rotational constraints
* and fixed constraints.
*/
export declare class World {
private rotConstraints;
private fixConstraints;
private bodies;
private bodiesLst;
private indices;
private errors;
private dof;
private x;
/**
* World constructor.
* @param rotConstraints set of rotational constraints
* @param fixConstraints set of fixed constraints
* @throws `WorldSetupError` if set of constraints is
* inconsistent or usolvable.
*/
constructor(rotConstraints: RotConstraint[], fixConstraints: FixedConstraint[]);
/**
* Loops through rotConstraints and fixConstraints
* and adds bodies to bodies dictionary.
* If errors are found, appends error to `this.errors`
*/
private loadBodies;
private loadIndices;
private loadX0;
/**
* Calculates the degrees of freedom of a system with
* b bodies, r rotational constraints and f degrees of
* freedom.
* It follows the formula `deg_of_freedom = 3*b - 2*r - 3*f`
*/
private calcDegsOfFreedom;
/**
* Solves the set of constraints and bodies.
* Updates the bodies to their solved positions
* @param solver (optional) `fsolve-js.Solver`
* @throws UnableToSolveError if solver is unable to solve the system.
*/
solve(solver?: Solver): World;
/**
* Returns object where keys are bodies ids, values are bodies intances.
*/
getBodies(): {
[id: string]: Body;
};
private f;
private rotConstraintF;
private fixConstraintF;
private getBodyPosition;
private setBodyPosition;
}