Components / Building blocks
Printed

Blended fillet

One rounded edge that changes radius smoothly round a corner.

Two separate fillets of different sizes leave a crease where they meet. This rounds a whole chain of edges in one operation, with the radius set at each corner by a function, so a big radius along the front can fade into a small one down the sides.

Printed: Printed, but the mechanism has not been exercised yet.Printed on a laptop lid: 8 mm along the front edge blending into 3 mm along the sides.
3D model: Blended filletLoading 3D view
lid with a blended edge

Use it in code

typescript
import { ready, geom } from "partkit";
await ready();

lid = geom.blendedFillet(
  lid,
  ([x, y, z]) => Math.abs(z - 15) < 1e-6 && Math.abs(y + 215) < 1e-6,   // pick the front top edge
  (x, y, z) => (y < -204 && Math.abs(x) < 176 ? 8.0 : 3.0));            // 8 mm in front, 3 mm down the sides

What you print

  • Nothing by itself

Functions

CallWhat it gives you
geom.blendedFillet(part, seedPick, radAt)seedPick(midpoint) chooses one starting edge; radAt(x, y, z) gives the radius at each corner point.

Frame. Works on any solid. The chain is every edge that runs on smoothly from the seed edge.

Check before you print

  • The result is a valid solid (the function asserts it)

Learned the hard way

  • A bevel that stops at a corner reads as a mistake on the printed part; blend it.

Open it in Fusion 360

The scene above as a STEP file: real solid bodies, each part its own named component, in position. In Fusion 360 use File, Open, then Open from my computer. It also opens in FreeCAD, SolidWorks and Onshape. It carries the shapes, not the sizes you can change; for different sizes, use Make it above or change them in code.

Source: ts/src/geom.ts
typescript
/** Small solid-building helpers shared by every component. Units are millimetres.
 *  Convention: a hinge or barrel axis runs along X; "sections" are drawn in the YZ plane. */
import { makeBox, makeCylinder, makePolygon, basicFaceExtrusion, Vector, measureVolume, drawRoundedRectangle, getOC, iterTopo, cast, type Shape3D } from "replicad";

export type Solid = Shape3D;
export type P2 = [number, number];

export const box = (x0: number, x1: number, y0: number, y1: number, z0: number, z1: number): Solid =>
  makeBox([x0, y0, z0], [x1, y1, z1]);

/** Cylinder along X from x0 to x1, centred on (y, z). */
export const xcyl = (r: number, x0: number, x1: number, y = 0, z = 0): Solid => makeCylinder(r, x1 - x0, [x0, y, z], [1, 0, 0]);
/** Cylinder along Y from y0 to y1, centred on (x, z). */
export const ycyl = (r: number, x: number, z: number, y0: number, y1: number): Solid => makeCylinder(r, y1 - y0, [x, y0, z], [0, 1, 0]);
/** Cylinder along Z from z0 to z1, centred on (x, y). */
export const zcyl = (r: number, x: number, y: number, z0: number, z1: number): Solid => makeCylinder(r, z1 - z0, [x, y, z0], [0, 0, 1]);

/** Prism along X from x0 to x1 whose section is the polygon pts, given as (y, z) points. */
export function prismYZ(pts: P2[], x0: number, x1: number): Solid {
  let area = 0;
  for (let i = 0; i < pts.length; i++) {
    const [y0, z0] = pts[i];
    const [y1, z1] = pts[(i + 1) % pts.length];
    area += y0 * z1 - y1 * z0;
  }
  const ordered = area >= 0 ? pts : [...pts].reverse(); // counter-clockwise seen from +x
  const face = makePolygon(ordered.map(([y, z]) => [x0, y, z] as [number, number, number]));
  return basicFaceExtrusion(face, new Vector([x1 - x0, 0, 0]));
}

const rad = (d: number) => (d * Math.PI) / 180;

