Lesson 3.9 · III Modelling
Rounded edges
What it's about: Sharp edges are unwelcome in 3D printing. At the bottom they bleed into the print bed, at the top they are unpleasant in the hand, and where a boss stands on a plate the part likes to break along the edge. A fillet replaces an edge with a piece of a circle that touches both sides. This lesson builds fillets the way Lesson 3.8 built walls: from building blocks, and exactly. There are two building blocks for it:
filletrounds the corners of a flat curve;aroundcarries a profile around a section, the wayrevolveturns it around the axis.

let plate = rounded_box(width, depth, thick, edge)
let bosses = [boss(circle(size), height, rounding) |> move(…) | …]
export fold(holes, fold(bosses, plate, union), difference)
1. The circle that touches two sides
At a corner, two pieces of a curve meet at an angle. The circle of radius r that touches both has its centre c at distance r from both. If c lies on the normal of the first piece at parameter s and on that of the second at t, then
P₁(s) + r · n₁(s) = P₂(t) + r · n₂(t)
That is two equations (x and y) in the two unknowns s and t, and
Newton solves them in a few steps. Two straight sides give the starting
values: there the circle touches at r · tan(φ/2) from the corner, where
φ is the angle by which the curve turns. fillet cuts both
pieces at the points where the circle touches them
(segment) and puts an exact circular arc in between.
Because the centre lies on both normals, the arc has exactly the sides' direction where it meets them, so no kink is left. Straight sides stay straight, and arcs stay arcs.
Every fillet takes area away (at a corner turning outwards) or adds some (at a corner turning inwards): exactly r² · (tan(φ/2) − φ/2). So a square with four rounded corners loses (4 − π) r². A fuzzer checks this on 5000 random polygons.
2. Which corners
fillet(rectangle(40, 20), 3) // every corner
fillet(rectangle(40, 20), [3, 0, 3, 0]) // one number per corner, 0 stays sharp
fillet(profile, p => if p.x == 0 then 0 else 1) // by where the corner is
corners(rectangle(40, 20)) // [{t, point, turn}], the order
The third form matters for profiles for revolve. A
profile that starts on the axis has corners there. Rounding them would
leave a little dimple in the middle of the floor once the profile is
turned. So the cup (examples/cup.kf) rounds every corner
except those on the axis.
When something does not fit, fillet says so:
- two fillets that overlap on the same side;
- a fillet that does not fit between the neighbouring corners (the message gives the largest radius that does);
- a turn of 180°.
3. The fidget rings
The example fidget_rings_rounded turns each ring from
its profile. The profile is two circular arcs (a ball inside and
outside), cut off flat at the top and bottom. Computing the four little
arcs in the corners by hand with trigonometry takes a function of
fifteen lines. With fillet it is one call:
fn profile(i) = fillet(sharp(r_in(i), r_out(i)), rounding)
The volume is the same as by hand, to the last digit.
4. around:
turning around a section
A plate with rounded edges is not a solid of revolution, but it is
made in a similar way. A profile (a quarter circle at the bottom, the
side, a quarter circle at the top) is carried around the plate's
outline. around(profile, section) does exactly
that. x in the profile is the distance outwards, at right angles to the
section in its plane; y is the height:
S(u, v) = A(u) + x(v) · N(u) + y(v) · Z
Here A is the section and N its outward normal. For sections made of lines and circular arcs, this is one exact NURBS surface:
- Along a line, N is constant, so A + x·N moves the line.
- Along an arc with centre c, A + x·N = c + (A − c)(1 + x/R). That is a scaling about c, and such an affine map keeps a NURBS exact.
- At a sharp outward corner, N turns on the spot: a piece of radius 0. Its surface is a piece of a sphere (or, with a straight profile, of a cylinder).
revolve is the special case where the section is a point
and N the unit circle.
A corner pointing inwards cannot be carried around,
because the profile would fold there. around asks for it to
be rounded first with fillet, at least as much as the
profile reaches out.
The prelude builds on around:
rounded_box(w, d, h, r) // a box with every edge rounded
rounded_extrude(section, h, r) // a section extruded, rounded at top and bottom

