# Tripod kinematics

The three-legged balance solver: a load schedule per foot, the body position that schedule demands, and the support polygon it has to stay inside.

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

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

## Notes

- The inverse of `bear-kinematics`: that one is given a centre of mass and works out the loads, in one dimension. This one is given the loads and works out the centre of mass, in two — which is the only way a three-legged machine can take a step.
- Sway is derived, not chosen: it is what is left of a leg's reach once a planted foot has been paid for, so femur, tibia and ride height all change whether a gait is statically holdable. An explicit `sway` can only make it smaller.
- Illustrative trajectories, not dynamics: the load ramp is a schedule, there is no ground reaction or inertia, and the feet travel rather than the world.

## Usage

```tsx
import { solveTripod, supportMargin } from "@/lib/robocn/tripod"

const pose = solveTripod({ gait: "creep", phase: 0.35 })
pose.centre   // where the body has to stand to hold that load split
pose.margin   // room left inside the support polygon; negative is over the edge
pose.legs     // hip, knee, foot, kneeHeight, clearance, contact, load
```

## API

| name | type | default | description |
| --- | --- | --- | --- |
| `solveTripod` | `(options?: TripodOptions) => TripodPose` | — | Schedules the load across three feet, solves the body position that schedule demands, clamps it to what the legs can follow, and solves each knee as a two-link chain in its own vertical plane. |
| `TripodOptions` | `{ gait?, phase?, height?, step?, lift?, heading?, turn?, sway?, lean?, femur?, tibia? }` | — | Normalized height, step and lift; heading and turn in degrees; sway in world units, clamped to what the legs can reach; lean in −1..1 of that limit. |
| `TripodPose` | `{ gait, height, centre, yaw, legs, support, margin, stable, sway, femur, tibia }` | — | Plan positions are x starboard, y toward the nose. `centre` is the body over its feet, `margin` the signed distance from it to the edge of the support polygon. |
| `TripodGait` | `"stand" | "creep" | "amble" | "pivot"` | — | Creep keeps a three-foot overlap to hand the load across; amble takes two feet off at once; pivot runs the creep pattern as a turn on the spot. |
| `supportMargin` | `(centre: Vec2, support: readonly Vec2[]) => number` | — | How much room a centre of mass has inside a polygon of contacts: positive inside a triangle, zero at best on a segment, negative outside either. |

## Source

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