Transforms (affine / reorient)¶
- bosl2.transforms.polar_to_xy(radius, angle)[source]¶
Convert polar coordinates (radius, angle in degrees) to a 2-D [x, y] point.
- Parameters:
radius (float)
angle (float)
- Return type:
list[float]
- bosl2.transforms.rot_from_to(a, b)[source]¶
(angle_degrees, axis) rotating direction a onto direction b.
Matches BOSL2’s
rot(from=, to=)axis choice, including the antiparallel case (180 degrees about a perpendicular axis).- Return type:
tuple[float, ndarray]
- bosl2.transforms.axis_angle_matrix(angle, axis)[source]¶
3x3 rotation matrix for angle degrees about axis (Rodrigues’ rotation formula).
- Parameters:
angle (float)
- Return type:
- bosl2.transforms.rot_about_axis(angle, axis, center=(0.0, 0.0, 0.0))[source]¶
4x4 matrix rotating angle degrees about the line through center in direction axis.
The 4x4 form of BOSL2’s
rot(a=, v=, center=): translate center to the origin, rotate, translate back.- Parameters:
angle (float)
center (tuple[float, float, float])
- Return type:
- bosl2.transforms.rot_inverse(t)[source]¶
Inverse of a rigid 4x4 transform (BOSL2 rot_inverse()): transpose the rotation, un-translate.
- Return type:
- bosl2.transforms.rot_decode(m, long=False)[source]¶
Decode a rigid 4x4 transform into its screw motion (BOSL2 rot_decode()).
Returns
[angle_degrees, axis, center, translation_along_axis]– rotating by angle about the line through center in direction axis then translating along the axis reproduces m. axis, center and the axial translation are returned asVec3. With long, the complementary (>180 degree) rotation about the reversed axis is chosen.- Parameters:
long (bool)
- Return type:
list
- bosl2.transforms.reorient(anchor=None, spin=0, orient=None, size=None)[source]¶
The 4x4 matrix that reorients a cuboid of size onto anchor/spin/orient.
The Python equivalent of BOSL2’s
reorient(anchor, spin, orient, size), for feeding PythonSCAD’s.multmatrix(). Composed asR(UP -> orient) * Zrot(spin) * Translate(-anchor * size / 2); verified to match BOSL2’s own output exactly across every anchor/orient/spin/size combination the toolkit uses (see tests/test_bosl2_reorient.py).Returns plain nested lists, not an ndarray: the result feeds straight into the native
multmatrix(), which rejects numpy arrays (“Error during parsing multmatrix(object, vec16)”).Usage:
tmat = reorient(anchor=CENTER, spin=90, orient=LEFT, size=[10, 20, 30]) shape.multmatrix(tmat)
- Parameters:
anchor – BOSL2 anchor vector (default CENTER)
spin (float) – rotation about Z in degrees, applied after the anchor move (default 0)
orient – direction the shape’s UP is rotated onto (default UP)
size – [x, y, z] size the anchor is resolved against (default [0, 0, 0])
- Return type:
list[list[float]]
- bosl2.transforms.apply(transform, points)[source]¶
Apply a 4x4 (or 3x3, 2-D) transform matrix to every point in points.
The Python equivalent of BOSL2’s
apply(). Returns plain nested lists so the result can cross the native FFI boundary.Usage:
apply(reorient(anchor=CENTER, orient=LEFT, size=[1, 1, 1]), [[5, 0, 0], [-5, 0, 0]])
- Return type:
list