translate(obj,[x, y, z])
Translate object by x, y, z
cube([5,5,5]).translate([10, 0, 0]).show()
rotate(obj,[x, y, z])
Rotate object by x, y, z degrees
cube([5,10,5]).rotate([0, 0, 45]).show()
scale(obj,[x, y, z])
Scale object by x, y, z factors
cube([5,5,5]).scale([2, 2, 1]).show()
mirror(obj,[x, y, z])
Mirror object across the plane defined by x, y, z
cube([5,10,15]).mirror([1, 0, 0]).show()
multmatrix(m)
Apply transformation matrix
mat = [[1,0,0,10],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
cube(5).multmatrix(mat).show()
divmatrix(m)
Apply inverse matrix
mat=[[1,0,0,6],[0,1,0,0],[0,0,1,0],[0,0,0,1]] # Move to the right by 6
a=cube([1,1,1])
b=a.multmatrix(mat) # move to right
c=b.divmatrix(mat) # move back left
c.show()
b.show()
offset(r, delta=None, chamfer=False)
Offset 2D shape
square(10).offset(2).show()
roof(method, convexity=1)
Create roof from 2D shape
square(10).roof().show()
pull(src, dst)
Pull between points
cube(5).pull([0,0,1],[10,2,2]).show()
wrap(r)
Wrap around cylinder
text("Hello again").linear_extrude(3).rotate([90,0,0]).wrap(2).show()
๐ Extrusions
linear_extrude(shape,height)
Extrude 2D shape linearly
circle(5).linear_extrude(10).show()
rotate_extrude(angle,shape,v)
Extrude 2D shape by rotating it, and displacing in x,y,z
square(3).right(5).rotate_extrude(v=[0,0,10], angle=600).show()
path_extrude(shape, path)
Extrude shape along a specified path, with curved bends
path_extrude(square(2),[[0,0,0],[0,0,5,3],[8,8,8],[8,8,12]]).show()
๐งฉ Custom Shapes
circle(r, angle)
Create a circular arc
circle(r=5, angle=70).show()
cylinder(r, h, angle)
Create a cylindrical sector
cylinder(r=5, h=10, angle=120).show()
sphere(rfunc)
Create a sphere with radius defined by a function
def rfunc(v):
 
cf = abs(v[0]) + abs(v[1]) + abs(v[2]) + 3
 
print("cf = ",cf)
 
return 10 / cf
sphere(rfunc(10,22,-12), fs=0.5, fn=10).show()
linear_extrude(xsection, height)
Extrude a shape defined by a function along Z-axis
from math import sin
def xsection(h):
 
v = 5 + sin(h)
 
return [[-v,-v],[v,-v],[v,v],[-v,v]]
linear_extrude(xsection, height=10, fn=20).show()
rotate_extrude(xsection)
Rotate a shape defined by a function around Z-axis
from math import sin, pi
def xsection(h):
 
v = 2 * sin(4 * pi * h)
 
return [[10+v,-v],[15-v,-v],[15-v,5+v],[10+v,5+v]]
rotate_extrude(xsection, fn=50).show()
โ๏ธ Extra Features
align(object,connecthandle)
Align one object to another using handles
cone=cylinder(h=10,d1=5,d2=0)
cone.tip=translate(cone.origin,[0,0,10])
cub= cube(6)-[3,3,0]
cone = cone.roty(30) # Handles are also transformed
cone |= cub.align(cone.tip)
cone.show()
mesh()
Convert object to mesh (vertices and triangles)
u = cube(1) | cylinder(d=1,h=10)
pts, tris = u.mesh()
v = polyhedron(pts, tris)
v.show()
print("pts = ",pts,"\n\ntris = ",tris)
quick transformations
Shorthand for common transformations
cube(2).right(1.5).rotx(30).show()
(cylinder(r=3,h=5)*0.4 + [5,0,0]).show()
quick combination
Union(+), Difference(-) and Intersections(&)
(cube(2)-sphere(2)).show()
-- **************************************************-->