Skip to content

Boolean cut between shapes does not produce expected result #1796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dstraub-pf opened this issue Mar 31, 2025 · 1 comment
Open

Boolean cut between shapes does not produce expected result #1796

dstraub-pf opened this issue Mar 31, 2025 · 1 comment

Comments

@dstraub-pf
Copy link

Hi! I am trying to cut a cylindrical hole into a toroidal shell. The function I'm using works "most of the time", but for same orientations & parameter values does not execute the cut correctly. Here is a minimal reproducible example.

import cadquery as cq
import cadquery.occ_impl.shapes as cq_shapes
import numpy as np

R = 3.3
r = 2.2
t = 0.05

# torus-like shape
inner_tor = cq_shapes.torus(d1=R * 2, d2=r * 2)
outer_tor = cq_shapes.torus(d1=R * 2, d2=(r + t) * 2)
torus_shape = cq_shapes.solid(outer_tor.Faces(), inner=inner_tor.Faces())

#cylinder
xyz1 = np.array([-0.5, -2.4 ,  2.1])
xyz2 = np.array([-2.6, -1.0, -0.1])
length = 5.0
radius = 0.1
plane = cq.Plane(origin=tuple(xyz2), normal=tuple(xyz1 - xyz2))
workplane = cq.Workplane(plane).circle(radius).extrude(length)
cylinder_shape = workplane.solids().val()

cut_shape = torus_shape.cut(cylinder_shape)

The result is as expected, getting a nice hole in the torus shell:

Image

The intersection looks like this:

Image

Now, if we change xyz2 from np.array([-2.6, -1.0, -0.1]) to np.array([-2.7, -1.0, -0.1]), it suddenly doesn't work anymore: this is the result of the cut operation

Image

And this is the intersection:

Image

I suspect this is an OCC issue, but I am running this in an automated script and don't have the liberty of manipulating coordinates by trial and error. Any idea of a workaround would be greatly appreciated, thanks!

@adam-urbanczyk
Copy link
Member

I can reproduce the issue with 7.8. I'm afraid that a workaround will be to not use the bool op in one shot. I.e. do something like this

from cadquery.vis import show
from cadquery.func import loft, solid, split

w = workplane.val()

oface, of2 = split(outer_tor.faces(), w).faces()
iface, if2 = split(inner_tor.faces(), w).faces()

side= loft(of2.edges(), if2.edges())

show(solid(oface, iface, side))

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants