import cadquery as cq
import cq_warehouse.extensions
torus_major_radius = 50
torus_minor_radius = 10
def surface(u, v):
"""Calculate the surface displacement of the flag at a given position"""
return (
cq.Vector(torus_minor_radius, 0, 0).rotateY(360 * u)
+ cq.Vector(torus_major_radius, 0, 0)
).rotateZ(180 * v)
torus_face = cq.Workplane("XY").parametricSurface(lambda u, v: surface(u, v), N=10)
torus_end_edges = [
torus_face.edges(">X").val(),
torus_face.edges("<X").val(),
]
torus_end_wires = [cq.Wire.assembleEdges([e]) for e in torus_end_edges]
torus_end_faces = [cq.Face.makeFromWires(w, []) for w in torus_end_wires]
torus_faces = [torus_face.val()] + torus_end_faces
torus_shell = cq.Shell.makeShell(torus_faces).fix()
torus_solid = cq.Solid.makeSolid(torus_shell)
for i, f in enumerate(torus_faces):
print(f"face{i}.isValid()={f.isValid()}")
print(f"{torus_shell.isValid()=}")
print(f"{torus_shell.Closed()=}")
print(f"{torus_solid.isValid()=}")
test = cq.Solid.makeBox(50, 50, 50).fuse(torus_solid)
print(f"{test.isValid()=}")
if "show_object" in locals():
# show_object(torus_solid, name="torus_solid")
# show_object(torus_face, name="torus_face")
# show_object(torus_end_edges, name="torus_end_edges")
# show_object(torus_end_wires, name="torus_end_wires")
# show_object(torus_end_faces, name="torus_end_faces")
# show_object(torus_shell, name="torus_shell")
show_object(torus_solid, name="torus_solid")
# show_object(test, name="test")