Lesson 3.3 · III Modelling
Walls: moving curves sideways
What it's about: A cup, a bowl, a pot: they all have
a wall of a certain thickness. It is measured at right angles to the
wall, not horizontally. For this there are three building blocks for
flat curves: chaining curves (chain),
reversing curves (reverse) and
moving curves sideways (offset; the result
is also known as a parallel curve). From these, the language itself
builds thicken: from a profile, a closed outline with a
wall thickness, ready for revolve. This lesson stays in the
plane; the wall of a whole surface, with floor and rim, is made by
shell (Lesson 3.8).

1. Measured horizontally is too thin
The pot (examples/pot.kf) draws its wall like this: on
the outside the point (rt, height), on the inside
(rt - wall, height). So the wall is moved inwards
horizontally by wall. If the wall is
vertical, that is the same thing. If it leans at an angle α, the real
thickness at right angles to the wall is only
wall · cos α:
| Wall | Lean α | 1.6 mm horizontally gives |
|---|---|---|
| the pot (radius 55 → 75 mm over a height of 150 mm) | 7.6° | 1.59 mm |
| a bowl with a 45° wall | 45° | 1.13 mm |
| a shallow bowl | 60° | 0.80 mm |
For the pot it does not matter: 0.8 % less material. For a bowl with a 45° wall almost a third is missing, at 60° half, and finding that out only in the slicer's print preview is annoying. The right thing is to move every point of the wall along its normal.
2. Offset: every point along its normal
offset(curve, d) moves every point of the curve sideways
by d, namely to the left of the direction
of travel (seen from above, z pointing up). For a profile drawn from
bottom to top (x = radius), left is inwards. A negative d
goes to the right.
The surprise: the offset curve of a NURBS curve is in general not a NURBS curve. The normal is the derivative divided by its length, and that length contains a square root. A quotient of polynomials, which is what a NURBS curve is (Lesson 1.2), cannot reproduce a root. The exceptions are straight lines (the length of the derivative is constant) and circles (the offset curve is a circle with a different radius).
So it is approximated, but under control:
- For many parameters t, the exact offset point is computed, along with its exact direction.
- Between two such points lies a cubic piece that passes exactly through the point at both ends and points exactly in the right direction (Hermite interpolation). The error of such a piece falls with the fourth power of its length.
- Each piece is checked against the exact offset point in seven places. If it is more than 0.0001 mm off, it is cut in half.
Straight lines and arcs stay exact. offset looks at the
curve one Bézier piece at a time: a straight piece is moved, a piece of
a circle is scaled about its centre, both with the same control points
and weights. That is not just nice to have. Built from cubic pieces as
well, they would give the pot eight times as many triangles, although
nothing about its shape changes. And everything done with the curve
afterwards costs more: the outline of a splined shaft, made of arcs and
involutes, had four times as many control points once offset, and a
boolean with it took 3.3 s instead of 0.1 s.
3. Corners, narrow places, loops
At a corner the normal jumps. The two neighbouring pieces, once moved, no longer fit together:
- The corner turns away from the offset side (a square offset outwards): a gap opens between the pieces. It is filled with an exact circular arc of radius d around the corner. This is not decoration: all points at distance d from a corner lie on exactly this arc.
- The corner turns towards the offset side (a square offset inwards): the two pieces overlap and have to be shortened up to the point where they cross.
Looking only at the two neighbours of a corner is not enough, though. If a piece is shorter than d, say a small chamfer or a step in the floor of a cup, the real offset simply passes over the short piece; a method that only shortens neighbours would find no crossing there and have to give up.
So offset uses the method that drawing programs use as
well. It does not think about corners but about distances:
- Raw offset. Each piece between two corners is offset on its own. On the outside the arc is added. On the inside, if the pieces cross right at the corner, they are shortened there; otherwise two straight pieces connect them through the corner itself. The result is a closed line with loops.
- Find the crossings. Wherever the raw offset crosses itself, it is cut. The search runs over short straight steps along the curve, sorted into a grid: only steps in the same cell are compared. Each crossing of steps is then confirmed on the real curves with Newton's method. So two arcs that merely come close between two steps do not count.
- Throw away the loops. Each piece between two cuts is checked at its middle: if it is closer than d to the original curve there, it belongs to a loop and is dropped. What is left is the offset.
An open curve needs one more thing: around its end, the offset can get to the other side of a piece and come too close to it there, without crossing itself. So there the circles of radius d around the start and the end, and the offset to the other side, cut as well. They are not part of the result; they only cut. Whatever tiny loops are still left at the end, for example at the tip where the offset of a sharp bend folds over, are searched for once more and cut out.
4. What can't be done says so
Three things cannot be done, and they are reported, with a location:
- Nothing is left: a circle of radius 5 mm, offset inwards by 6 mm, has no point that is 6 mm from its edge ("leaves nothing").
- The offset falls apart: if the shape is narrower
than 2 d somewhere, for example because of a neck or a deep notch, the
offset breaks into separate pieces.
offsetcannot return a curve made of several parts, so you get the message "falls apart near …". - The offset crosses itself where no loop can be cut off cleanly: a circle of radius 10 mm, offset inwards by exactly 10 mm, shrinks to a point.
The same crossing search also runs in revolve: a profile
that crosses itself would give a solid that runs through itself. Instead
of making it silently, revolve reports, for example, "the
profile crosses itself near (2, 1)". Touching on the axis is the
exception: two balls on top of each other touch there, and that is a
valid solid. What to do in each of these cases is in the handbook,
chapter 6.
5. Chaining curves
A profile often consists of pieces: a straight floor, a curved wall,
an arc at the rim. chain([a, b, c]) makes
one curve out of them. Each one must start where the
previous one ends (otherwise the message says how large the gap is).
Three things happen along the way:
- The same degree. A NURBS curve has only one degree. A straight line (degree 1) and a circular arc (degree 2) are raised to the highest degree, and exactly so: each polynomial piece is written on its own as a Bézier curve of higher degree. For a step from degree n to n + 1: Q_i = i/(n+1) · P_(i−1) + (1 − i/(n+1)) · P_i. The shape does not change.
- The same weights at the joint. Multiplying all the weights of a curve by the same number does not change it (Lesson 1.2). This way the two end points that become one get the same weight.
- Parameters by length. Each piece gets the share of
the range 0 … 1 that it has of the length.
at(curve, 0.5)then lies roughly in the middle.
On top of that there is reverse(curve): the same curve,
run the other way round. You need it to close an outline in a loop.
For closed outlines "to the left of the direction" is awkward:
whether left is inside depends on whether the outline runs anticlockwise
or clockwise. inset(outline, d) takes care of that. It
moves a closed outline inwards by d (outwards for negative d), whichever
way round it runs, and is one line in the prelude:
fn inset(c, d) = offset(c, if clockwise(c) then -d else d)
6. thicken:
written in the language
With these three building blocks, the wall is one line in the prelude:
fn thicken(c, t) = chain([c, line(at(c, 1), at(inner, 1)), reverse(inner), line(at(inner, 0), at(c, 0))])
where inner = offset(c, t)
The profile on the outside, a straight rim across at the top, the
offset curve back on the inside, and back to the start at the bottom.
For a cup, the profile starts on the axis, runs out along the floor and
up the wall (examples/cup.kf):
let floor = line((0, 0), (foot, 0))
let side = interpolate([(foot, 0), (belly, widest * height), (mouth, height)])
export revolve(thicken(chain([floor, side]), wall))
The corner between floor and wall turns left, that is inwards: there the floor and the wall of the inside are shortened until they meet. The floor is as thick as the wall, measured at right angles to both. The start of the inside lies on the axis again, at (0, wall).
A test with a known result: a straight cup, 10 mm outer radius and 20 mm high, wall and floor 1 mm. Its volume is π · (10² · 20 − 9² · 19) = 1,448.3 mm³. The tessellated solid hits that to within 0.1 %, and it is closed.
7. Limits, and where it goes on
- Walls for surfaces are not
thicken's job: it works with profiles, that is, with anything that can be turned (revolve). The twisted vase, though, is aloftthrough polygons. Its wall needs the offset surface of a surface, and the outer and inner surface must be joined by a rim into one solid. That is whatshelldoes (Lesson 3.8). - An offset in several parts does not exist: if the offset falls apart at a narrow place, a message comes instead of a list of curves.
- Outer corners are round: outside there is always the arc, no mitre.
8. How it is checked
A fuzz test offsets tens of thousands of random curves (polylines, closed ones, NURBS up to degree 3) by random distances and checks every offset: every point checked exactly d from the curve, on the right side, without a crossing, or one of the three messages. On top of that come malicious single cases: a 0.5 mm chamfer under a 1 mm thick wall, a polyline of 2000 pieces each bending by 0.0005°, a square at x = 10⁸, a zigzag with 20,000 corners.
Try it yourself
cargo run --release -p kf -- render examples/cup.kf -o out/cup.png
cargo run --release -p kf -- render examples/cup.kf -D wall=6 -D belly=60 -o out/cup.stl
cargo run --release -p kf -- svg --demo corners -o out/corners.svg
- Rebuild
examples/pot.kfwiththicken: the profile ispolyline([(0, 0), (rb, 0), (rt, height)]). Compare the volumes thatkf renderprints. Where does the difference come from? - What does
offset(circle(10), 10)report, and why exactly that? What happens with-10? - Draw a profile with a notch: a polyline that briefly goes deep
inwards and back out again. Increase
walluntil the message appears. Where does it report the falling apart, and does that match your drawing? What does the offset do at the notch just before that? - Something to think about: the offset curve of a circle is a circle. Why is the offset curve of a parabola not a parabola? (Hint: how does the distance between the points change when you move a parabola inwards?)