knotflow Lessons PDF ↓ Deutsch Handbook Modeller ↗ Source

Lesson 4.7 · IV Tools

knotflow and OpenSCAD: a comparison on large models

What this is about: OpenSCAD is the best-known tool that describes shapes as text, and knotflow has taken a lot from it (Lesson 2.3). This lesson puts the two side by side: the same parts from the large examples (differential, Golden Gate Bridge) built in both tools, measured the same way and checked the same way. It describes how things can be expressed and what comes out; which tool suits a task depends on the task.

What you should bring: Lesson 1.1 (computing exactly, triangles only at the end), Lesson 3.7 (booleans). To measure yourself, OpenSCAD in a version with the option --backend.

1. Two approaches

Both tools read a program and write triangles. They differ in when shapes become triangles.

A few things follow from this, without either approach being the right one: meshes are simple, and computing on them is fast and well studied. Exact surfaces keep their shape to the end: a rounding can follow a cut edge, and how fine things get is decided last. In return the geometry has to tell apart cases a mesh does not know at all, such as two surfaces that only touch.

2. What was compared

Four parts, each written in both languages; the files are in tools/compare-openscad/, and run.sh measures them all.

Part What it tests
The differential's carrier classic CSG: two turned bodies, a cavity, windows, 12 bores
Ring gear, 46 teeth, spiral bevel free form: teeth from sections, cut to a zone, bores
A ladder with n rungs many unions, cylinder crossing cylinder
Golden Gate Bridge quantity: some 7500 parts, hardly any booleans

Measured on an Apple M4 Pro (macOS 26), knotflow's kf as a release build (as of 26 Oct 2026), OpenSCAD 2026.10.11; the time for computing and writing the STL file, measured once. Both files are checked with kf check (closed?, triangles, volume).

One difficulty first: the two settings for fineness are not the same thing. $fn = 170 breaks a circle of radius 58 mm into chords about 0.01 mm off it, roughly what --tol 0.01 means in knotflow. But knotflow applies its tolerance to every surface and every intersection curve and refines where it seems needed; OpenSCAD divides every circle evenly. The tables therefore give both, time and the number of triangles.

3. How the parts are expressed

Turned bodies and bores read almost the same in both languages. The carrier takes 35 lines in knotflow and 34 in OpenSCAD:

knotflow:  revolve(profile) |> rotate(90, (0, 1, 0))
OpenSCAD:  rotate([0, 90, 0]) rotate_extrude() polygon(profile);

Free forms. The ring gear is made of sections of its teeth, each turned a little further than the one before (the spiral). knotflow joins the sections with loft. OpenSCAD has no loft; there one builds a polyhedron oneself: all points of all sections in one list, the faces as lists of four indices between neighbouring sections, the caps, all running the right way round. Since the faces in between are flat, it takes more sections (20 here instead of 5), and the tooth flanks become polylines instead of curves. knotflow: 21 lines plus a gear library of 61 lines; OpenSCAD: 51 lines.

Many equal parts. knotflow has copies (instance, Lesson 3.1): a part is computed once and put on many frames. OpenSCAD repeats with for; at the end all parts of a model are joined into one body. The bridge takes 87 lines in OpenSCAD and 122 in knotflow.

Constructions and assemblies. In knotflow a shape can be described by conditions instead of formulas (Lesson 3.11). examples/construction.kf gives a triangle by what is known about it – two corners, the angle at B, a right angle at C – and the circle touching all three sides; solve finds C, the centre and the radius:

let s = solve({c: (25, 20), m: (22, 8), r: 5}, v => [
  angle_at(a, b, v.c) - at_b,        // the angle at B
  angle_at(a, v.c, b) - 90,          // a right angle at C
  touches(v.m, v.r, a, b),           // the circle touches all three sides
  touches(v.m, v.r, b, v.c),
  touches(v.m, v.r, a, v.c)])

In OpenSCAD one describes the same by its solution: one works out where C lies (on the circle of Thales over A–B, at the angle at B) and how the inscribed circle's radius and centre follow from the sides, and writes those formulas down:

C = [side * sin(at_b)^2, side * sin(at_b) * cos(at_b)];
p = side * cos(at_b);  q = side * sin(at_b);     // the sides B–C and A–C
r = (p + q - side) / 2;
M = (p * A + q * B + side * C) / (p + q + side);

Both give the same points (here to 10⁻⁹ mm). The first way records what is to hold, and solve says when the conditions do not fix the shape, say something twice or contradict each other; if what is given changes (another angle instead of the right one), the conditions change. The second way needs no solver and computes in one step; if what is given changes, it is worked out anew. Assemblies work the same way in knotflow: solve places parts against each other by joints (revolute, slider …), and the V12 places its pistons and rods like that. In OpenSCAD one works the positions out, for instance with the formula of the crank drive.

