knotflow Lessons PDF ↓ Deutsch Handbook Modeller ↗ Source

Lesson 3.14 · III Modelling

Gallery: hard shapes

What it's about: Four models of the kind people usually build with node editors – each one a real test for the language and the geometry core. For each: the idea, the heart of the code and a variant that shows what "parametric" means: the same model, different parameters. The building blocks behind them are explained in other lessons: melted rods in Lesson 3.12, fields and structural analysis in Lesson 3.13, frames and copies in Lesson 3.1. Here it is about how they play together.

The models live in examples/. The images are made by tools/gallery.sh with kf's PNG renderer (kf render x.kf -o x.png --view az,el --width px); Lesson 4.6 shows how it works.

1. Interwoven Voronoi nets

Interwoven Voronoi nets

Three independent Voronoi nets on the same sphere. At every crossing one strand runs over the other net and the other runs under it – like wickerwork. No net can be pulled out, even though the nets are not connected anywhere. The bars are thick where load flows and thin where it doesn't, and they flare out at the nodes like grown wood.

Voronoi on the sphere

A Voronoi diagram splits a surface into cells: each cell belongs to one point and contains everything that is closer to that point than to any other. On a sphere there is an elegant way to get it: take the convex hull of the points. Its triangles are the Delaunay triangulation, and the point above the centre of each triangle is a corner of a Voronoi cell. Whether a triangle belongs to the hull is decided by the question "Do all other points lie on one side?" – exactly the kind of yes/no decision you must not leave to rounding noise (Lesson 1.4, experiment 5). That is why voronoi_sphere uses the exact orientation test. This time the points are purely random – that gives the irregular, organic cells.

Weaving

  1. arc_crossings finds every place where an arc of one net crosses an arc of another, along with the position on both arcs (t = 0 … 1).
  2. For each crossing, a dice roll decides which net is on top – with rand(seed, n), so it is reproducible.
  3. Each strand is lifted or lowered at its crossings: by just enough that exactly play of clearance remains between the two strand surfaces. For that you need to know how thick the strands are there – which is why the structural analysis (below) comes before the weaving.
  4. The height along a strand is a sum of soft bumps (bump), each only so wide that it doesn't reach the neighbouring crossing or the nodes:
fn height(ms, t) = sum([m.s * m.h * bump((t - m.t) / m.w) | m <- ms])

fn strand(k, e, ms) = [rod(p, q, thickness(k, e, s), r_end: thickness(k, e, t))
                       | ((s, p), (t, q)) <- zip(take(samples, n - 1), drop(samples, 1))]
  where samples = [(t, slerp(a, b, t) * (radius + height(ms, t))) | t <- ts], …