The touchstone here is Steiner's formula. A section with area F and
perimeter L, moved outwards by x, has the area F + L·x + π·x². So the
volume of every surface from around is known, and the
rounded box has exactly abc + 2r(ab + bc + ca) + πr²(a + b + c) +
⁴⁄₃πr³.
5. A point is not a rim
A rounded_box has a flat floor whose rim is the section
itself, at x = 0. If the section is a sharp rectangle, the radius-0
piece shrinks to a point at every corner, and the floor's rim would get
pieces of length zero there. Tessellation does not know such half poles.
So rounded_box rounds the corners of its section by a
thousandth of r. The box then deviates by at most that thousandth at its
corners, far below anything a printer shows. Whoever uses
around directly gets a message with exactly this advice at
that point.
6. Bosses with a fillet
Where a boss stands on a plate, the edge at its foot should be
rounded inwards. The profile is simple: the boss gets a foot, and a
quarter circle bending inwards leads from the top of the plate to the
boss's wall. boss(section, height, r) builds this with
around, for any section: round, or angular with rounded
corners.
But a fillet touches the plate by definition,
tangentially along a whole line. That is exactly the weak spot of
booleans (Lesson 3.7, section 4): a surface that touches another along a
line does not cut it there, so the union with the plate would stay open.
That is why boss lets the fillet dip a hundredth of r below
the top of the plate, so that the two surfaces cut each other at about
8°. The deviation from the exact fillet is that hundredth: at r = 1.5
mm, 0.015 mm. Below, the boss reaches a twentieth of r into the plate,
which must not be thinner than that.
7. On to Lesson 3.10
The building blocks of this lesson round what can be drawn as a curve or a profile:
- the rims of vessels;
- the edges of plates and boxes;
- the vertical edges of extruded parts
(
extrude(fillet(section, r), h)); - bosses on plates.
An edge between two faces of a finished solid, such as one a boolean has left behind, is rounded differently: a ball rolls along both faces. Its centre line is where the two offset surfaces meet (Lessons 3.8 and 3.6). The strip the ball cuts out of both faces is taken away by a boolean, with a tool built from a rounding of this lesson. Lesson 3.10 shows how. There, too, the rounding dips a hundredth of r into the faces, for the same reason as the boss's fillet in section 6: what only touches a face does not cut it.
Where rounded solids have faces that coincide or touch, the same weakness of the booleans shows. These cases give a message or an open mesh:
- two bosses whose fillets overlap;
- a
rounded_boxwith a smaller concentricrounded_boxtaken away (a hollow box with an even wall) –shell(extrude(rounded_rectangle(…), h), t)is the way for that; - two rounded boxes standing flush on or next to each other;
- a shell whose wall is exactly as thick as the section's corner radius.
8. How it is checked
Every rounding of a curve takes or gives exactly r² · (tan(φ/2) −
φ/2) of area; a fuzzer checks this on thousands of random polygons, and
also that no corner is left and nothing crosses. The volumes of the
rounded box and the rounded extrusion follow Steiner's formula,
around a circle gives the same as revolve, and
booleans with rounded solids (a hole through a sphere corner, bosses on
plates) are closed. Browser and command line give byte-identical
files.
Try it yourself
cargo run --release -p kf -- render examples/rounded_plate.kf -o out/plate.png
cargo run --release -p kf -- render examples/cup.kf -D rounding=1.2 -o out/cup.stl
cargo run --release -p kf -- render examples/fidget_rings_rounded.kf -D section=true -o out/rings.png
- Set the cup's
roundingto half the wall. What does the rim look like now, and why can it not get any rounder? - Round the cup's corners on the axis too. Where does the dimple appear?
- Build
rounded_extrudewith a section that has a sharp corner pointing inwards. What does the message say? - Why does a line stay a line when
aroundmoves it outwards, but an arc does not stay the same arc? - Work it out: by how much is the volume of a rounded box smaller than that of the sharp box?