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 |
|---|---|---|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
|
ported |
|
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()
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()
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()
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…
-
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…
- 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…
-
pybosl2.miscellaneous.minkowski_difference(base, *diffs, size=
1000, convexity=10)[source]¶ Carve diffs out of the surface of base (BOSL2 minkowski_difference()).
- class pybosl2.miscellaneous.Extrudable[source]¶
Bases:
objectMixin adding path_extrude / path_extrude2d as methods on
Path2Dand.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).
-
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=0plane first. For most sweepspath_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.
-
path_extrude2d(profile, caps=
- class pybosl2.miscellaneous.Miscellaneous[source]¶
Bases:
ABCMixin 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).
-
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.
-
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
offset3dthree times and is extremely slow.
- chain_hull(*others)[source]¶
Return this solid chain-hulled with others, in order (see
chain_hull()).
-
bounding_box(excess=