Package Exports
- inverse-kinematics
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (inverse-kinematics) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
IK - Inverse Kinematics
Inverse kinematics for 2D and (soon) 3D applications.
Quickstart 2D
https://codesandbox.io/s/quickstart-2d-ob7yw?file=/src/index.ts
import { V2, Solve2D } from 'inverse-kinematics'
// Create a list of 'links'
// Three links, of 50 units long, all pointing in the same direction
const bones: Solve2D.Link[] = [
{ rotation: 0, length: 50 },
{ rotation: 0, length: 50 },
{ rotation: 0, length: 50 },
]
// Define the base of the links
const base: Solve2D.JointTransform = { position: [0, 0], rotation: 0 }
// Define a target for the 'end effector' or the tip of the last link to move to
const target: V2 = [50, 50]
// Iterate until the error is within acceptable range
const acceptedError = 10
function loop() {
const error = Solve2D.getErrorDistance(bones, base, target)
if (error < acceptedError) return
Solve2D.solve(bones, base.position, target)
setTimeout(loop, 100)
console.log(error.toFixed(0))
}
loop()Examples
Check out https://tmf-code.github.io/inverse-kinematics or find them in the folder /example
Terminology
Base
The starting point of the link chain
Link
A Link can be thought of as a connecting bar, that extends from it's joint, to the joint of the next link in the chain.
Joint
Occurs at the tip of the preceding link, and at the base of the following link. We've chosen to consider ownership of the joint to the following link. So that itself can be considered a Base to the remaining links.
Visulization of terminology
You could visualize a link chain like so:
Base
-> rotate(link_1.rotation) [joint_1] -> translate(link_1.length)
-> rotate(link_2.rotation) [joint_2] -> translate(link_2.length)