CadQuery / CadQuery/cadquery

Boolean cut between shapes does not produce expected result

Open
#1,796 1 comment 0 reactions 0 assignees View on GitHub
OCC kernel issue
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

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.

```python
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](https://github.com/user-attachments/assets/da3873d6-6f7d-406f-97ec-2c88f23c9a65)

The intersection looks like this:

![Image](https://github.com/user-attachments/assets/0b63080a-e5b1-47f9-8640-270b06d1ed96)

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](https://github.com/user-attachments/assets/2253a9eb-82c4-4fdd-ab00-865f84e67d2d)

And this is the intersection:

![Image](https://github.com/user-attachments/assets/39c65720-ee2f-46af-867f-04deedb1071d)

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!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.