-
Notifications
You must be signed in to change notification settings - Fork 357
Open
Labels
Description
To Reproduce
import cadquery as cq
import pyvista as pv
#Initialize the assembly
model = cq.Assembly()
#Define the major and minor radii for the torus
R = 50.0
r = 20.0
#Create a circle in the XY plane with the minor radius r
torus_profile = cq.Workplane("XY").circle(r)
#Revolve the circle around Y-axis to generate the torus
torus = torus_profile.revolve(angleDegrees=360, axisStart=[R, 0, 0], axisEnd=[R, 1, 0])
#Define the radius and height of the cylinder
#cylinder_radius = r/5 # It works for this radius!
cylinder_radius = r/4
cylinder_height = 4*R # Ensure the height is enough to pierce through the torus
#Create the cylinder in the YZ plane, centered at the origin
cylinder = cq.Workplane("YZ").circle(cylinder_radius).extrude(cylinder_height)
#Move the cylinder to the center of the torus
cylinder = cylinder.translate((-R, 0, 0))
#Cut the cylinder from the torus
#pierced_torus = torus.add(cylinder)
pierced_torus = torus.cut(cylinder)
model.add(pierced_torus)
#Export/Show the result
model.toCompound().exportStl('cut_torus.stl') # .stl / .step / .glb are supported
#Export the assembly to a STEP file
cq.exporters.export(model.toCompound(), 'cut_torus.step')
#View model
pv_mesh = pv.read('cut_torus.stl')
pl = pv.Plotter()
pl.add_mesh(pv_mesh)
pl.show()
Backtrace
Environment
OS:
Was CadQuery installed using Conda?:
Output of conda list
from your active Conda environment:
Using:
Working on Win10; cadquery (2.5.2) is installed using pip; plus VSCode