Skip to main content

Subtract

Subtract carves one solid out of another. The base is the solid you keep; the tool is the solid whose volume is taken away. Whatever the tool occupied becomes a hollow in the base, and the tool itself is gone.

That makes it the operation for cavities shaped by a real body: a mould around a part, a clearance pocket the size of the component that has to fit in it, a channel cut by a swept or lofted shape.

In the viewport

  1. Click Boolean on the toolbar and choose the Subtract tab.
  2. Click the solid you want to keep — it fills the Base slot, and the Tool slot arms itself next.
  3. Click the solid to remove. It fills Tool.
  4. Click Apply.
The Boolean dialog on the Subtract tab with a base and a tool picked
  1. 1
    Subtract tab
    Swapping to this tab turns the single Solids slot into the two slots below. The first two solids you had picked become the base and the tool; any extras are dropped, since a subtract takes exactly two.
  2. 2
    Base
    The solid that survives — one solid only. While this slot is armed, picking a different solid replaces what is in it.
  3. 3
    Tool
    The solid that is taken away, also one only. Click a slot to arm it (blue border) before re-picking; a chip’s ✕ empties the slot, and so does clicking the solid that is already in it.
  4. 4
    Apply
    Writes subtract(base, tool). Both slots must be filled first; Exit closes the dialog without writing anything.

Getting the two the wrong way round is the usual mistake, and it is easy to spot: you end up with the tool full of a base-shaped hole. Click Base to re-arm it and pick again.

The same two cubes, with the second one taken out of the first:

BeforeBefore modetwo solids

Cube A is the base, cube B the tool. They share a 30 × 30 × 60 corner.

AfterAfter modesubtract(a, b)

Cube A with that corner taken out of it. Cube B is used up doing the cutting and is no longer in the Shapes panel.

The code behind it

The notch is exactly the corner the two cubes shared — nothing more is removed than the tool actually occupied.

cubes.part.js
import { sketch, line, extrude, subtract } from 'fluidcad/core';
import { coincident, distance, fix, horizontal, vertical } from 'fluidcad/constraints';

// Cube A. The four lines and the constraints that hold them square are what
// the Rectangle tool writes; `fix` pins one corner, the two `distance`s size
// the square.
sketch("xy", () => {
const bottom = line([-30, -30], [30, -30]);
const right = line([30, -30], [30, 30]);
const top = line([30, 30], [-30, 30]);
const left = line([-30, 30], [-30, -30]);
coincident(bottom.end(), right.start());
coincident(right.end(), top.start());
coincident(top.end(), left.start());
coincident(left.end(), bottom.start());
horizontal(bottom);
vertical(right);
horizontal(top);
vertical(left);
fix(bottom.start(), [-30, -30]);
distance(bottom.start(), bottom.end(), 60);
distance(right.start(), right.end(), 60);
});
const a = extrude(60);

// Cube B. The same square, shifted 30 mm along X and Y, so the two cubes
// share a 30 x 30 x 60 corner.
sketch("xy", () => {
const bottom = line([0, 0], [60, 0]);
const right = line([60, 0], [60, 60]);
const top = line([60, 60], [0, 60]);
const left = line([0, 60], [0, 0]);
coincident(bottom.end(), right.start());
coincident(right.end(), top.start());
coincident(top.end(), left.start());
coincident(left.end(), bottom.start());
horizontal(bottom);
vertical(right);
horizontal(top);
vertical(left);
fix(bottom.start(), [0, 0]);
distance(bottom.start(), bottom.end(), 60);
distance(right.start(), right.end(), 60);
});
const b = extrude(60).new();

subtract(a, b);
// Cube A survives with a 30 x 30 x 60 notch where cube B passed through it.
// Swap the arguments and you keep cube B with the notch instead.

Code forms

import { subtract } from 'fluidcad/core';

subtract(base, tool) // keep base, remove tool's volume

Both arguments are required, and swapping them gives a different solid. The faces the cut leaves behind are the tool's surfaces where they ran through the base:

const s = subtract(box, cyl)
s.internalFaces() // the cavity walls
s.internalEdges()

Subtract or cut?

If you can draw the shape you want to remove, sketch it and use the extrude dialog's Remove tab instead — that writes cut(), which stays tied to its sketch, so changing the sketch changes the pocket. It is the right tool for holes, slots and pockets.

subtract() is for removing a body that already exists as a solid: a STEP import, a revolve, a loft, the result of another feature.

And inside a sketch you need neither. A closed profile drawn inside another closed profile becomes a hole as soon as the sketch is extruded.