Appendix A: How this book is made

This book is source code. Every chapter is a Quarto document or a Jupyter notebook, every derivation that can be checked by a computer is checked by one, and most figures we drew ourselves are produced by a script kept next to the chapter it belongs to.

Text and mathematics

Derivations are carried out in SymPy inside the chapter notebooks and displayed with the ltx helper of MechanicsKit, our teaching library, so the equation on the page is the output of the computation and not a transcription of it. Where a result can be reached by two routes, as the spring rate of 9.8.9 by the twist of the wire and by Castigliano’s theorem, both are computed and compared. Notebooks are executed once and stored with their outputs, so the book renders the same results every time.

Figures as code

Different kinds of visual are made with different tools, chosen for what the visual has to do.

Visual Tool Example
Problem figures and free-body diagrams mechanicskit.sketch on matplotlib, saved as SVG Figure 9.8.9
Plots of results matplotlib, generated in the chapter notebook Figure 9.8.11
Animations of mechanisms manim, p5.js, matplotlib the involute gear and pendulum animations
Interactive configurators marimo notebooks the beam calculator
Photorealistic parts Blender, through our toolkit mechanicskit-parts Figure 9.8.4

The drawn figures share one palette and one set of symbols: tan for brackets and links, a fading grey bar for fixed ground, red for loads, blue for displacements, green for internal forces and rotations. The drawing primitives (ground, pin, spring, force, dimension, gear) live in MechanicsKit, and each chapter has a script under tools/ that composes its figures from them. A problem figure is therefore a short program, and changing a load or a dimension means changing a number and running it again.

Renders with Blender

The photorealistic images of machine elements, such as the springs in Figure 9.8.4, are made with Blender, the open-source 3D package, driven entirely from Python. A render is produced in three steps. The geometry is computed from the engineering parameters with plain numpy: a helical spring, for instance, becomes the centre line of its wire, wound from the coil diameter, the wire diameter, the number of active coils and the pitch, with closed end coils. Blender then sweeps the wire cross-section along that line, grinds the ends flat, places the part on an invisible floor that only catches its shadow, and lights it with a fixed studio set. Finally the path tracer renders it with a transparent background, so the same image works on a light and a dark page. The part in the picture is the part described in the text.

Animations add a fourth step. The series and parallel springs of Figure 9.8.7 are rendered frame by frame, each frame at a slightly smaller height, and a matplotlib graph of force against deflection is drawn beside each frame before the frames are encoded as video.

The role of AI

Much of the code behind the figures, and drafts of some of the text, are written by an AI coding agent (Claude Code, by Anthropic) working in the book’s repository under our direction. We decide what a chapter teaches, what each figure has to show, and which sources are acceptable. The agent writes the drawing script, the Blender scene or the animation, runs it, and shows us the result; it drafts prose against the style guide and checks the draft for the constructions the guide forbids; it searches for openly licensed photographs and verifies each licence on the file’s own page before proposing it.

We review all of it. Every equation is checked, every figure is looked at before it is captioned, and every number in a worked example is produced by code in the chapter.

We state this openly for two reasons. Readers should know how a teaching text was produced before they rely on it. And the method itself is worth teaching: the figures in this book are short programs whose parameters a student can change, which is a different relationship to a figure than looking at it.

Material by others

Photographs and drawings by others are used only under open licences (public domain, CC0, CC BY or CC BY-SA), with the licence checked on the source page. They are credited in Image credits, together with the figures they appear in. Everything else in the book is our own work under CC BY 4.0.