Miscellaneous¶
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 Path2D / 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.
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.
- Parameters:¶
- profile : object¶
The cross-section to sweep or extrude.
- pt1 : Sequence[float]¶
The first point.
- pt2 : Sequence[float]¶
The second point.
- twist : float¶
Total twist in degrees.
- scale : float¶
Scale applied along the extrusion.
- slices : int | None¶
How many intermediate sections to insert.
- convexity : int¶
Convexity hint for the renderer.
- Return type:¶
Bosl2Solid
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).
- Parameters:¶
- profile : object¶
The 2-D shape to wrap around the cylinder.
- inner_radius : float | None¶
Radius the wrapped profile starts at.
- outer_radius : float | None¶
Radius the wrapped profile reaches.
- outer_diameter : float | None¶
Outer diameter, instead of outer_radius.
- inner_diameter : float | None¶
Inner diameter, instead of inner_radius.
- size : float | Sequence[float] | None¶
Size of the flat region the profile is drawn in before wrapping.
- spin : float¶
Z-axis rotation in degrees after anchor.
- orient : Anchor | Sequence[float]¶
Direction to rotate the top towards, after spin.
- convexity : int¶
Convexity hint for the renderer; higher for more self-overlapping profiles.
- fn : int | None¶
Fixed fragment count for curved surfaces. Omitted, the ambient
use_defaults(fn=...)value applies;fn=0opts back out to fa/fs.- fa : float | None¶
Minimum fragment angle in degrees. Omitted, the ambient
use_defaults(fa=...)value applies.- fs : float | None¶
Minimum fragment size in millimetres. Omitted, the ambient
use_defaults(fs=...)value applies.
- Return type:¶
Bosl2Solid
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.
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.
- 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.
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.
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=