slerp runs along the great circle; the strand is a chain of short bars (rod) whose radius follows thickness. (You could also use interpolate to lay a smooth curve through the points and tube to put a tube around it whose radius is itself a function – that works, but such tubes don't merge at the nodes; see Lesson 3.12.)

Is that really true? A weave that looks good may still touch at some crossings. You can check it in the language itself, with a few lines at the end of a copy of the model that measure the clearance at every crossing:

let clearance = [abs(height(ms[c.i][c.a], c.ta) - height(ms[c.j][c.b], c.tb))
                 - thickness(c.i, c.a, c.ta) - thickness(c.j, c.b, c.tb) | c <- crossings]
let touching  = len(clearance.filter((< 0.01)))

The check uncovers three traps: lift all crossings by the same amount and the strands touch where they are thick; neighbouring bumps with opposite signs cancel each other out; and narrow bumps fall between the sample points of the curve. That is why the lift follows the thickness and every bump is narrow enough not to reach its neighbours. In the model every one of the 276 crossings has exactly 0.8 mm of clearance.

Growing: material where the load flows

The idea comes from nature. Trees add wood where the stress is high and round out notches – Claus Mattheck turned this into the methods CAO (Computer Aided Optimization) and SKO (Soft Kill Option). The general field is called topology optimisation (in CAD programs "generative design"): material is removed where it carries nothing.

For a net of bars there is a handy variant. frame_sizing computes each net as a frame structure:

This is checked against a textbook case: a cantilever with a load at its tip deflects by P·L³/(3·E·I) – the computation agrees to within 10⁻⁹, even for a beam lying at an angle.

The grown shape at the nodes: each strand gets a little thicker towards its ends, and all strands of a net merge into a single solid – at every node a fillet grows, like wood at the fork of a branch. Lesson 3.12 explains how. The three nets are merged separately; they remain three solids, woven into each other.

Variant: two nets with 24 cells each – here you can see the weave clearly.

Two nets

2. Tree-column roof

Tree columns

Columns that branch like trees until their tips end exactly beneath the roof – like the famous tree columns at Stuttgart Airport.

The idea: design from the top down. Every fork sits at a fixed height, the branches of each level spread over a smaller circle and are rotated relative to the previous level. The recursion doesn't end with an if, but with an equation with a guard:

fn crown_at(p, l, s, r) | l > levels = []
fn crown_at(p, l, s, r) = flatten([limb(p, child(p, k, l, s), l, s, r) | k <- [0 .. split - 1]])

fn limb(p, q, l, s, r) = [cylinder(p, q, r), sphere(r * 1.05) |> translate(q)]
  ++ crown_at(q, l + 1, s * shrink, r * 0.68)

How far apart do the trees stand? The crown reaches crown + crown·shrink + crown·shrink² + … – a geometric series whose sum is well known:

let reach = crown * (1 - shrink ^ levels) / (1 - shrink)

Organic: with organic = true (the default) every branch is a tapering bar, and all branches of a tree merge at the forks with fillets (Lesson 3.12). The recursion stays the same – only one equation of piece is different:

fn piece(p, q, r) | organic = [rod(p, q, r, r_end: r * 0.7)]
fn piece(p, q, r)           = [cylinder(p, q, r), sphere(r * 1.05) |> translate(q)]
fn grown(t) | organic       = isosurface(blend(t, k: fillet), voxel: voxel)

Variant: three branches instead of four, four levels, roof hidden. Here you can see the fractal:

-D split=3 -D levels=4 -D shrink=0.55 -D roof=false

Variant without roof

3. Parametric facade

Facade

A curved glass wall with floor slabs and fins that turn open towards an attractor – a classic of parametric design, for example as a sunshade that reacts to a point.

The idea: at every point (u, v) a surface has a frame: an origin and three axes – along u, along v, and the normal. place puts a shape built at the origin exactly there. That is how the fins come about, without ever computing a coordinate:

fn fin(i, j) = box(1.2, 0.86 * storey, depth)
    |> move(z: depth / 2 + 1)
    |> rotate(angle, axis: (0, 1, 0))
    |> place(f)
  where f     = frame_on(wall, (i + 0.5) / fins, (j + 0.5) / floors),
        angle = turn * smooth(clamp(1 - distance(f.origin, attractor) / reach, 0, 1))

smooth is the function s²(3 − 2s): it goes smoothly from 0 to 1, without a kink at the edge of the area of influence. The floor slabs are strips along the floor plan: points on the curve (at), offset outwards along the horizontal normal (tangent), extruded as a closed outline.

Variant: -D turn=0 – all fins straight.

Without rotation

4. Romanesco

Romanesco

A cone made of smaller cones, which are themselves made of even smaller cones.

The idea: Romanesco is self-similar on a logarithmic spiral. From bud to bud the distance d to the tip shrinks by the same factor q, and each bud is rotated on by the golden angle of 137.5° – that is how plants arrange their buds so that none hides another. Each bud is a scaled-down copy of the whole:

fn floret(0) = pearl
fn floret(l) = [core] ++ [bud(k, l) | k <- [0 .. buds - 1]]

fn bud(k, l) = floret(l - 1) |> scale(packing * d) |> orient(dir) |> translate(pos)
  where d   = start * q ^ k,
        a   = k * golden,
        pos = (0.5 * d * cos(a), 0.5 * d * sin(a), 1 - d),
        dir = (sin(tilt) * cos(a), sin(tilt) * sin(a), cos(tilt))

floret(l - 1) is a whole group of shapes; scale, orient and translate move it as a whole (Lesson 2.2, section 10).

How big is a bud? At the height where the distance to the tip is d, the cone has radius 0.5·d. A narrow ring of the cone's surface between d and q·d has the area 2π · 0.5·d · 1.118 · (1 − q)·d ≈ 3.5 · (1 − q) · d² (1.118 is the factor for the slope). This area belongs to one bud. If its base, a circle with diameter s, is to fill it exactly, then π·s²/4 = 3.5·(1 − q)·d², so

s = d · √(4.5 · (1 − q))          let packing = sqrt(4.5 * (1 - q))

So the buds grow in proportion to their distance from the tip – which is exactly what makes the shape self-similar.

Variant: one level (-D levels=1): the cone with 55 pearls, which turn into 55 small romanescos at two levels.

One level

How it is checked

Every model of the gallery must be a closed solid with its default values, in as many parts as expected, and stay one after being written as STL and read back the way a slicer does. The structural analysis is checked against a textbook case (above), the weave by measuring the clearance at every crossing.

Limits

Try it yourself

cargo run --release -p kf -- render examples/romanesco.kf -o out/romanesco.png
cargo run --release -p kf -- render examples/voronoi_sphere.kf -D cells=80 -o out/sphere.png --view -30,40
cargo run --release -p kf -- render examples/tree_roof.kf -D levels=4 -D split=2 -o out/tree.stl
cargo run --release -p kf -- graph examples/facade.kf

Exercises:

  1. Move the supports of the nets to the top (p.z > 0.75): how do the bar thicknesses change?
  2. Give the facade a second attractor (hint: the max of the two effects).
  3. Let the tree columns branch not in a circle but along a line – like a fan.
  4. Romanesco with buds 34, 55, 89 (Fibonacci numbers) and with 50: do you see a difference in the spirals?