Computing besides the shape. A model often computes more than its geometry. The fidget toy (examples/fidget_rings.kf) checks that its rings hold together: every ring must be wider at its middle than the opening of the next one.

let caught = assert(fold(range(ring_count - 1), true, (ok, i) => ok and r_out(i) > opening(i + 1)),
  "a ring falls out of the next one: make the rings higher or the gap smaller")

That is arithmetic on the sizes, and OpenSCAD can express the same with a function and assert. One difference lies in whether a program can ask the shapes it makes: in knotflow they are values. intersect(a, b) gives the curves along which two surfaces cross, an empty list means they do not cross; crossings, bounds, point_on and tangent query curves and surfaces. An OpenSCAD program cannot query the meshes it makes, for instance for their bounds or whether they cross; what it wants to check it computes from the sizes. On top of that, knotflow brings computations besides the shape: solve for constructions and joints (Lesson 3.11), analyze_plane (finite elements in the plane, Lesson 3.13) and frame_sizing (analysing a frame of bars and sizing them by their load, Lesson 3.14).

What OpenSCAD brings beyond that: hull and minkowski, 2D offset, importing STL, SVG and DXF files, a fast preview (F5) that only draws the booleans instead of computing them, and large third-party libraries grown over years, among them collections of standard parts. knotflow has exact roundings of edges (Lesson 3.10), records, match and functions as values, solve, data from files (Lesson 2.5) and a cache that, after a change, recomputes only what depends on it (Lesson 4.2).

4. Measurements

Part, setting Time Triangles closed Volume [mm³]
Carrier, knotflow tol 0.05 0.34–0.75 s 41,534 yes 711,664
Carrier, knotflow tol 0.01 0.97–1.37 s 170,438 yes 711,681
Carrier, OpenSCAD Manifold $fn 76 0.12–0.14 s 14,332 yes 710,894
Carrier, OpenSCAD Manifold $fn 170 0.14–0.26 s 31,440 yes 711,579
Carrier, OpenSCAD CGAL $fn 76 12.1 s 14,880 yes 710,894
Carrier, OpenSCAD CGAL $fn 170 49.5 s
Ring gear, knotflow tol 0.01 3.7–3.9 s 292,774 yes 646,079
Ring gear, OpenSCAD Manifold 0.35–0.40 s 35,552 no 646,025

(Two runs at different times; the ranges show how much timings vary.)

The volumes lie close together. The difference comes from the polygons: their corners lie on the circle, their sides inside it. As $fn grows, the volume approaches the value knotflow has already with the coarser tolerance; both of OpenSCAD's engines give the same volume for the same $fn.

Many unions (ladder, cylinders Ø 6 and Ø 4 mm, all results closed):

Rungs knotflow tol 0.01 Triangles OpenSCAD Manifold $fn 64 Triangles
10 0.64 s 206,644 0.08 s 10,784
40 2.7 s 798,312 0.11 s 41,624
160 13.1 s 3,171,972 0.23 s 164,984
640 62.8 s 0.68 s

With 40 rungs knotflow takes just under 1 s for the exact cuts and the rest for the triangles; it lays about twenty times as many triangles around the intersection curves as OpenSCAD, although OpenSCAD's chords are even shorter here. With --tol 0.05 the time halves. Whether the unions are computed one after the other (fold) or pairwise as a tree makes no difference in knotflow.

The bridge: knotflow 0.47–0.53 s (--tol 5, the parts as copies), OpenSCAD Manifold 1.06–1.18 s ($fn 24, everything joined into one body), both some 460,000–500,000 triangles.

Preview: OpenSCAD's F5 preview, as a picture, takes 0.5 s for the carrier and 0.4 s for the ring gear; knotflow with --draft 1.2 s for the ring gear.

5. What comes out closed

All results of both tools are closed bodies inside their engines. In the STL file not always:

6. Limits of this measurement

Try it yourself

tools/compare-openscad/run.sh quick      # without the slow old engine
tools/compare-openscad/run.sh            # with it
  1. Raise $fn in OpenSCAD's carrier step by step and watch the volume approach knotflow's. How many triangles does OpenSCAD need for the same deviation?
  2. Compute the ladder in knotflow with --tol 0.05 and --tol 0.2. How do the time, the number of triangles and the volume change?
  3. Open ring.scad and ring.kf side by side. Which lines in OpenSCAD do what loft does in knotflow?
  4. To think about: which cases does a tool with exact surfaces have to tell apart that a tool with meshes does not see at all – and the other way round?