cadquery icon indicating copy to clipboard operation
cadquery copied to clipboard

Issue with cutting a cylinder from a torus (revolved circle)

Open bedilu opened this issue 4 months ago • 4 comments

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()

Image

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

bedilu avatar Jun 05 '25 14:06 bedilu