catastrophe/CLAUDE.md

99 lines
3.9 KiB
Markdown
Raw Normal View History

2026-03-25 18:23:53 +00:00
# Catastrophe Theory — 3D Print Models
## Project Overview
This project generates 3D-printable STL models of surfaces from **catastrophe theory** — a branch of mathematics studying how small changes in parameters can cause sudden, discontinuous changes in a system's equilibrium state.
Two surfaces are being produced:
| Model | Catastrophe Type | Codimension | Potential |
|-------|-----------------|-------------|-----------|
| Cusp | Cusp catastrophe | 2 | x⁴ + ax² + bx |
| Butterfly | Butterfly catastrophe | 4 | x⁶ + ax⁴ + bx³ + cx² + dx |
---
## The Mathematics
Each surface is the **equilibrium manifold** — the set of all points where the system is in equilibrium. For a potential V(x), equilibria satisfy:
> dV/dx = 0
The 3D surface is swept over the control parameter space (a, b), with x (the state variable) as the third axis. Where the surface folds back on itself is the **bifurcation set** — the region where the system can catastrophically jump between states.
### Butterfly Catastrophe
- **Potential:** V(x) = x⁶ + ax⁴ + cx² + dx (a = 3 fixed, b = 0)
- **Equilibrium condition:** dV/dx = 6x⁵ 12x³ + 2cx + d = 0
- **Control space:** (c, d) swept over a 2D grid
- **State space:** up to 5 real roots x at any given (c, d)
- **Characteristic feature:** nested "butterfly wing" fold structure — a self-intersecting bifurcation curve in the (c, d) plane enclosing a 5-root "pocket" (c∈[0,3], d≈0), surrounded by a 3-root wing region, with a single-root region outside
> **Why not vary (a, b) with c=d=0?** With c=d=0, the equilibrium equation factors as
> x²(6x³ + 4ax + 3b) = 0 — x=0 is always a double root and the remaining roots come
> from a cubic, which is structurally identical to the **cusp** catastrophe. The butterfly
> structure only appears when d ≠ 0 generically, which requires d (or an equivalent odd
> perturbation) to be varied as a control parameter.
2026-03-25 18:23:53 +00:00
---
## Files
- `butterfly_catastrophe.py` — generates the butterfly surface STL
- `butterfly_catastrophe.stl` — ready-to-slice output (ASCII STL)
2026-03-25 18:23:53 +00:00
- `CLAUDE.md` — this file
> A cusp catastrophe script also exists and was the starting point for this project.
---
## How the Generator Works
1. **Root finding** — at each (a, b) grid point, all real roots of dV/dx = 0 are found using Newton-Raphson with dense initial seeding across the x range
2. **Branch tracking** — roots are sorted and matched by branch index across adjacent grid cells
3. **Mesh construction** — adjacent grid quads on the same branch are triangulated into a surface mesh
4. **Base slab** — a flat rectangular base is added so the model is self-supporting on a print bed
5. **ASCII STL output** — written as ASCII (not binary) for maximum compatibility with slicers and viewers
---
## Running the Generator
```bash
python butterfly_catastrophe.py
```
Output: `butterfly_catastrophe.stl`
### Tuning Parameters (inside the script)
| Parameter | Default | Effect |
|-----------|---------|--------|
| `GRID` | `50` | Resolution of the (c,d) control grid — increase to 80100 for final print |
| `C_RANGE` | `(-2.0, 7.0)` | Range of control parameter c |
| `D_RANGE` | `(-6.0, 6.0)` | Range of control parameter d |
| `X_RANGE` | `2.5` | Search window for equilibrium roots |
2026-03-25 21:34:16 +00:00
| `MAX_MATCH_DZ` | `0.8` | Max z-gap for inter-row branch matching in main surface |
2026-03-25 18:23:53 +00:00
For a final high-quality print, increase `grid` to `80``100`. The default of `40` is optimised for STL viewer compatibility.
---
## 3D Printing Tips
- **Orientation:** flat base down — no supports needed
- **Layer height:** 0.150.20 mm for good surface detail
- **Perimeters:** ≥ 2, as the fold regions are thin
- **Scale:** ~120 mm along the a-axis makes a good desk model
- **Material:** PLA or PETG both work well; the overhangs are gentle
---
## Dependencies
```
numpy
```
No other dependencies — STL writing uses Python's built-in `struct` module (binary) or plain file I/O (ASCII).