knotflow Lessons PDF ↓ Deutsch Handbook Modeller ↗ Source

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:

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?

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.

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