# Resistance cam

A lever on a variable-radius cam: the cable leaves at a radius that changes with the angle, so the moment arm is the cam profile and the stack does not rise linearly.

> 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/resistance-cam.json
```

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

## Notes

- Solved: the moment arm. The cable leaves the groove on a tangent, so the perpendicular distance from the pivot to it is the cam's working radius exactly — and that is the arm the resistance acts on. The dashed line from the hub is that radius, drawn.
- Solved: the payout. Cable off the cam is the integral of r dθ, so the stack does not rise in step with the lever. Turn the cam through its fat part and the stack runs away from the handle.
- Solved: the profile. The outline is `camRadius` in polar, turned to where the lever has put it — the drawn cam is the resistance curve rather than a picture of one. The cam is keyed to the lever and turns forward with it.
- Illustrated: the strength curve the profile is shaped to is a raised cosine chosen for the drawing, not a measurement of any joint. Frictionless, and the cable does not stretch.
- Design note: docs/gym-machines.md.

## Usage

```tsx
import { ResistanceCam } from "@/components/ui/resistance-cam"

// Runs its own set.
<ResistanceCam behavior="curl" />

// Reshape the cam and the resistance curve changes with it.
<ResistanceCam baseRadius={8} peakRadius={38} peak={0.7} />

// Or drive the lever, which stops the loop.
<ResistanceCam angle={0.6} onAngleChange={setAngle} interactive />
```

## Props

| name | type | default | description |
| --- | --- | --- | --- |
| `angle` | `number` | — | Lever travel, 0 at the bottom of the sweep to 1 at the top. Supplying it stops the loop. |
| `onAngleChange` | `(angle: number) => void` | — | Fires while it is dragged or keyed, so interaction works in controlled mode too. |
| `behavior` | `"curl" | "slow" | "hold" | "static"` | `"curl"` | What it does with nobody driving it. |
| `baseRadius` | `number` | `13` | The cam's smallest working radius, at the ends of the sweep. |
| `peakRadius` | `number` | `34` | Its largest, where the strength curve peaks. |
| `peak` | `number` | `0.46` | Where in the sweep the profile peaks, as a fraction of it. This is the strength curve the cam is cut for. |
| `pin` | `number` | `4` | Which plate the selector pin is in, counted from the top. |
| `plateWeight` | `number` | `5` | What one plate weighs, for the readout in the accessible label. |
| `showProfile` | `boolean` | `true` | Draw the cam's profile. It is the resistance curve, so this is the graph and the part in one. |
| `interactive` | `boolean` | `false` | Hand it to a person: drag up it, or focus it and use the arrow keys. It eases back into the behaviour on release. |
| `showGround` | `boolean` | `true` | Draw the contact shadow and the ground line beneath it. |
| `label` | `string` | — | Optional technical caption under the drawing. |
| `view` | `"plan" | "front" | "profile" | "iso"` | `"profile"` | Where the camera stands. One machine, four projections: straight down, straight on, side elevation, or three-quarter from above. |
| `speed` | `number` | `0.3` | Reps per second. |
| `animate` | `boolean` | `true` | Off parks the machine at phase and stops rendering. A reduced-motion preference does the same. |
| `paused` | `boolean` | `false` | Freeze where it stands. |
| `phase` | `number` | `0` | Seconds of offset, so a row of machines breaks step. |
| `variant` | `"solid" | "outline" | "blueprint" | "wire"` | `"solid"` | How the machine is painted. Geometry never changes between variants. |
| `size` | `"xs" | "sm" | "md" | "lg" | "xl" | number` | `"md"` | Rendered width in pixels, or a step on the scale. |
| `color` | `string` | `var(--robot-shell)` | Body panels — the colour the machine reads as. |
| `accent` | `string` | `var(--robot-accent)` | Status colour: tip light, live tool, readouts. |
| `metal` | `string` | `var(--robot-metal)` | Bare machined parts: collars, bolts, tool bodies. |
| `dark` | `string` | `var(--robot-dark)` | Cast joints, base, shadow side. |
| `palette` | `Partial<RobotPalette>` | — | Override any subset of roles at once, including glow and grid. |

## Source

- `src/components/ui/resistance-cam.tsx`
