inverse-kinematics
Version:
Inverse kinematics for 2D and 3D applications
76 lines (75 loc) • 2.48 kB
TypeScript
import { V2 } from '.';
import { Range } from './Range';
import { SolveOptions } from './SolveOptions';
export interface Link {
/**
* The rotation at the base of the link
*/
rotation: number;
/**
* undefined: No constraint
*
* Range: minimum angle, maximum angle (radians), positive is anticlockwise from previous Link's direction vector
*
* ExactRotation: Either a global, or local rotation which the Link is locked to
*/
constraints?: Constraints;
position: V2;
}
declare type Constraints = number | Range | ExactRotation;
interface ExactRotation {
value: number;
/**
* 'local': Relative to previous links direction vector
*
* 'global': Relative to the baseJoints world transform
*/
type: 'global' | 'local';
}
export interface SolveResult {
/**
* Copy of the structure of input links
* With the possibility of their rotation being changed
*/
links: Link[];
/**
* Returns the error distance after the solve step
*/
getErrorDistance: () => number;
/**
* true if the solve terminates early due to the end effector being close to the target.
* undefined if solve has adjusted the rotations in links
*
* undefined is used here as we don't rerun error checking after the angle adjustment, thus it cannot be known true or false.
* This is done to improve performance
*/
isWithinAcceptedError: true | undefined;
}
/**
* Changes joint angle to minimize distance of end effector to target
*
* If given no options, runs in FABRIK mode
*/
export declare function solve(links: Link[], baseJoint: JointTransform, target: V2, options?: SolveOptions): SolveResult;
export interface JointTransform {
position: V2;
rotation: number;
}
/**
* Distance from end effector to the target
*/
export declare function getErrorDistance(links: Link[], base: JointTransform, target: V2): number;
/**
* Absolute position of the end effector (last links tip)
*/
export declare function getEndEffectorPosition(links: Link[], joint: JointTransform): V2;
/**
* Returns the absolute position and rotation of each link
*/
export declare function getJointTransforms(links: Link[], joint: JointTransform): {
transforms: JointTransform[];
effectorPosition: V2;
effectorRotation: number;
};
export declare function buildLink(position: V2, rotation?: number, constraint?: number | Range | ExactRotation): Link;
export {};