# Hexapod kinematics

The radial walking solver behind the spider and the crab: four to ten legs, three gaits, plan-view feet, and knees solved in each leg's own vertical plane.

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

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

## Notes

- Femur and tibia hold their lengths in every pose, because the stance radius is capped so a full stride still lands inside the leg's reach.
- Illustrative trajectories, not dynamics: no balance, no ground reaction, and the body never translates — the feet do.

## Usage

```tsx
import { solveHexapod } from "@/lib/robocn/hexapod"

const pose = solveHexapod({ legs: 8, gait: "tripod", phase: 0.4, heading: 90 })
pose.legs // id, side, hip, knee, foot, kneeHeight, clearance, contact, bearing
pose.height // body height in world units
```

## API

| name | type | default | description |
| --- | --- | --- | --- |
| `solveHexapod` | `(options?: HexapodOptions) => HexapodPose` | — | Fans the hips around the carapace, slides each foot along the travel direction, and solves the knee as a two-link chain in the leg's vertical plane. |
| `HexapodOptions` | `{ legs?, gait?, phase?, height?, stride?, lift?, heading?, radius?, fan?, spread?, femur?, tibia? }` | — | Legs 4–10 rounded to an even number; normalized height, stride and lift; heading in degrees (0 walks toward the nose, 90 to starboard). |
| `HexapodLeg` | `{ id, side, hip: Vec2, knee: Vec2, foot: Vec2, kneeHeight, clearance, contact, bearing }` | — | Positions are plan view — x starboard, y toward the nose — with the knee's height reported separately so a drawing can raise it. |
| `HexapodGait` | `"stand" | "tripod" | "wave" | "ripple"` | — | Tripod swings alternate legs (duty 0.5), wave moves one leg at a time, ripple runs a delay down each side. |

## Source

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