Miscellaneous: extrusions, bbox, hull & minkowski

Pure-Python port of BOSL2’s miscellaneous.scad – the extrusions (extrude_from_to, path_extrude2d, path_extrude, cylindrical_extrude), the bounding box, chain_hull, and the minkowski-based transforms (minkowski_difference, offset3d, round3d).

The two path extrusions are methods on Path / Path3D, and – unlike BOSL2, which extrudes its children – they take the 2-D cross-section as a profile argument:

Path([[0, 0], [40, 0], [40, 40]]).path_extrude2d(s2.square([4, 8], center=True))
Path3D([[0, 0, 0], [30, 0, 10], [30, 30, 20]]).path_extrude(s2.circle(radius=4))

The profile can be a native 2-D shape, a Path, a Region, a Bosl2Solid wrapping 2-D geometry, or a zero-argument factory that returns fresh geometry each call – the “children” form. Use a factory when the profile is a frep/SDF solid, so each placement gets its own handle (avoiding the frep handle-reuse segfault); a plain object is meshed once and reused, which is fine for native CSG.

Coverage of BOSL2 miscellaneous.scad

BOSL2 module

Status

Notes

extrude_from_to

ported

extrude_from_to() – linear extrude of a profile between two 3-D points, with twist / scale / slices.

path_extrude2d

ported

path_extrude2d() – a moulding along a 2-D path, with revolved corner fillets, closed loops and rounded caps.

path_extrude

ported

path_extrude() – extrude a profile along a 2-D/3-D path (mitre-clipped segments). path_sweep() is faster for a single polygon.

cylindrical_extrude

ported

cylindrical_extrude() – wrap a 2-D profile around a cylinder.

bounding_box

ported

bounding_box() – uses the native bbox (exact and fast; BOSL2’s projection/minkowski trick isn’t needed). planar is not ported (the host is always a 3-D solid).

chain_hull

ported

chain_hull() and the chain_hull() method.

minkowski_difference

ported

minkowski_difference() and the method form.

offset3d / round3d

ported

offset3d() / round3d() – minkowski-based; very slow, as in BOSL2.

Examples

A moulding that follows an L-shaped path:

route = Path([[0, 0], [40, 0], [40, 40]], closed=False)
route.path_extrude2d(s2.square([4, 8], center=True)).show()

⬇ Download STL mesh

A profile swept along a rising 3-D path:

route = Path3D([[0, 0, 0], [30, 0, 10], [30, 30, 20], [0, 30, 30]], closed=False)
route.path_extrude(s2.circle(radius=4, _fn=16)).show()
_images/a3d8594a7354130b.png

A twisting, tapering column between two points:

extrude_from_to(s2.square([8, 4], center=True), [0, 0, 0], [8, 12, 30], twist=180, scale=2).show()

⬇ Download STL mesh

API reference

bosl2.miscellaneous.extrude_from_to(profile, pt1, pt2, twist=0, scale=1, slices=None, convexity=10)[source]

Linearly extrude a 2-D profile between two 3-D points (BOSL2 extrude_from_to()).

The profile’s origin is placed on pt1 and pt2, oriented perpendicular to the line between them. profile is a native 2-D shape, a Path/Region, a Bosl2Solid, or a factory.

Examples

A twisted, tapering column between two points:

extrude_from_to(s2.circle(radius=4), [0, 0, 0], [10, 20, 30], twist=180, scale=2).show()

⬇ Download STL mesh

Parameters:
  • twist (float)

  • scale (float)

  • slices (int | None)

  • convexity (int)

Return type:

Bosl2Solid

bosl2.miscellaneous.cylindrical_extrude(profile, inner_radius=None, outer_radius=None, outer_diameter=None, inner_diameter=None, size=None, spin=0, orient=[0, 0, 1], convexity=10, fn=None, fa=None, fs=None)[source]

Wrap a 2-D profile around a cylinder, from radius inner_radius out to outer_radius (BOSL2 cylindrical_extrude()).

Chops the profile into vertical facets and extrudes each radially. Handy for embossing text onto a curved wall. The profile’s X spans one revolution by default (override with size).

Parameters:
  • inner_radius (float | None)

  • outer_radius (float | None)

  • outer_diameter (float | None)

  • inner_diameter (float | None)

  • spin (float)

  • convexity (int)

  • fn (int | None)

  • fa (float | None)

  • fs (float | None)

Return type:

Bosl2Solid

bosl2.miscellaneous.chain_hull(*objects)[source]

Union the hulls of each consecutive pair of objects (BOSL2 chain_hull()).

bosl2.miscellaneous.minkowski_difference(base, *diffs, size=1000, convexity=10)[source]

Carve diffs out of the surface of base (BOSL2 minkowski_difference()).

Parameters:
  • size (float)

  • convexity (int)

class bosl2.miscellaneous.Extrudable[source]

Bases: object

Mixin adding path_extrude / path_extrude2d as methods on Path and Path3D. Both take the 2-D cross-section as a profile argument instead of OpenSCAD children (a native 2-D shape, a Path/Region, a Bosl2Solid, or a factory).

path_extrude2d(profile, caps=False, closed=None, s=None, convexity=10)[source]

Extrude a 2-D profile along this 2-D path, standing it vertically (BOSL2 path_extrude2d()).

Builds a straight run for each segment and a revolved fillet at each corner, unioned into a 3-D “moulding” that follows the path. caps rounds the two open ends (the profile must be symmetric across the Y axis); closed joins the ends into a loop; s is the internal mask size (defaults to the path’s bounding-box diagonal).

Parameters:
  • caps (bool)

  • closed (bool | None)

  • convexity (int)

path_extrude(profile, convexity=10, clipsize=100)[source]

Extrude a 2-D profile along this path in 3-D (BOSL2 path_extrude()).

Places an oriented linear extrusion for each segment and clips it at the mitre planes between segments. A 2-D Path is lifted to the z=0 plane first. For most sweeps path_sweep() is faster and cleaner; this exists for extruding an arbitrary native 2-D object (text, multi-part shapes) that is not a single polygon.

Parameters:
  • convexity (int)

  • clipsize (float)

class bosl2.miscellaneous.Miscellaneous[source]

Bases: ABC

Mixin adding bounding_box / offset3d / round3d / chain_hull / minkowski_difference as methods on Bosl2Solid.

bounding_box(excess=0)[source]

The smallest axis-aligned cuboid containing this solid, grown by excess (BOSL2 bounding_box()).

Uses the native bounding box, so it is exact and fast (BOSL2’s projection/minkowski trick is not needed here).

Parameters:

excess (float)

offset3d(radius, size=1000, convexity=10)[source]

Expand (or, for negative radius, contract) the surface of this solid by radius (BOSL2 offset3d()).

Uses minkowski() with a sphere and is very slow; use sparingly.

Parameters:
  • radius (float)

  • size (float)

  • convexity (int)

round3d(radius=None, outer_radius=None, inner_radius=None, size=1000)[source]

Round the corners of this solid (BOSL2 round3d()): radius rounds all, outer_radius only convex, inner_radius only concave. Uses offset3d three times and is extremely slow.

Parameters:
  • radius (float | None)

  • outer_radius (float | None)

  • inner_radius (float | None)

  • size (float)

chain_hull(*others)[source]

This solid chain-hulled with others, in order (see chain_hull()).

minkowski_difference(*diffs, size=1000)[source]

Carve diffs out of this solid’s surface (see minkowski_difference()).

Parameters:

size (float)