Distributors: copiers & reflected copies¶
Pure-Python port of BOSL2’s distributors.scad – the “copiers” that duplicate a shape into a
line, grid, ring, arc, sphere, or path pattern, plus the reflected-copy helpers. Each copier is a
module-level function returning a list of 4x4 transformation matrices (BOSL2’s function form), and
a matching method on every geometry object via the distributors
mixin.
What a copier returns depends on the object it is called on:
shapes3d– the union of the transformed geometry copies (a new solid), matching BOSL2’s module form:cuboid([10, 10, 10]).grid_copies(num_copies=[3, 3], spacing=30) # 9 cubes, unioned cuboid([6, 6, 6]).zrot_copies(rots=6, radius=30) # a ring of 6 cubes part.right(20).xflip_copy() # part + its mirror imagepaths/path3d– a plainlistof the transformed path copies (BOSL2’s function form). A 2-DPathonly supports the in-plane copiers; one that would lift it out of the XY plane (zcopies,xrot_copies,sphere_copies, …) raises, directing you toPath3D.
Every copier’s matrices are pinned to the real BOSL2 output in tests/test_pybosl2_reorient.py.
Coverage of BOSL2 distributors.scad¶
BOSL2 function |
Status |
Notes |
|---|---|---|
|
ported |
|
|
ported |
spacing/ |
|
ported |
|
|
ported |
square and staggered (hex) grids, |
|
ported |
rotated copies about any axis, with |
|
ported |
rings about the X/Y/Z axes ( |
|
ported |
along a circular or elliptical arc in the XY plane ( |
|
ported |
golden-spiral spread over a sphere/ellipsoid ( |
|
ported |
|
|
ported |
the original plus one reflected copy. |
|
ported |
|
|
not ported |
OpenSCAD special variables for per-copy customization have no Python equivalent; build the
variants yourself and use |
Examples¶
A grid of rounded pillars, unioned into one solid:
from functools import reduce
from pybosl2 import shapes3d as s3
reduce(lambda a, b: a | b, s3.cyl(height=12, radius=4, rounding=1).grid_copies(num_copies=[4, 3], spacing=14)).show()
A ring of wedges facing the centre:
from functools import reduce
from pybosl2 import shapes3d as s3
reduce(lambda a, b: a | b, s3.prismoid([6, 10], [2, 10], height=12).zrot_copies(rots=8, radius=24)).show()
Copies of a 2-D outline along an arc, extruded together:
from functools import reduce
from pybosl2 import Path2D
tile = Path2D([[-3, -3], [3, -3], [3, 3], [-3, 3]])
reduce(lambda a, b: a | b, (c.polygon() for c in tile.arc_copies(radius=30, ea=180, num_copies=10))) \
.linear_extrude(height=3).show()
API reference¶
Return Distributors: line/grid/ring/arc/sphere/path copiers and reflected copies.
-
pybosl2.distributors.xdistribute(children, spacing=
None, sizes=None, length=None)[source]¶ Distribute distinct children along the X axis.
Examples
from pybosl2.solid import cuboid from pybosl2.distributors import xdistribute xdistribute(spacing=15, children=[cuboid([5, 5, 20]) for _ in range(5)]).show()Loading 3-D preview…
-
pybosl2.distributors.ydistribute(children, spacing=
None, sizes=None, length=None)[source]¶ Distribute distinct children along the Y axis.
-
pybosl2.distributors.zdistribute(children, spacing=
None, sizes=None, length=None)[source]¶ Distribute distinct children along the Z axis.
- class pybosl2.distributors.DistributableMatrix[source]¶
Bases:
objectReturn Matrix-generating copiers – each returns
list[np.ndarray](4x4 matrices).-
static line_copies(spacing=
None, length=None, p1=None, p2=None, num_copies=None)¶ Return translation matrices evenly spread along a line.
-
static xcopies(spacing=
None, length=None, start_pos=None, num_copies=None)¶ Return copies spread along the X axis.
-
static ycopies(spacing=
None, length=None, start_pos=None, num_copies=None)¶ Return copies spread along the Y axis.
-
static zcopies(spacing=
None, length=None, start_pos=None, num_copies=None)¶ Return copies spread along the Z axis.
-
static grid_copies(spacing=
None, size=None, stagger=False, inside=None, nonzero=None, axes='xy', num_copies=None)¶ Return copies laid out in a square or staggered (hex) grid.
-
static rot_copies(rots=
None, v=None, center=(0, 0, 0), sa=0, offset=0, delta=(0, 0, 0), subrot=True, num_copies=None)¶ Return rotated copies about an axis, optionally offset into a ring.
-
static xrot_copies(rots=
None, center=(0, 0, 0), sa=0, radius=None, diameter=None, subrot=True, num_copies=None)¶ Return rotated copies around the X axis, optionally into a ring of radius radius.
-
static yrot_copies(rots=
None, center=(0, 0, 0), sa=0, radius=None, diameter=None, subrot=True, num_copies=None)¶ Return rotated copies around the Y axis, optionally into a ring of radius radius.
-
static zrot_copies(rots=
None, center=(0, 0, 0), sa=0, radius=None, diameter=None, subrot=True, num_copies=None)¶ Return rotated copies around the Z axis, optionally into a ring of radius radius.
-
static arc_copies(radius=
None, radius_x=None, radius_y=None, diameter=None, diameter_x=None, diameter_y=None, sa=0, ea=360, rot=True, num_copies=6)¶ Return copies spread along an (elliptical) arc in the XY plane.
-
static sphere_copies(num_copies=
100, radius=None, diameter=None, cone_ang=90, scale=(1, 1, 1), perp=True)¶ Return copies spread over a sphere/ellipsoid by the golden-spiral method.
-
static path_copies(path, spacing=
None, start_pos=None, dist=None, rotate_children=True, closed=None, num_copies=None)¶ Return copies placed along path, oriented to it.
-
static mirror_copy(v=
(0, 0, 1), offset=0, center=None)¶ Return the original plus a mirrored copy across the plane with normal v.
-
static line_copies(spacing=
- class pybosl2.distributors.Distributable[source]¶
Bases:
ABCReturn Mixin adding the distributors.scad copiers as methods.
Inherited by
Bosl2Solid,Path2D, andPath3D. Each copier returns alistof positioned copies; callers union, hull, or combine them as needed.-
line_copies(spacing=
None, length=None, p1=None, p2=None, num_copies=None)[source]¶ Return copies spread along a line.
-
xcopies(spacing=
None, length=None, start_pos=None, num_copies=None)[source]¶ Return copies spread along the X axis.
-
ycopies(spacing=
None, length=None, start_pos=None, num_copies=None)[source]¶ Return copies spread along the Y axis.
-
zcopies(spacing=
None, length=None, start_pos=None, num_copies=None)[source]¶ Return copies spread along the Z axis.
-
grid_copies(spacing=
None, size=None, stagger=False, inside=None, nonzero=None, axes='xy', num_copies=None)[source]¶ Return copies in a square or staggered (hex) grid.
-
rot_copies(rots=
None, v=None, center=(0, 0, 0), sa=0, offset=0, delta=(0, 0, 0), subrot=True, num_copies=None)[source]¶ Rotated copies about an axis (optionally into a ring via delta).
-
xrot_copies(rots=
None, center=(0, 0, 0), sa=0, radius=None, diameter=None, subrot=True, num_copies=None)[source]¶ Rotated copies around the X axis.
-
yrot_copies(rots=
None, center=(0, 0, 0), sa=0, radius=None, diameter=None, subrot=True, num_copies=None)[source]¶ Rotated copies around the Y axis.
-
zrot_copies(rots=
None, center=(0, 0, 0), sa=0, radius=None, diameter=None, subrot=True, num_copies=None)[source]¶ Rotated copies around the Z axis.
-
arc_copies(radius=
None, radius_x=None, radius_y=None, diameter=None, diameter_x=None, diameter_y=None, sa=0, ea=360, rot=True, num_copies=6)[source]¶ Return copies spread along an (elliptical) arc in the XY plane.
-
sphere_copies(num_copies=
100, radius=None, diameter=None, cone_ang=90, scale=(1, 1, 1), perp=True)[source]¶ Return copies spread over a sphere/ellipsoid surface.
-
path_copies(path, spacing=
None, start_pos=None, dist=None, rotate_children=True, closed=None, num_copies=None)[source]¶ Return copies placed along path, oriented to it.
-
mirror_copy(v=
(0, 0, 1), offset=0, center=None)[source]¶ Return this object plus a copy mirrored across the plane with normal v.
-
static distribute(children, spacing=
None, sizes=None, dir=Anchor.RIGHT, length=None)[source]¶ Space a list of distinct objects along dir so they don’t overlap.
Unlike the copiers, this lays out several different children. sizes gives each child’s extent along dir; auto-computed from bounding boxes if omitted.
-
line_copies(spacing=