UNPKG

inverse-kinematics

Version:

Inverse kinematics for 2D and 3D applications

94 lines (93 loc) 2.93 kB
import { SolveOptions } from '.'; import { Quaternion } from './math/Quaternion'; import { V3 } from './math/V3'; import { Range } from './Range'; export interface Link { /** * The rotation at the base of the link */ rotation: Quaternion; /** * undefined: No constraint * * {pitch, yaw, roll}: Range | Number * * Range: minimum angle, maximum angle (radians), positive is anticlockwise from previous Link's direction vector * * number: the range of rotation (radian) about the previous links direction vector. A rotation of 90 deg would be 45 deg either direction * * ExactRotation: Either a global, or local rotation which the Link is locked to */ constraints?: Constraints; position: V3; } declare type Constraints = EulerConstraint | ExactRotation; interface EulerConstraint { /** * Rotation about X */ pitch?: number | Range; /** * Rotation about Y */ yaw?: number | Range; /** * Rotation about Z */ roll?: number | Range; } interface ExactRotation { value: Quaternion; /** * '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: V3, options?: SolveOptions): SolveResult; export interface JointTransform { position: V3; rotation: Quaternion; } /** * Distance from end effector to the target */ export declare function getErrorDistance(links: Link[], base: JointTransform, target: V3): number; /** * Absolute position of the end effector (last links tip) */ export declare function getEndEffectorPosition(links: Link[], joint: JointTransform): V3; /** * Returns the absolute position and rotation of each link */ export declare function getJointTransforms(links: Link[], joint: JointTransform): { transforms: JointTransform[]; effectorPosition: V3; }; export declare function buildLink(position: V3, rotation?: Quaternion, constraints?: Constraints): Link; export {};