Examples
A hollow elbow
The smallest useful model: a hollow 90° elbow from three waypoints.
Source: examples/01_elbow.scad
// A hollow elbow
// The smallest useful model: a hollow 90° elbow from three waypoints.
// 01_elbow — the worked example from docs/reference/ir.md.
//
// A 90-degree hollow elbow: three spine segments, one polyhedron, no CSG.
// render() forces CGAL, so `just verify` has a report to read; a raw
// polyhedron() is never validated otherwise. A tiny subtracted cube would do it
// too, but it PERTURBS THE GEOMETRY -- at the origin of a manifold that is
// inside the material.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 6;
$fs = 0.5;
path = ut_polyline([ [ 0, 0, 0 ], [ 50, 0, 0 ], [ 50, 50, 0 ] ], r = 15);
prof = ut_round(od = 12, wall = 2);
// The example geometry, as a module so `just verify` can wrap it in a no-op
// boolean to force CGAL. A raw polyhedron() is never validated otherwise.
module part()
{
ut_tube(path, prof);
}
part();
examples/01_elbow.scad on GitHub
A polyline run
A long 3D run with a different fillet radius at each of six bends.
Source: examples/02_polyline_run.scad
// A polyline run
// A long 3D run with a different fillet radius at each of six bends.
// 02_polyline_run — the legacy demo path, ported.
//
// These are the exact waypoints and radii from reference/axford/curvedPipe.scad's
// own test piece. Since commit 5d2975b (2025-01-10) every BEND in this path has
// rendered as literally nothing, because torusSlice's parameters were renamed
// without updating the call sites. This is the regression made visible.
//
// It lowers to 12 spine segments over 544.21 mm. Note that two of the bends are
// exactly tangent -- the straight between them is zero-length and is omitted
// rather than emitted as a degenerate segment.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 8;
$fs = 1;
pts = [
[ 0, 0, 0 ], [ 100, 0, 0 ], [ 100, 100, 0 ], [ 50, 100, 100 ], [ 50, 100, 150 ], [ 0, 100, 50 ], [ 0, 0, 0 ],
[ 50, 0, 50 ]
];
radii = [ 70, 30, 30, 6, 50, 30 ];
// The example geometry, as a module so `just verify` can wrap it in a no-op
// boolean to force CGAL. A raw polyhedron() is never validated otherwise.
module part()
{
ut_tube(ut_polyline(pts, r = radii), ut_round(od = 10, id = 8));
}
part();
examples/02_polyline_run.scad on GitHub
A turtle route
A bender program. roll puts later bends in a different plane.
Source: examples/03_turtle_route.scad
// A turtle route
// A bender program. `roll` puts later bends in a different plane.
// 03_turtle_route — a bender program.
//
// This is the frontend that PROVES the IR (ADR 0002). It is shaped nothing like
// the polyline frontend -- relative rather than absolute, with an explicit roll
// command -- and it lowers to the same spine without the spine growing a case.
//
// `roll` emits NO GEOMETRY. It rotates the turtle's own up-vector, which changes
// the PLANE of every subsequent bend and therefore the shape of the path, and
// then it is gone. Nothing about roll enters the IR, because a bender rotating
// the workpiece does not twist the tube. Comment out the roll below and the last
// two bends fold back into the first plane.
//
// This is also literally how a CNC tube bender is programmed: Length, Rotation,
// Angle.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 6;
$fs = 0.5;
module part()
{
route = ut_turtle([
[ "feed", 60 ],
[ "bend", 90, "r", 24 ],
[ "feed", 40 ],
[ "roll", 90 ], // no geometry -- but the next bend leaves the plane
[ "bend", 45, "r", 24 ],
[ "feed", 30 ],
[ "roll", -60 ],
[ "bend", 60, "r", 20 ],
[ "feed", 45 ],
]);
ut_tube(route, ut_round(od = 12, wall = 2));
}
part();
examples/03_turtle_route.scad on GitHub
A helix
A parametric coil with ut_curve, with exact tangents from dfdt.
Source: examples/04_helix.scad
// A helix
// A parametric coil with `ut_curve`, with exact tangents from `dfdt`.
// 04_helix — an arbitrary parametric centreline.
//
// The only frontend that expresses helices, coils and serpentines. It lowers to
// a single sampled `P` segment, which is honest about what it gives up: exact
// arclength, exact transport, and the minimum-bend-radius check all need arcs.
// Measured here, the sampled length is 0.025% under the analytic helix length --
// a chord approximation, behaving exactly as documented.
//
// Supplying `dfdt` gives EXACT tangents at every sample instead of central
// differences, which is worth doing whenever the derivative is known.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 6;
$fs = 0.5;
R = 50; // helix radius
TURNS = 2.5; // how many
RISE = 45; // mm of climb per turn
module part()
{
coil =
ut_curve(function(t)[R * cos(360 * TURNS * t), R * sin(360 * TURNS * t), RISE * TURNS * t],
dfdt = function(t)[-R * sin(360 * TURNS * t), R * cos(360 * TURNS * t), RISE * TURNS / 360], n = 220);
ut_tube(coil, ut_round(od = 10, wall = 2));
}
part();
examples/04_helix.scad on GitHub
A split conduit
A C-section whose gap faces up along two bends: a split profile plus frame = "fixed".
Source: examples/05_split_conduit.scad
// A split conduit
// A C-section whose gap faces up along two bends: a split profile plus `frame = "fixed"`.
// 05_split_conduit — replaces reference/axford/half_curvedPipe.scad.
//
// A lengthwise-split conduit over two bends in DIFFERENT planes. The seam must
// not wander around the tube as the axis turns; that is the entire problem
// half_curvedPipe.scad existed to solve, in ~300 lines and with a hard
// nine-segment ceiling.
//
// Here it is two things:
// * the split is a PROFILE ut_round(..., split=[-30,30])
// * the seam is a FRAME POLICY frame="fixed", normal=UP
//
// "fixed" is better than transport for a printable part: transport only
// guarantees the seam does not spiral relative to the TUBE, whereas a printed
// part has a gravity-relative requirement. Here the gap faces as near world-up
// as the axis allows the whole way, so it prints as an open channel with no
// bridging.
//
// THE RUN NEVER GOES VERTICAL, AND THAT IS A CONSTRAINT, NOT AN ACCIDENT. A seam
// pinned to a world direction is undefined where the axis points along it -- a
// vertical pipe has no upward-facing side. This example used to climb straight
// up +Z at the end, and the seam flipped 174 degrees in a single 6-degree step
// while the mesh stayed manifold and every gate passed. The final leg now rises
// at 37 degrees, and ut_stations() refuses the degenerate ask outright.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 6;
$fs = 0.5;
path = ut_polyline([ [ 0, 0, 0 ], [ 60, 0, 0 ], [ 60, 40, 0 ], [ 100, 40, 30 ] ], r = 18);
prof = ut_round(od = 16, wall = 2, split = [ -30, 30 ]);
// The example geometry, as a module so `just verify` can wrap it in a no-op
// boolean to force CGAL. A raw polyhedron() is never validated otherwise.
module part()
{
ut_tube(path, prof, opts = [ [ "frame", "fixed" ], [ "normal", [ 0, 0, 1 ] ] ]);
}
part();
examples/05_split_conduit.scad on GitHub
A four-into-one manifold
Four inlets converging on one outlet at a single declared joint.
Source: examples/06_manifold_4into1.scad
// A four-into-one manifold
// Four inlets converging on one outlet at a single declared joint.
// 06_manifold_4into1 — THE ACCEPTANCE TEST.
//
// Four inlets converging into one outlet. This is the driving application the
// whole project was started for, and it has never rendered in ANY commit of this
// repository: the 2023 attempt (see docs/developer/history.md §4) got about 60% of the way
// and stopped at the bend lumen, calling torusSlice_only_inner_pipes(), which
// `git log -S` confirms was never defined anywhere.
//
// What makes it work is that the bore is FREE: the same spine, the same
// stations and the same frame as the shell, swept with a different region. The
// assembler then runs one difference per lumen group -- all shells unioned
// first, all bores cut second -- so no branch's wall can seal another's lumen.
//
// `Simple: yes` does NOT prove the lumens are open; the sealed version reports
// exactly the same. checks/manifold/ asserts patency independently.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 8;
$fs = 1;
BRANCH_OD = 12;
BRANCH_ID = 8;
TRUNK_OD = 16;
TRUNK_ID = 12;
N = 4; // inlets
RING = 50; // how far out each inlet starts
DROP = -55; // and how far below
module part()
{
prof = ut_round(od = BRANCH_OD, id = BRANCH_ID);
branches = [for (i = [0:N - 1]) let(th = 360 * i / N) ut_run(
str("in", i),
ut_polyline([[RING * cos(th), RING * sin(th), DROP], [RING * cos(th), RING * sin(th), -25], [0, 0, 0]], r = 15),
prof)];
trunk = ut_run("out", ut_polyline([ [ 0, 0, 0 ], [ 0, 0, 55 ] ]), ut_round(od = TRUNK_OD, id = TRUNK_ID));
net = ut_net(concat(branches, [trunk]),
[ut_joint(concat([for (i = [0:N - 1])[str("in", i), "b"]], [[ "out", "a" ]]), at = [ 0, 0, 0 ])]);
ut_assemble(net);
}
part();
examples/06_manifold_4into1.scad on GitHub
Port frames
Port frames drawn as arrows: outward direction in red, roll reference in blue.
Source: examples/07_ports_debug.scad
// Port frames
// Port frames drawn as arrows: outward direction in red, roll reference in blue.
// 07_ports_debug — the termination seam, made visible.
//
// A port carries a full FRAME, not a position and a diameter. Red is the
// OUTWARD direction; blue is the roll reference, which is the clocking a hex
// flat or bayonet lug would be aligned to. Terminations themselves are a
// separate library (ADR 0005) -- this is the interface they attach to.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 8;
$fs = 1;
path = ut_polyline([ [ 0, 0, 0 ], [ 60, 0, 0 ], [ 60, 40, 0 ], [ 60, 40, 40 ] ], r = 18);
prof = ut_round(id = 8, wall = 2);
ports = ut_run_ports(path, prof, "demo");
// The example geometry, as a module so `just verify` can wrap it in a no-op
// boolean to force CGAL. A raw polyhedron() is never validated otherwise.
module part()
{
color("silver") ut_tube(path, prof);
for (p = ports)
ut_port_marker(p);
}
part();
examples/07_ports_debug.scad on GitHub
A coaxial jacket
A tube inside a tube, kept apart by lumen groups.
Source: examples/08_coaxial_jacket.scad
// A coaxial jacket
// A tube inside a tube, kept apart by lumen groups.
// 08_coaxial_jacket — the LUMEN GROUP regression.
//
// A tube inside a tube: a Bowden liner in a conduit, a double-wall flue, a
// vacuum jacket, a tube-in-tube exchanger. Ordinary tube topology.
//
// Under ONE global difference over the whole assembly, the outer run's bore
// (d26) swallows the inner run's shell (d12) entirely -- measured, 7883.8 of
// 29958.5 mm3, 26% of the material, silently deleted, with CGAL still reporting
// `Simple: yes`. The invariant did not remove silent corruption, it swapped one
// flavour for its dual, and the new one looks plausible.
//
// The fix is five lines: every run carries a lumen group, and the two-pass runs
// once per group. Declaring the group is the user's job, and ut_check_net's
// NET-5 refuses the assembly if two nesting runs share one.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 8;
$fs = 1;
module part()
{
path = ut_polyline([ [ 0, 0, 0 ], [ 60, 0, 0 ], [ 60, 50, 0 ] ], r = 20);
jacket = ut_run("jacket", path, ut_round(od = 30, id = 26), group = 0);
liner = ut_run("liner", path, ut_round(od = 12, id = 8), group = 1);
ut_assemble(ut_net([ jacket, liner ]));
}
part();
examples/08_coaxial_jacket.scad on GitHub
A square bore
An arbitrary section: a square bore in a round tube, sampled by angle.
Source: examples/09_square_bore.scad
// A square bore
// An arbitrary section: a square bore in a round tube, sampled by angle.
// 09_square_bore — an arbitrary hollow section, with no special case anywhere in
// the backend. A round shell over a square lumen.
//
// The bore is sampled BY ANGLE, at the same angles as the shell. That is what
// PROF-2 requires and it is not optional: sampling the square by PERIMETER gives
// the right point count, starts the loop at a corner while the shell starts at
// 0 degrees, twists the end-cap strip around the annulus, and CGAL reports only
// "assertion violation". See ADR 0006 and tests/guards/g_prof_align.scad.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 6;
$fs = 0.5;
function square_by_angle(h, n) = [for (k = [0:n - 1])
let(t = 360 * k / n, cx = cos(t), cy = sin(t), m = h / max(abs(cx), abs(cy)))[m * cx, m *cy]];
N = ut_fragments(7, 360);
prof = ut_profile(ut_ring(7, N), square_by_angle(4, N), [ [ "od", 14 ], [ "kind", "square-bore" ] ]);
path = ut_polyline([ [ 0, 0, 0 ], [ 50, 0, 0 ], [ 50, 40, 0 ] ], r = 18);
// The example geometry, as a module so `just verify` can wrap it in a no-op
// boolean to force CGAL. A raw polyhedron() is never validated otherwise.
module part()
{
ut_tube(path, prof);
}
part();
examples/09_square_bore.scad on GitHub
A tee landing on a wall
A branch drawn from the trunk’s outer wall, joined mid-run.
Source: examples/10_tee_wall_landing.scad
// A tee landing on a wall
// A branch drawn from the trunk's outer wall, joined mid-run.
// 10_tee_wall_landing — the junction case that breaks the naive construction.
//
// The branch starts on the trunk's outer WALL, not on its axis. That is how
// every real tee is described, and how reference/doommeister/'s own middle_tee_n
// is parameterised -- and in design review it produced a 0.95 mm PLUG across the
// branch lumen while CGAL reported `Simple: yes, Volumes: 2` and a naive
// manifoldness regression test PASSED.
//
// Two things fix it, and neither is a global epsilon:
// * the joint is DECLARED, with a mid-run landing ["s", 50] on the trunk, so
// the assembler knows the node is on the trunk CENTRELINE;
// * both the shell AND the bore are extended from the branch end to that node.
// Extending only the bore leaves the shells touching tangentially -- measured
// `Simple: yes, Volumes: 3`, two solids sharing a circle.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 8;
$fs = 1;
module part()
{
trunk = ut_run("trunk", ut_polyline([ [ -50, 0, 0 ], [ 50, 0, 0 ] ]), ut_round(od = 20, wall = 2));
// Starts at y = 10, exactly on the trunk's outer surface.
branch = ut_run("branch", ut_polyline([ [ 0, 10, 0 ], [ 0, 50, 0 ] ]), ut_round(od = 12, wall = 2));
ut_assemble(ut_net([ trunk, branch ], [ut_joint([ [ "trunk", [ "s", 50 ] ], [ "branch", "a" ] ])]));
}
part();
examples/10_tee_wall_landing.scad on GitHub
A closed loop
A closed path. Its bore is a sealed cavity.
Source: examples/11_closed_loop.scad
// A closed loop
// A closed path. Its bore is a sealed cavity.
// 11_closed_loop — a closed path.
//
// The closed machinery has existed since Phase 1 and was never reachable: the
// holonomy absorption in ut_stations, the cap-suppressing wrap in ut_mesh, and
// SPINE-2's closed contiguity check were all built and all correct. What was
// missing was a way to ask for one, a test, and the STATION-7 fix.
//
// Closed paths are reachable through ut_spine ONLY. ut_polyline refuses them
// explicitly, and ut_turtle and ut_curve have no `closed` parameter at all
// (--hardwarnings turns passing one into an error). Wiring `closed` through the
// other frontends raises a real question each -- what IS a closed turtle
// program? -- and is deliberately not answered yet.
//
// WHAT A CLOSED TUBE IS: its lumen is a SEALED INTERNAL CAVITY. CGAL reports
// `Volumes: 3` -- the outside, the material, and the trapped bore -- which is
// geometrically correct and means the part is useless until something breaches
// it. That is a property of the topology, not a defect.
//
// The frame is transported all the way round and the loop holonomy is measured,
// absorbed against the profile's rotational symmetry, and distributed by
// arclength, so the seam meets itself exactly. Measured residual: 0 degrees.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 6;
$fs = 0.5;
R = 60;
module part()
{
// Four quarter arcs about the origin, tangent-continuous, closing on themselves.
loop = ut_spine(
[
ut_arc([ 0, 0, 0 ], [ 1, 0, 0 ], [ 0, 1, 0 ], R, 90),
ut_arc([ 0, 0, 0 ], [ 0, 1, 0 ], [ -1, 0, 0 ], R, 90),
ut_arc([ 0, 0, 0 ], [ -1, 0, 0 ], [ 0, -1, 0 ], R, 90),
ut_arc([ 0, 0, 0 ], [ 0, -1, 0 ], [ 1, 0, 0 ], R, 90),
],
closed = true);
ut_tube(loop, ut_round(od = 14, wall = 2));
}
part();
examples/11_closed_loop.scad on GitHub
A section view
A twisted square-bore tube cut open with ut_cutaway, so the roll is visible on the cut face. Known issue (uniTube#33): the twist necks the tube on straight legs, to an outer radius of 8.56 mm against a nominal 9.
Source: examples/12_section_view.scad
// A section view
// A twisted square-bore tube cut open with `ut_cutaway`, so the roll is visible on the cut face.
// Known issue (uniTube#33): the twist necks the tube on straight legs, to an outer radius of
// 8.56 mm against a nominal 9.
// 12_section_view — how to LOOK at a hollow part.
//
// Two questions come up on every model this library makes, and neither is
// answerable by rotating the viewport:
//
// * IS THE BORE OPEN? An open bore seen at a shallow angle and a sealed end
// render identically, and `Simple: yes` does not settle it -- a sealed lumen
// reports exactly that.
// * WHERE IS THE ROLL? A round tube looks the same however the frame is
// clocked, so a twist or the wrong frame policy stays invisible.
//
// They are the SAME question, and one cut answers both: the section shows the
// bore directly, and because this profile has a SQUARE bore, the orientation of
// the cut face is the roll. The run is twisted a quarter turn, and you can watch
// the square rotate along it.
//
// SECTION is the toggle. Set it false and this is an ordinary solid part.
// clang-format off
use <../src/uniTube.scad>;
// clang-format on
$fa = 6;
$fs = 0.5;
SECTION = true;
// A square bore in a round tube -- ut_profile asserts PROF-2, so the square is
// sampled BY ANGLE to stay index-aligned with the outer circle (ADR 0006).
function square_by_angle(h, n) = [for (i = [0:n - 1]) let(a = 360 * i / n, c = cos(a), s = sin(a)) h /
max(abs(c), abs(s)) * [ c, s ]];
N = ut_fragments(9, 360);
prof = ut_profile(ut_ring(9, N), square_by_angle(5, N), [ [ "od", 18 ], [ "kind", "square-bore" ] ]);
path = ut_polyline([ [ 0, 0, 0 ], [ 70, 0, 0 ], [ 70, 60, 0 ] ], r = 22);
module part()
{
ut_cutaway([ 0, 0, 1 ], at = 0, on = SECTION) ut_tube(path, prof, opts = [[ "twist", 90 ]]);
}
part();