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 paths / 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 paths, a regions, a shapes3d 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

miscellaneous() – 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). shapes3d() is faster for a single polygon.

cylindrical_extrude

ported

miscellaneous() – 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

miscellaneous() and the miscellaneous() method.

minkowski_difference

ported

miscellaneous() 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:

from pybosl2 import Path, shapes2d as s2

route = Path([[0, 0], [40, 0], [40, 40]], closed=False)
route.path_extrude2d(s2.square([4, 8], center=True)).show()
Loading 3-D preview…

⬇ Download STL mesh

A profile swept along a rising 3-D path:

from pybosl2 import Path3D, shapes2d as s2

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()
Loading 3-D preview…

⬇ Download STL mesh

A twisting, tapering column between two points:

from pybosl2 import extrude_from_to, shapes2d as s2

extrude_from_to(s2.square([8, 4], center=True), [0, 0, 0], [8, 12, 30], twist=180, scale=2).show()
Loading 3-D preview…

⬇ Download STL mesh

API reference

Extrusions, bounding box, chain hull, and minkowski-based transforms.

pybosl2.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 Path2D/Region, a Bosl2Solid, or a factory.

Examples

A twisted, tapering column between two points:

from pybosl2 import shapes2d as s2, extrude_from_to

extrude_from_to(s2.circle(radius=4), [0, 0, 0], [10, 20, 30], twist=180, scale=2).show()
Loading 3-D preview…

⬇ Download STL mesh

Parameters:
profile : object

pt1 : Sequence[float]

pt2 : Sequence[float]

twist : float

scale : float

slices : int | None

convexity : int

Return type:

Bosl2Solid

pybosl2.miscellaneous.cylindrical_extrude(profile, inner_radius=None, outer_radius=None, outer_diameter=None, inner_diameter=None, size=None, spin=0, orient=Anchor.TOP, 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).

Examples

from pybosl2 import shapes2d as s2, cylindrical_extrude

cylindrical_extrude(s2.circle(radius=8), inner_radius=25, outer_radius=30).show()
Loading 3-D preview…

⬇ Download STL mesh

Parameters:
profile : object

inner_radius : float | None

outer_radius : float | None

outer_diameter : float | None

inner_diameter : float | None

size : float | Sequence[float] | None

spin : float

orient : Anchor | Sequence[float]

convexity : int

fn : int | None

fa : float | None

fs : float | None

Return type:

Bosl2Solid

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

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

Examples

from pybosl2.solid import sphere
from pybosl2 import chain_hull

chain_hull([sphere(radius=5).translate([x * 20, 0, 0]) for x in range(4)]).show()
Loading 3-D preview…

⬇ Download STL mesh

Parameters:
objects : object

Return type:

Bosl2Solid

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

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

Parameters:
base : object

diffs : object

size : float

convexity : int

Return type:

Bosl2Solid

class pybosl2.miscellaneous.Extrudable[source]

Bases: object

Mixin adding path_extrude / path_extrude2d as methods on Path2D and.

Path3D. Both take the 2-D cross-section as a profile argument instead of OpenSCAD children (a native 2-D shape, a Path2D/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:
profile : object

caps : bool

closed : bool | None

s : float | None

convexity : int

Return type:

Bosl2Solid

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 Path2D 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:
profile : object

convexity : int

clipsize : float

Return type:

Bosl2Solid

class pybosl2.miscellaneous.Miscellaneous[source]

Bases: ABC

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

on Bosl2Solid.

bounding_box(excess=0)[source]

Return 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

Return type:

Bosl2Solid

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

Return type:

Bosl2Solid

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

Return type:

Bosl2Solid

chain_hull(*others)[source]

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

Parameters:
others : object

Return type:

Bosl2Solid

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

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

Parameters:
diffs : object

size : float

Return type:

Bosl2Solid