# Stewart kinematics

Closed-form inverse kinematics for a six-legged parallel platform: give it a head pose, get six leg lengths and their stroke.

> 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/stewart-kinematics.json
```

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

## Notes

- Anchors sit in three pairs 120° apart on both rings and each leg crosses to the far anchor of its pair, so every leg has the same home length.
- Out-of-range poses still return complete geometry with reachable false, so a UI can draw the fault instead of handling an exception.

## Usage

```tsx
import { solveStewart } from "@/lib/robocn/stewart"

const solution = solveStewart({ yaw: 20, pitch: -6, heave: 3 })
solution.legs // base, platform, length, stroke, withinLimits
solution.reachable // false when any leg runs out of travel
```

## API

| name | type | default | description |
| --- | --- | --- | --- |
| `solveStewart` | `(pose?: StewartPose, geometry?: StewartGeometry) => StewartSolution` | — | Rotates and translates each platform anchor, then measures back to its base anchor. One pass, no iteration. |
| `StewartPose` | `{ sway?, heave?, surge?, roll?, pitch?, yaw? }` | — | Translations in world units (x right, y up, z toward the viewer) and rotations in degrees, applied yaw, then pitch, then roll. |
| `StewartLeg` | `{ id, base: Vec3, platform: Vec3, length, stroke, withinLimits }` | — | Stroke is the change from the home length; withinLimits compares it to geometry.travel. |
| `defaultStewartGeometry` | `StewartGeometry` | — | Ring radii, anchor spread per pair, platform height, and actuator travel for a desk-scale head. |

## Source

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