import math
import cadquery as cq
from cadquery import Workplane as WP
from cadquery import exporters
from cadquery import Edge
from cadquery import Wire
from cadquery import Face
from cadquery import Shell
from cadquery import Solid
from cadquery import Vector
def Tetra(s=1):
c0 = s*math.sqrt(2) / 4
vertices = [[c0, -c0, c0], [c0, c0, -c0], [-c0, c0, c0], [-c0, -c0, -c0]]
faces_ixs = [[0, 1, 2, 0], [1, 0, 3, 1], [2, 3, 0, 2], [3, 2, 1, 3]]
faces = []
for ixs in faces_ixs:
lines = []
for v1, v2 in zip(ixs, ixs[1:]):
lines.append(
Edge.makeLine(Vector(*vertices[v1]), Vector(*vertices[v2]))
)
wire = Wire.combine(lines)
faces.append(Face.makeFromWires(wire))
shell = Shell.makeShell(faces)
solid = Solid.makeSolid(shell)
return solid
def save( self, fname, tol = 1):
with open(fname, 'w') as f:
exporters.exportShape(self, "STL", f, tol)
WP.save = save
s = WP("XY").sphere(radius=1).union(Tetra(s=3))
s.save("./cq-output.stl", tol=0.01)