Geometry, fits and math
These helpers are optional. Existing CadQuery builders can continue using CadQuery directly. Lengths are millimetres, angles are degrees unless an external API explicitly says otherwise.
Reusable native shapes
annulus
Build a native ring from Z=0 along positive Z.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outer_diameter
|
float
|
Outer diameter in millimetres. |
required |
inner_diameter
|
float
|
Inner diameter in millimetres. |
required |
height
|
float
|
Ring height in millimetres. |
required |
Returns:
| Type | Description |
|---|---|
Workplane
|
Native annular prism centred on the origin in XY. |
rounded_rect_prism
Build an XY rounded rectangle extruded from Z=0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
float
|
Overall X extent in millimetres. |
required |
width
|
float
|
Overall Y extent in millimetres. |
required |
height
|
float
|
Z height in millimetres. |
required |
radius
|
float
|
Corner radius, at most half the smaller XY extent. |
required |
centered
|
bool
|
Centre XY at the origin; if false, use positive XY extents. |
True
|
Returns:
| Type | Description |
|---|---|
Workplane
|
Native rounded rectangular prism. |
capsule
Build a rounded slot-shaped prism from two semicircular ends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
tuple
|
XY centre in millimetres. |
(0, 0)
|
diameter
|
float
|
Width in millimetres. |
5
|
travel
|
float
|
Distance between end-circle centres in millimetres.
Overall length is |
10
|
angle
|
float
|
Long-axis angle in degrees from +X toward +Y. |
0
|
height
|
float
|
Extrusion from Z=0 along +Z, in millimetres. |
10
|
Returns:
| Type | Description |
|---|---|
Shape
|
Native capsule prism. |
polar_points
Return XY points on a circle, preserving the supplied angle order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius in millimetres. |
required |
angles
|
tuple
|
Angles in degrees from +X toward +Y. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple]
|
XY pairs in millimetres. |
normalized_to_bed
Translate geometry vertically so its lowest point touches Z=0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
object
|
Native Shape, Workplane, or Mesh. |
required |
Returns:
| Type | Description |
|---|---|
Shape | Mesh
|
Translated geometry; X/Y placement and rotation are preserved. |
Explicit fit allowances
Allowance changes a diameter, not a radius. A nominal fit in the model is not calibration of a printer, material or machining process.
Bore
dataclass
A nominal circular interface with an explicit diametral print allowance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nominal_diameter
|
float
|
Mating diameter in millimetres. |
required |
diametral_allowance
|
float
|
Added to diameter, not radius, in millimetres. Negative values make a smaller bore; final diameter must be positive. |
0.2
|
Countersink
dataclass
A standalone conical cutter described by its throat, head, and full angle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
through_diameter
|
float
|
Throat diameter in millimetres. |
required |
head_diameter
|
float
|
Head diameter in millimetres, greater than the throat. |
required |
included_angle
|
float
|
Full cone angle in degrees, strictly between 0 and 180. |
90
|
cutter
Return a cone with its nominal mouth at an explicit world Z plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_z
|
float
|
Nominal mouth plane in millimetres. |
required |
at
|
tuple
|
XY position of the cone axis in millimetres. |
(0, 0)
|
overlap
|
float
|
Extra cone height in millimetres to clear the entry face. |
0.05
|
Returns:
| Type | Description |
|---|---|
Shape
|
Native conical cutter. This cutter does not include the throat hole. |
fit_coupon
Build an ordered ladder of bores for testing real manufactured fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nominal_diameter
|
float
|
Nominal mating diameter in millimetres. |
required |
allowances
|
tuple
|
Nonempty sequence of diametral allowances in millimetres. |
(-0.1, 0, 0.1, 0.2, 0.3)
|
height
|
float
|
Positive block thickness in millimetres. |
6
|
wall
|
float
|
Positive surrounding wall allowance in millimetres. |
3
|
Returns:
| Type | Description |
|---|---|
Shape
|
Native block at positive XYZ with bores ordered along +X. |
Record the position-to-allowance mapping in the Part's notes; geometry has no engraved labels. Print using the intended material and process settings.
Native and mesh boundaries
shape
Unwrap a Workplane's first value; preserve Shapes, Meshes, and None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
CadQuery Workplane, native Shape, Mesh, or empty sentinel. |
required |
Returns:
| Type | Description |
|---|---|
object
|
|
This does not combine a Workplane stack. Return an explicit compound from builders that intentionally contain multiple solids.
Mesh
An explicit Manifold triangle-mesh boundary in an otherwise native CAD model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifold
|
Manifold
|
Valid Manifold solid. |
required |
Obtain one using import_mesh or mesh. Meshes can be shown, measured
approximately, transformed, and exported as STL. They do not become analytic
STEP solids. Translation and rotation return new Mesh wrappers.
mesh
Convert native geometry to the explicit Manifold mesh representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
object
|
Native Shape, Workplane, Mesh, or |
required |
Returns:
| Type | Description |
|---|---|
Mesh
|
Existing Mesh unchanged or newly tessellated geometry. Native tessellation uses 0.025 mm linear and 0.08 rad angular tolerance. |
import_mesh
Load an existing mesh file into a validated Manifold representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Mesh file recognized by trimesh. |
required |
Returns:
| Type | Description |
|---|---|
Mesh
|
Explicit mesh geometry in the file's numerical units; no rescaling. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The file does not exist. |
ValueError
|
Manifold rejects the imported geometry. |
Booleans and transforms
These functional helpers accept lists of geometry and combine them before transforming. Booleans involving a Mesh become meshes. Native solids remain native otherwise; a spatial convex hull is another explicit mesh boundary.
union
Fuse all nonempty inputs, retaining the native/mesh boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list
|
Shapes, Workplanes, Meshes, or |
required |
Returns:
| Type | Description |
|---|---|
Shape | Mesh | None
|
Native result when all inputs are native;
mesh result when any is a Mesh. Empty input yields |
Planar native faces use planar booleans. union ignores None values;
difference is empty if its first value is None; intersection is
empty if any value is None.
difference
Subtract subsequent inputs from the first, retaining the native/mesh boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list
|
Shapes, Workplanes, Meshes, or |
required |
Returns:
| Type | Description |
|---|---|
Shape | Mesh | None
|
Native result when all inputs are native;
mesh result when any is a Mesh. Empty input yields |
Planar native faces use planar booleans. union ignores None values;
difference is empty if its first value is None; intersection is
empty if any value is None.
intersection
Intersect all inputs, retaining the native/mesh boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list
|
Shapes, Workplanes, Meshes, or |
required |
Returns:
| Type | Description |
|---|---|
Shape | Mesh | None
|
Native result when all inputs are native;
mesh result when any is a Mesh. Empty input yields |
Planar native faces use planar booleans. union ignores None values;
difference is empty if its first value is None; intersection is
empty if any value is None.
translate
Union inputs and translate them in millimetres.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list
|
Input geometry. |
required |
v
|
tuple
|
XY or XYZ displacement; omitted trailing coordinates are zero. |
required |
Returns:
| Type | Description |
|---|---|
Shape | Mesh | None
|
Transformed geometry, or |
rotate
Union inputs and rotate about the origin using degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list
|
Input geometry. |
required |
a
|
float | tuple
|
One angle about |
required |
v
|
tuple | None
|
Axis for a scalar angle; defaults to positive Z. |
None
|
Returns:
| Type | Description |
|---|---|
Shape | Mesh | None
|
Rotated geometry. |
mirror
Union inputs and reflect about a plane through the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list
|
Input geometry. |
required |
v
|
tuple
|
Plane normal. |
required |
Returns:
| Type | Description |
|---|---|
Shape | Mesh | None
|
Reflected geometry. |
scale
Union inputs and scale about the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list
|
Nonempty input geometry. |
required |
v
|
float | tuple
|
Uniform factor or XYZ factors. |
required |
Returns:
| Type | Description |
|---|---|
Shape | Mesh
|
Scaled geometry. Nonuniform native scaling uses a general geometry transform rather than a rigid placement. |
Lower-level primitives
The functional primitives return native faces or shapes, except where their
description states a mesh boundary. facets is not a general tessellation
control: circles and spheres ignore it; cylinders use it only for polygonal
prisms with at most twelve sides.
circle
Return a native XY disk centred at the origin. Supply radius r or diameter d in millimetres; d wins. facets is accepted but unused.
square
Return a native XY rectangle. size is one length or an (x, y) pair in millimetres; center=False uses positive XY.
cube
Return a native box. size is one length or XYZ lengths in millimetres; center=False uses positive XYZ.
cylinder
Return a native +Z cylinder or cone of height h in millimetres. Use r/d, or r1/d1 and r2/d2 for bottom/top. center=True centres Z. facets <= 12 selects a polygonal prism; larger values retain analytic round geometry.
sphere
Return an analytic sphere centred at the origin. Supply r or d in millimetres; d wins. facets is accepted but unused.
linear_extrude
Union planar inputs and extrude their faces along +Z by height millimetres. center=True centres Z. Extra keyword arguments are accepted but unused; twist and taper are not implemented.
rotate_extrude
Revolve an XY profile about world Z after mapping its Y axis to Z. angle is in degrees; facets is accepted but unused.
offset
Offset planar regions by r with arc joins or delta with intersection joins, in millimetres. Positive offsets expand outer boundaries and shrink holes.
hull
Return a convex hull. Circles use native tangent geometry; other planar curves are sampled. Spatial hulls cross to the Mesh representation.
projection
Project tessellated input onto XY, or section at Z=0 with cut=True. Returns planar faces reconstructed from Manifold contours; this is not an analytic projection.
Degree-based arithmetic
cadkit.math also re-exports Python's pi, sqrt, floor, and ceil.
vec arithmetic is elementwise; multiplication is not a dot or cross product.
vec
Bases: tuple
Immutable coordinate vector with elementwise arithmetic and stable cache keys.
atan2
Return the signed angle of (x, y) in degrees using the standard two-argument arctangent.
require
Raise ValueError with the supplied message when a design constraint is false.
inclusive_range
Return a tuple including the end when reached by the step. Use (start, stop) for step 1 or (start, step, stop) for an explicit nonzero step. Supports fractional and descending steps.