Lesson 3.4 · III Modelling
What a solid is
What it's about: A single surface can be printed if it is closed all round. Most parts, though, are made of several surfaces: a wall of outer surface, inner surface and rim, a box of six sides, a Boolean solid of pieces of many surfaces. This lesson shows how knotflow describes such a solid and why it is always closed after it is cut into triangles. That is the core of a small CAD kernel, the part of a modelling program that knows what is inside and what is outside. The Booleans (Lesson 3.7) and the walls (Lesson 3.8) build on it.
Assumed: surfaces and tessellation (Lesson 1.3).

1. One solid, several faces
A single exported surface is a solid on its own. Its seam and its poles share corners; open ends get flat caps (Lesson 1.3). A wall is different: it consists of the outer surface, the inner surface and, at each open end, a rim joining the two. That is four faces, and they only make a closed solid if neighbouring faces fit together without a gap.
In CAD this is called a boundary representation (B-rep for short): a solid is described by its hull, that is, by faces and the edges where two faces meet. A solid in knotflow is a list of faces and a list of edges. Every edge is a curve and belongs to exactly two faces; every face knows its edges. There are three kinds of faces:
- a whole surface, usually closed all round (in u), with an edge or a pole at each end in v: the outer wall of a pot, a ball; or a piece of a surface between two creases, then with an edge at each side in u as well (section 3);
- a flat cap on one edge: the floor of an extrusion;
- a flat polygon of several edges: the sides of a box.
Faces with any boundary, trimmed faces, are unknown to the solid. The Booleans (Lesson 3.7) only trim when cutting into triangles.
solid(surface) makes such a solid from a surface (the
same one an exported surface gives); shell,
union, difference and
intersection return solids.
2. Closed because of who shares what
The obvious way to join faces would be to tessellate each one on its own and then merge vertices that lie at the same place. That fails in the details: two faces have their own grids, the vertices along the shared edge do not lie at the same places, and merging by distance needs a tolerance that is either too small or too large somewhere. Lesson 1.4 already said: topology before geometry. Which vertices are shared is decided by the structure, not by coordinates.
So the tessellation goes like this:
- Agree on the parameters. Every face chooses its grid lines in u. Every edge collects the u values of both of its faces, and every face takes over the values of its edges. This is repeated until nothing changes any more. Afterwards, faces that meet at an edge have exactly the same u values along it.
- Edges first. Every edge gets its vertices once, at these u values.
- Faces. Each surface face is tessellated as a grid; its first and last row are replaced by the vertices of its edges. The rim between the outside and the inside thus uses the very same vertex numbers as the two walls.
- Point everything the same way. Each face is tessellated in its own direction. Neighbouring faces must run along a shared edge in opposite directions; where they do not, one of them is turned over, starting from one face and walking from neighbour to neighbour. Finally each closed shell is turned outwards (its volume positive) – unless it lies inside another one: the inside of a hollow ball faces into the hollow. Where the construction already knows which way a face points (the outer wall of a shell points out, the inner one into the wall), that decides. Otherwise a ray does: if it crosses another shell an odd number of times, it starts inside. The thin wall in Lesson 3.8 shows why the ray alone is not enough.
Step 1 has a trap that only shows in the STL file. The u values of the outer surface and those of the inner surface are the same knots, but computed in two ways, and some differ by 10⁻¹⁷. If both went into the grid, two grid lines would lie practically on top of each other. In double precision these are two different vertices; in the STL, which stores single precision floats, they become one, and thousands of edges would have more than two triangles. That is why values closer together than a millionth of the range count as one.
An edge is therefore also closed by construction, not by
coordinates. Whether an edge closes on itself cannot be decided
by comparing its two end points: after a move they differ
by 10⁻¹⁴, and the wall would have a hole. An edge is closed because a
face round it is closed – topology before geometry, again.
3. Creases become edges
An extruded outline with corners, a gear or half a circle with its diameter, is a single NURBS surface. At each corner a knot appears as often as the degree (Lesson 1.2), and the normal jumps: the surface has a crease there, with two tangent planes. Everything that computes on the surface would have to know: the surface intersection stops on the crease (Lesson 3.6), a Boolean asks about both sides (Lesson 3.7), a rounding needs the edge it rolls along (Lesson 3.10).
For a solid, though, a crease is nothing but an edge. So
solid cuts a surface closed in u at its creases, just as it
already cuts it at creases in v (a revolved profile with a flat bottom).
First into bands in v, then each band at the creases in u. The places in
u are the same for every band, the creases of the whole
surface: otherwise one band would have one piece where the next has two,
and the edges between them would not fit. Every piece becomes a face of
the solid:
- a flat piece becomes a flat polygon, like the side of a box;
- a curved piece stays a surface, now with four edges: two at its ends in v and two at its sides in u, whose parameter is the surface's v;
- the open ends become flat polygons of the edges at the start and at the end of each piece.
Here too the solid's corners come from the structure: where the edges
of two faces come together there is a corner, whether or not the
coordinates agree to the last digit. Two creases only a rounding error
apart would give a piece without width, its two side edges on top of
each other; solid leaves such pieces out, the same ones in
every band.
Afterwards no face of a solid has a crease in u: Booleans, roundings
and the tessellation see only smooth faces, and where a face bends
sharply, the topology says so, not a computation on the surface. In
exchange the solid has more faces, a gear with 46 teeth nearly two
hundred. An outline with just one corner, at its seam, stays a surface
with a crease for now; so does a free surface that does not become a
solid: intersect on two surfaces therefore still works with
creases.
4. Two rules for every surface
Two rules concern the tessellation of every surface, not just of solids. A twisted strip, a ruled surface between two wavy rings turned against each other, shows them:
- Spread the budget evenly. At most 1,024 grid lines per direction (Lesson 2.3). Used up from the front, the last spans get nothing, and a finer tolerance makes the surface coarser instead of finer. So an exhausted budget makes the whole direction coarser.
- Split narrow cells along their length. Long, narrow cells can be within the tolerance and still tilted far from the surface; the strip's area would come out 14 % too large. This is the Schwarz lantern: a cylinder made of ever thinner triangles whose area does not converge. So a narrow cell along which the normal turns by more than 10° is split along its length.
Where it stands: over 900 random walls give 453 valid ones and 443 clear messages (fold, crease), none with a wrong volume, a crossing or a hole. Two borderline cases remain: walls of 0.5 mm, 1 m away from the origin, are open after rounding to single precision (that far out, a float cannot say more precisely than 0.00006 mm where a corner is); and twice the offset surface is 0.00018 mm off instead of at most 0.0001 between the places where it is checked.
5. How it is checked
Every solid is checked after it is cut into triangles: every edge
must belong to exactly two triangles that run along it in opposite
directions, also after rounding to the single precision of STL
(kf check, Lesson 1.3). Solids with a known volume (a
hollow ball, a tube, a ring between two cylinders) meet it to 0.2 %.
Browser and command line give the same bytes in the STL and the 3MF for
every example.
Try it yourself
cargo run --release -p kf -- render examples/lampshade.kf -o out/lampshade.stl
cargo run --release -p kf -- check out/lampshade.stl
shell(sphere(10), 2)gives a hollow ball. How many parts doeskf renderreport, and why? Which way do the triangles of the inner ball face?- Export
solid(sphere(10))andsphere(10). Do the files differ? Why not? - A hexagon, extruded:
solid(extrude(polygon(6, 10), 5)). How many faces and how many edges does the solid have? Which of the edges were creases of the surface before? - To think about: two cubes share exactly one edge (corner to corner). How many triangles hang on that edge, and why is that not a fault of the tessellation?