# Kinematics

The maths every component shares. No React, no three.js, no dependencies — import it on its own if you only want the solver.

> For the complete index, see [llms.txt](https://robocn.dev/llms.txt). A Markdown version of any page is available by appending `.md` to its URL or by sending an `Accept: text/markdown` header.

## Install

```bash
bunx --bun shadcn@latest add https://robocn.dev/r/robot-kinematics.json
```

Registry item: `robot-kinematics` · [`https://robocn.dev/r/robot-kinematics.json`](https://robocn.dev/r/robot-kinematics.json)

## Usage

```tsx
import { solveChain2, chainAngles2 } from "@/lib/robocn/kinematics"

const joints = solveChain2({ x: 0, y: 0 }, { x: 40, y: 25 }, [30, 24, 16])
const angles = chainAngles2(joints)
```

## API

| name | type | default | description |
| --- | --- | --- | --- |
| `solveChain2 / solveChain3` | `(root, target, links, options?) => Vec[]` | — | Joint positions from shoulder to tip. Two links solve analytically; longer chains run FABRIK, seeded with the previous pose for temporal coherence. |
| `solveElbow2 / solveElbow3` | `(root, target, upper, fore, bend?) => Vec` | — | Law-of-cosines elbow, with a chosen side. |
| `solveDelta` | `(target, geometry) => DeltaPose` | — | Closed-form delta IK: anchors, elbows, platform corners and motor angles, plus whether the target was reachable. |
| `forwardChain2 / chainAngles2 / chainLinks2` | `…` | — | Forward kinematics and its inverse, for driving joints directly. |
| `chainReach / chainMinReach / clampToReach2` | `…` | — | The annulus a chain can touch. Out-of-reach targets clamp onto it rather than failing. |
| `isometric / isometricDepth` | `(v: Vec3, options?) => Vec2 | number` | — | Flatten 3D points for SVG, and sort parts front to back. |

## Source

- `src/lib/robocn/kinematics.ts`
