catastrophe/CLAUDE.md

3.6 KiB
Raw Permalink Blame History

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

Butterfly Catastrophe

  • Potential: V(x) = x⁶ + ax⁴ + cx² + dx (a = 3 fixed, b = 0)
  • Equilibrium condition: dV/dx = 6x⁵ 12x³ + 2cx + d = 0
  • Rearranged as a height field: d = 6x⁵ + 12x³ 2cx
  • Print base: (x, c) plane — state variable × control parameter
  • Print height: d (the other control parameter, computed directly)

This parameterisation is single-valued: every (x, c) point maps to exactly one d, so the mesh is a simple height field with no multi-valued branches, no root finding, and no fold-edge gaps.

The fold ridges — where the surface has zero gradient in x — satisfy ∂d/∂x = 0, giving the bifurcation curve c = 18x² 15x⁴. This self-intersecting curve is visible as a characteristic ridge on the surface.

Why not sweep (c, d) and solve for x? That approach requires finding multiple roots of a degree-5 polynomial at each grid point, tracking which root belongs to which branch across fold lines, and capping fold edges — all of which introduce artefacts and holes. Rearranging to d(x, c) avoids all of this entirely.


Files

  • butterfly_catastrophe.py — generates the butterfly surface STL
  • butterfly_catastrophe.stl — ready-to-slice output (ASCII STL)
  • CLAUDE.md — this file

A cusp catastrophe script also exists and was the starting point for this project.


How the Generator Works

  1. Height field — for each (x, c) grid point, compute d = (6x⁵ + 12x³ 2cx) × D_SCALE
  2. Mesh construction — adjacent grid quads are triangulated into a regular height-field mesh
  3. Base slab — a flat rectangular base is added so the model is self-supporting on a print bed
  4. ASCII STL output — written as ASCII (not binary) for maximum compatibility with slicers and viewers

Running the Generator

python butterfly_catastrophe.py

Output: butterfly_catastrophe.stl

Tuning Parameters (inside the script)

Parameter Default Effect
GRID 200 Grid resolution — higher = smoother fold ridges
X_RANGE (-3.0, 3.0) Range of state variable x (print width)
C_RANGE (-1.0, 5.0) Range of control parameter c (print depth)
D_SCALE 0.5 Vertical scale factor — reduce if the model is too tall

The butterfly fold structure is concentrated around x ∈ [1.1, 1.1] and c ∈ [0, 5.4]; extending X_RANGE beyond ±2 adds flat outer wings with no additional features.


3D Printing Tips

  • Orientation: flat base down — no supports needed
  • Layer height: 0.150.20 mm for good surface detail
  • Perimeters: ≥ 2 for the thin ridge regions
  • Scale: the fold ridges are most visible at ~100150 mm along the c-axis
  • Material: PLA or PETG both work well; the overhangs are gentle

Dependencies

numpy

No other dependencies — STL writing uses plain file I/O (ASCII STL).