/** Prism along X whose YZ section is a rectangle in axes turned by deg: a along that direction, b across it. */
export function framePrism(deg: number, a0: number, a1: number, b0: number, b1: number, x0: number, x1: number): Solid {
  const u: P2 = [Math.cos(rad(deg)), Math.sin(rad(deg))];
  const v: P2 = [-u[1], u[0]];
  const pts = ([[a0, b0], [a1, b0], [a1, b1], [a0, b1]] as P2[]).map(([a, b]) => [a * u[0] + b * v[0], a * u[1] + b * v[1]] as P2);
  return prismYZ(pts, x0, x1);
}

/** Wedge along X between two directions in the YZ plane (less than 180 apart), from the axis out to r. */
export function sector(d0: number, d1: number, x0: number, x1: number, r = 80): Solid {
  const dm = (d0 + d1) / 2;
  const pts: P2[] = [[0, 0], ...[d0, dm, d1].map((d) => [r * Math.cos(rad(d)), r * Math.sin(rad(d))] as P2)];
  return prismYZ(pts, x0, x1);
}

export const cutAll = (body: Solid, tools: Solid[]): Solid => tools.reduce((b, t) => b.cut(t), body);
export const unionAll = (parts: Solid[]): Solid => parts.slice(1).reduce((b, t) => b.fuse(t), parts[0]);

/** The left-hand version of a right-hand part (mirror about x = 0). */
export const mirrored = (s: Solid): Solid => s.clone().mirror("YZ", [0, 0, 0]) as Solid;

/** Split at x = 0 into [left, right], for parts wider than the printer's bed. */
export function halves(body: Solid, big = 1000): [Solid, Solid] {
  return [body.intersect(box(-big, 0, -big, big, -big, big)), body.intersect(box(0, big, -big, big, -big, big))];
}

export function volume(s: Solid): number {
  try {
    return measureVolume(s);
  } catch {
    return 0;
  }
}

/** Shapes are consumed by translate/rotate in replicad; use these to move a copy and keep the original. */
export const moved = (s: Solid, x: number, y: number, z: number): Solid => s.clone().translate(x, y, z) as Solid;
export const turnedX = (s: Solid, deg: number): Solid => s.clone().rotate(deg, [0, 0, 0], [1, 0, 0]) as Solid;

/** Box with its four vertical edges rounded to radius r. */
export function rrectPrism(x0: number, x1: number, y0: number, y1: number, z0: number, z1: number, r: number): Solid {
  return (drawRoundedRectangle(x1 - x0, y1 - y0, r).sketchOnPlane("XY", z0) as any).extrude(z1 - z0).translate((x0 + x1) / 2, (y0 + y1) / 2, 0) as Solid;
}

/** Round the chain of edges that runs on smoothly from the one edge chosen by seedPick, with the radius at each
 *  corner point given by radAt(x, y, z). A big radius can then blend into a small one round a corner without the
 *  crease two separate fillets leave. seedPick gets each edge's midpoint. */
export function blendedFillet(
  body: Solid,
  seedPick: (mid: [number, number, number]) => boolean,
  radAt: (x: number, y: number, z: number) => number,
): Solid {
  const oc: any = getOC();
  const seeds = body.edges.filter((e) => {
    const c = e.pointAt(0.5);
    return seedPick([c.x, c.y, c.z]);
  });
  if (seeds.length !== 1) throw new Error(`blendedFillet: seedPick must choose exactly one edge, it chose ${seeds.length}`);
  const mk = new oc.BRepFilletAPI_MakeFillet(body.wrapped, oc.ChFi3d_FilletShape.ChFi3d_Rational);
  mk.Add(1.0, seeds[0].wrapped);
  const n = mk.NbEdges(1);
  for (let i = 1; i <= n; i++) {
    const edge = mk.Edge(1, i);
    for (const v of iterTopo(edge, "vertex")) {
      const p = oc.BRep_Tool.Pnt(v);
      mk.SetRadius(radAt(p.X(), p.Y(), p.Z()), 1, v);
    }
  }
  mk.Build(new oc.Message_ProgressRange());
  if (!mk.IsDone()) throw new Error("blendedFillet: the fillet could not be built with these radii");
  return cast(mk.Shape()) as Solid;
}

View this module on GitHub