Lesson 1.1 · I Geometry
What is parametric design?
What it's about: What parametric design is, why a model is a recipe rather than a result, and the path knotflow takes from text to a printable file.
What you should bring: School mathematics (coordinates, vectors, functions) is enough to start. If you have programmed before, part II will go faster. The lessons often point into the source code (Rust); you don't need to read it to follow them.
The model is a recipe, not a result
In a classic CAD program you draw a pot: you draw lines, revolve them, cut holes into the result. In the end you have one shape. If you want the pot 2 cm taller, you have to redo a lot of it by hand.
In parametric design you describe how the pot arises
from a few numbers instead. An example that comes up again and again in
these lessons is an air-pruning pot: a plant pot with honeycomb holes in
its wall, where the root tips end in the air instead of circling around.
From height, top_d, bottom_d,
wall and a few more numbers, the whole pot is computed anew
every time, with all its cells (examples/air_pot.kf). One
recipe gives you infinitely many pots.
Three kinds of values
Every parametric model has three kinds of values:
| Kind | Example from the pot | Who sets them? |
|---|---|---|
| Parameters (inputs) | height = 150, wall = 1.6 |
The user, e.g. with a slider |
| Derived values | rb = clamp(bottom_d/2, rt − h, rt + h) |
Formulas in the model |
| Geometry (output) | the finished pot as an STL | the model |
The derived values are the heart of the model. They hold the designer's knowledge:
- Rules (constraints): "The wall must never be
flatter than 45°, or it won't print." In the pot,
rb = clamp(…)keeps the bottom radius so that this holds. - Auto values: "0 = auto", for instance for a number
of ribs: the model picks a sensible number on its own (say
max(6, 3·round(2π·rt/75/3))) if you don't give one. - Derivations: The number of honeycomb rows follows from the height, the hole size and the web between holes; the rows are placed so that they sit centred in the wall.
The data-flow graph
Visual node editors show such a recipe as a graph: boxes (nodes) are computation steps, wires carry values from one node to the next. A piece of the pot would look like this:
[top_diameter]──►[÷ 2]──► rt ──┬──────────────────────────►[Profile]──►[Revolve]──► Pot
│ ▲
[height]───────────────────────┼──►[clamp: never below 45°]──►rb
[bottom_diameter]──►[÷ 2]──────┘ ▲ │
└── height ─────────┘
knotflow describes the same thing as text. Every
line let name = expression is a node, and every name that
appears in an expression is a wire. This model is already a complete,
printable pot:
param height = 150 in 40..500
param top_d = 150 in 40..500
param bottom_d = 110 in 30..500
param wall = 1.6 in 0.8..5
let rt = top_d / 2
let rb = clamp(bottom_d / 2, rt - height, rt + height)
let outside = polyline([(0, 0), (rb, 0), (rt, height)]) // outer contour: x = radius, y = height
export shell(revolve(outside), wall, open: [(0, 0, 1)]) // revolved, then a wall with a floor
kf graph pot.kf shows what each value depends on – the
graph as text:
param height
param top_d
param bottom_d
param wall
let rt ◄─ top_d
let rb ◄─ bottom_d, rt, height
let outside ◄─ rb, rt, height
export ◄─ outside, wall
Why text instead of boxes?
- Text can be versioned and diffed with Git. With a node graph, every change is a hard-to-read lump in a file that is really a picture.
- Copying, searching, replacing and writing your own functions come naturally with text.
- On the other hand, you don't see the graph. A live preview makes up for that: you change the text or a slider, and the model reappears at once (Lesson 4.1).
A nice side effect: because let values never change, the
program knows exactly what depends on what. If top_d
changes, only what hangs on top_d needs to be recomputed –
not everything. That keeps even large models responsive (Lesson
4.2).
Lists: many things at once
One strength of node editors: a node can receive a whole list instead of a single value and then works through all its elements. knotflow writes this in set-builder notation, as in mathematics ({f(x) | x ∈ M}):
[circle(r) | r <- [10, 20, 30]] // three circles
[circle(5) |> move(z: z) | z <- [0, 10, 20]] // one circle, moved three times
(Why this is explicit and not automatic as in node editors is explained in Lesson 2.1.)
The pot's honeycomb holes are exactly such a case: one hexagon shape, applied to a list of positions.
Compute exactly, cut into triangles only at the end
A screen and an STL file only know triangles. They don't know a true
circle. Breaking a smooth shape down into triangles is called
tessellation. The $fn parameter in
OpenSCAD is exactly this decision: into how many corners is a circle
split?
OpenSCAD breaks shapes into triangles right away and then keeps computing with the triangles: it cuts the holes into a cone made of many facets. If a hole edge lies almost, but not quite, on a facet edge, you get paper-thin splinter triangles ("slivers") and broken edges. A pot with honeycomb holes runs into this in many places; built that way, it needs workarounds: small offsets, turned rows of holes, holes "as far away from all edges as possible".
knotflow turns the order around:
text ──► NURBS (exact curves and surfaces) ──► triangles ──► screen / STL / 3MF
└─ computation happens here ──┘ └─ only at the very end
NURBS are a way to describe smooth curves and surfaces exactly with few numbers – including true circles. Lesson 1.2 shows how. Because the shapes stay exact until the end, the tessellation can use the hole edges deliberately as triangle corners. That way, slivers never arise in the first place. The same holds for booleans (union, difference and intersection of two solids): they cut the exact surfaces (Lesson 3.7). Only a few shapes are meshes of triangles from the start: melted "organic" shapes (Lesson 3.12), grown structures (Lesson 3.13) and reliefs from pictures (Lesson 2.5).
What knotflow can do
An overview of the whole range. How to use each of these is in the handbook; how it is built, in the lessons that follow.
- Curves: lines, arcs, circles, rectangles, polygons,
NURBS and Bézier curves, smooth curves through points
(
interpolate), curves joined end to end (chain), pieces of them (segment), rounded corners (fillet) and parallel curves (offset). Queries: the point and direction at a place, corners, where two curves cross, the box around them. (Lesson 1.2) - Surfaces: revolved (
revolve), extruded (extrude), through sections (loft), a profile along a path (sweep), tubes (tube,pipe), a profile carried around an outline (around), ready solids such as sphere, box, cylinder, cone and torus. (Lesson 1.3) - Solids: exact booleans (
union,difference,intersection), the curves where two surfaces meet (intersect), walls with a floor (shell), holes through walls (perforate). Every exported solid is checked for being closed, that is, printable. (Lessons 3.3–3.8) - Rounded edges: exactly on flat curves
(
fillet), on profiles (around,rounded_box,boss) and on the edges of finished solids, also after booleans: rounded (fillet_edges) or chamfered (chamfer_edges). (Lessons 3.9 and 3.10) - Constructing: instead of working out coordinates,
you write down conditions ("touches", "parallel", "20 apart"), and
solvefinds the points; assemblies with joints too. (Lesson 3.11) - Distributing: points and frames along curves and on
surfaces, at random or in a grid;
instancecomputes a shape once and places it thousands of times. (Lesson 3.1) - Organic: melted balls and rods (
blend,isosurface), simplifying meshes, fields (values on a grid, say from a picture or a computation) from which shapes grow. (Lessons 3.12 and 3.13) - Data: JSON, CSV, tables, SVG drawings, fonts and
PNG pictures from files next to the model; libraries of your own with
import, and the standard library (knots, sweeps). (Lessons 2.4 and 2.5) - Output: STL and 3MF for 3D printing, pictures as PNG and SVG. (Lesson 4.6)
- Tools: the modeller in the browser with sliders and
a fast preview, the command-line program
kf, a language server for editors and an interface for AI assistants. A cache keeps intermediate results, so that after a change only what depends on it is computed again. (Part IV)
The core is written in Rust and compiled twice: once as a command-line program, once as WebAssembly for the browser. The same code, two targets – and both write byte-identical files (Lesson 1.4).
How the lessons are organised
The lessons explain how knotflow is built and why that way. They are organised in four parts:
| Part | Content | Lessons |
|---|---|---|
| I Geometry | Curves, surfaces and solids, triangles, computing with floating-point numbers | 1.1 – 1.4 |
| II The language | Parser and evaluation, language design, language audit, modules, data from files | 2.1 – 2.5 |
| III Modelling | Distributing, building blocks, wall thickness, solids, holes, intersections, booleans, walls, rounded edges, edges of solids, constructing, simplifying, growing, gallery, research on intersections | 3.1 – 3.15 |
| IV Tools | Browser, cache, preview, language server, AI, 3MF | 4.1 – 4.6 |