Open alikureishy opened 1 year ago
not exactly the same problem, but I had trouble using hull
today with this example:
out = cq.Sketch().circle(rod_d / 2 + wall_t).push([mount_loc]).circle(mount_d / 2 + wall_t).edges().hull()
which is basically a big and small circle that intersect each other. using hull produced this error:
Traceback (most recent call last):
File "/home/haoqing/phone-mount.py", line 10, in <module>
sk = cq.Sketch().circle(rod_d / 2 + wall_t).push([mount_loc]).circle(mount_d / 2 + wall_t).edges().hull().reset().circle(rod_d / 2, "s").push([mount_loc]).circle(mount_d / 2, "s")
File "/home/haoqing/.local/lib/python3.10/site-packages/cadquery/sketch.py", line 508, in hull
rv = find_hull(el for el in self._faces.Edges())
File "/home/haoqing/.local/lib/python3.10/site-packages/cadquery/hull.py", line 395, in find_hull
angle, segment = get_angle(current_e, e)
File "/home/haoqing/.local/lib/python3.10/site-packages/cadquery/hull.py", line 312, in get_angle
return arc_arc(current, e)
File "/home/haoqing/.local/lib/python3.10/site-packages/cadquery/hull.py", line 262, in arc_arc
dx /= l
ZeroDivisionError: float division by zero
where l
is basically the distance between the objects.
After messing around a bit, I solved my issue (without understanding the code too much, just messing and observe what works) with this commit. Possibly this could help you.
AFAICT the issue occurs only with intersecting circles. Do you confirm?
I think the issue is with concentric arcs (haven't tested yet, I could do that tomorrow), and intersecting circles would be one instance of that
I tried to come up with other scenarios, but they don't seem to hit the same code path as 2 intersecting circles (haven't dug deeper to see what's actually going on).
Two things I tried:
cq.Sketch().circle(5).push([(5, 0)]).rect(10, 10, mode="i").reset().circle(2).hull() # concentric big semi + small circle
cq.Sketch().arc((0, 0), 5, 0, 180).arc((0, 0), 5, 180, 360).reset().edges().hull()) # 2 halves of a circle
Hi.
I've ran into problems with hull() when working on a model. I did a bit of testing with intersecting circles. The samples and code are here:
r = 11.0
d = 30.0
sketch = cq.Workplane('XY').sketch()
# Base circles
sketch = sketch.push(((0, 0),)).circle(r)
sketch = sketch.push(((0, d),)).circle(r)
sketch = sketch.push(((d, d),)).circle(r)
sketch = sketch.push(((d, 0),)).circle(r)
# # Choose one of the following shapes placed between the circles to get different results
# # Large circle, cuts deeply into base circles
# # Result: ZeroDivisionError
# sketch = sketch.push(((d/2, d/2),)).circle(2*r)
# # Medium circle, tangent to base circles
# # Result: ZeroDivisionError
# sketch = sketch.push(((d/2, d/2),)).circle(d/sqrt(2)-r)
# # Small circle, does not connect with base circles
# # Result: Computes correctly
# sketch = sketch.push(((d/2, d/2),)).circle(r/2)
# # Large square, cuts deeply into base circles
# # Result: ZeroDivisionError
# sketch = sketch.push(((d/2, d/2),)).rect(2*r, 2*r)
# # Medium square, single pint touching each base circle
# # Result: ZeroDivisionError
# sketch = sketch.push(((d/2, d/2),)).rect((d-sqrt(2)*r), (d-sqrt(2)*r))
# # Small square, does not connect with base circles, but wider than the gap between them
# # Result: Loops infinitely with full load
# sketch = sketch.push(((d/2, d/2),)).rect(d-2*r+1, d-2*r+1)
# # Very small square, edges do not coincide with base circles
# # Result: Computes correctly
# sketch = sketch.push(((d/2, d/2),)).rect(r/2, r/2)
sketch = sketch.select().hull()
solid = sketch.finalize().extrude(5)
solid.val().exportStl('./test.stl')
There are 4 equidistant circles (on a square). I place a single shape in the middle. Whenever the center circle is intersecting or is tangent to the others, the code fails. However, a new issue shows up when using a rectangle in the center. If the rectangle is not intersecting, but has sides bigger than gap between the circles (d-2*r) the code falls into an infinite loop. This behavior is not present when placing a similar sized circle.
Maybe this is some new info to work with
To Reproduce
I was going through the Sketch tutorial, and playing around with hull(), and encountered this error. What am I doing wrong in this script below?
This is the model right before the
hull()
invocation above:Backtrace
Environment
OS: MacOS Ventura 13.0.1
Was CadQuery installed using Conda?: Yes
Output of
conda list
from your active Conda environment:Using: jupyter-cadquery on Jupyter Notebook