CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
3.21k stars 292 forks source link

Sketch.hull() causes a ZeroDivisionError instead of some guidance around what was done wrong #1224

Open alikureishy opened 1 year ago

alikureishy commented 1 year ago

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?

cast: cq.Sketch = (
    cq.Sketch()
    .trapezoid(4, 3, 90)
    .vertices()
    .circle(.5, mode='s')
    .vertices()
    .circle(0.4, mode='a')
    .reset()
    .edges()
    .hull()          <----------- ZeroDivisionError
)

This is the model right before the hull() invocation above:

Screenshot 2023-01-11 at 7 38 04 PM

Backtrace

ZeroDivisionError                         Traceback (most recent call last)
/var/folders/fs/jcstsp1j5fn8rz8bhfqxsglh0000gn/T/ipykernel_33196/1777645838.py in <cell line: 1>()
      8     .reset()
      9     .edges()
---> 10     .hull()
     11 )
     12 show(cast)

~/anaconda3/envs/cad/lib/python3.10/site-packages/cadquery/sketch.py in hull(self, mode, tag)
    502 
    503         if self._selection:
--> 504             rv = find_hull(el for el in self._selection if isinstance(el, Edge))
    505         elif self._faces:
    506             rv = find_hull(el for el in self._faces.Edges())

~/anaconda3/envs/cad/lib/python3.10/site-packages/cadquery/hull.py in find_hull(edges)
    393 
    394         for e in entities:
--> 395             angle, segment = get_angle(current_e, e)
    396             angles.append(angle if angle >= current_angle else inf)
    397             segments.append(segment)

~/anaconda3/envs/cad/lib/python3.10/site-packages/cadquery/hull.py in get_angle(current, e)
    310             return arc_pt(current, e)
    311         else:
--> 312             return arc_arc(current, e)
    313 
    314 

~/anaconda3/envs/cad/lib/python3.10/site-packages/cadquery/hull.py in arc_arc(a1, a2)
    245     elif r1 < r2:
    246         arc_tmp = Arc(a2.c, r2 - r1, a2.a1, a2.a2)
--> 247         xtmp1, ytmp1, xtmp2, ytmp2 = _pt_arc(a1.c, arc_tmp)
    248 
    249         delta_r = r2 - r1

~/anaconda3/envs/cad/lib/python3.10/site-packages/cadquery/hull.py in _pt_arc(p, a)
    189     l = sqrt(dx ** 2 + dy ** 2)
    190 
--> 191     x1 = r ** 2 / l ** 2 * dx - r / l ** 2 * sqrt(l ** 2 - r ** 2) * dy + xc
    192     y1 = r ** 2 / l ** 2 * dy + r / l ** 2 * sqrt(l ** 2 - r ** 2) * dx + yc
    193     x2 = r ** 2 / l ** 2 * dx + r / l ** 2 * sqrt(l ** 2 - r ** 2) * dy + xc

ZeroDivisionError: float division by zero

Environment

OS: MacOS Ventura 13.0.1

Was CadQuery installed using Conda?: Yes

Output of conda list from your active Conda environment:

# packages in environment at /Users/safdar/anaconda3/envs/cad:
#
# Name                    Version                   Build  Channel
absl-py                   1.2.0                    pypi_0    pypi
ai-cs                     1.0.7                    pypi_0    pypi
aiosignal                 1.2.0                    pypi_0    pypi
alabaster                 0.7.12                     py_0    conda-forge
ampl-mp                   3.1.0             h2beb688_1005    conda-forge
anyio                     3.5.0           py310hecd8cb5_0  
anytree                   2.8.0                    pypi_0    pypi
applaunchservices         0.3.0              pyhd8ed1ab_2    conda-forge
appnope                   0.1.2           py310hecd8cb5_1001  
argon2-cffi               21.3.0             pyhd3eb1b0_0  
argon2-cffi-bindings      21.2.0          py310hca72f7f_0  
arrow                     1.2.3              pyhd8ed1ab_0    conda-forge
astroid                   2.12.10         py310h2ec42d9_0    conda-forge
asttokens                 2.0.5              pyhd3eb1b0_0  
astunparse                1.6.3                    pypi_0    pypi
atomicwrites              1.4.1              pyhd8ed1ab_0    conda-forge
attrs                     21.4.0             pyhd3eb1b0_0  
autopep8                  1.6.0              pyhd8ed1ab_1    conda-forge
babel                     2.9.1              pyhd3eb1b0_0  
backcall                  0.2.0              pyhd3eb1b0_0  
beautifulsoup4            4.11.1          py310hecd8cb5_0  
binaryornot               0.4.4                      py_1    conda-forge
black                     22.10.0         py310h2ec42d9_0    conda-forge
bleach                    4.1.0              pyhd3eb1b0_0  
brotlipy                  0.7.0           py310hca72f7f_1002  
bzip2                     1.0.8                h1de35cc_0  
c-ares                    1.18.1               h0d85af4_0    conda-forge
ca-certificates           2022.9.24            h033912b_0    conda-forge
cachetools                5.2.0                    pypi_0    pypi
cad-viewer-widget         1.4.0                    pypi_0    pypi
cadquery                  master                   py3.10    cadquery
cadquery-massembly        1.0.0rc0                 pypi_0    pypi
casadi                    3.5.5           py310h7fc55d0_7    conda-forge
certifi                   2022.9.24          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1          py310hc55c11b_0  
chardet                   5.0.0           py310h2ec42d9_0    conda-forge
charset-normalizer        2.0.4              pyhd3eb1b0_0  
click                     8.0.4                    pypi_0    pypi
cloudpickle               2.1.0                    pypi_0    pypi
colorama                  0.4.5              pyhd8ed1ab_0    conda-forge
cookiecutter              2.1.1              pyh6c4a22f_0    conda-forge
cq-editor                 master                   py3.10    cadquery
cq-gears                  0.62                     pypi_0    pypi
cq-warehouse              0.8.0                    pypi_0    pypi
cryptography              37.0.1          py310hf6deb26_0  
curl                      7.81.0               hf45b732_0    conda-forge
cycler                    0.11.0                   pypi_0    pypi
dbus                      1.13.6               h2f22bb5_0    conda-forge
debugpy                   1.5.1           py310he9d5cce_0  
decorator                 5.1.1              pyhd3eb1b0_0  
defusedxml                0.7.1              pyhd3eb1b0_0  
diff-match-patch          20200713           pyh9f0ad1d_0    conda-forge
dill                      0.3.6              pyhd8ed1ab_1    conda-forge
distlib                   0.3.5                    pypi_0    pypi
dm-tree                   0.1.7                    pypi_0    pypi
docutils                  0.18.1          py310hecd8cb5_3  
double-conversion         3.2.0                he49afe7_0    conda-forge
eigen                     3.4.0                h940c156_0    conda-forge
entrypoints               0.4             py310hecd8cb5_0  
executing                 0.8.3              pyhd3eb1b0_0  
expat                     2.4.4                he49afe7_0    conda-forge
ezdxf                     0.17.2          py310h2fea185_0    conda-forge
ffmpeg                    4.3.2                h4dad6da_1    conda-forge
filelock                  3.8.0                    pypi_0    pypi
flake8                    4.0.1              pyhd8ed1ab_2    conda-forge
flatbuffers               1.12                     pypi_0    pypi
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.13.96              h10f422b_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.36.0                   pypi_0    pypi
freeimage                 3.18.0               h7d96ac2_7    conda-forge
freetype                  2.12.1               h3f81eb7_0    conda-forge
frozenlist                1.3.1                    pypi_0    pypi
gast                      0.4.0                    pypi_0    pypi
gettext                   0.21.0               h7535e17_0  
giflib                    5.2.1                haf1e3a3_0  
gl2ps                     1.4.2                h4cff582_0    conda-forge
glew                      2.1.0                h046ec9c_2    conda-forge
glib                      2.69.1               h8346a28_1  
gmp                       6.2.1                h2e338ed_0    conda-forge
gnutls                    3.6.13               h756fd2b_1    conda-forge
google-auth               2.11.0                   pypi_0    pypi
google-auth-oauthlib      0.4.6                    pypi_0    pypi
google-pasta              0.2.0                    pypi_0    pypi
grpcio                    1.43.0                   pypi_0    pypi
gst-plugins-base          1.14.0               h4180768_2  
gstreamer                 1.14.0               h0fc69c2_2  
gym                       0.21.0                   pypi_0    pypi
h5py                      3.7.0                    pypi_0    pypi
hdf4                      4.2.15               hefd3b78_3    conda-forge
hdf5                      1.12.1          nompi_h2f0ef1a_103    conda-forge
icu                       68.2                 he49afe7_0    conda-forge
idna                      3.3                pyhd3eb1b0_0  
ilmbase                   2.5.5                hfab91a5_0    conda-forge
imageio                   2.21.1                   pypi_0    pypi
imagesize                 1.4.1              pyhd8ed1ab_0    conda-forge
importlib-metadata        4.11.4          py310h2ec42d9_0    conda-forge
inflection                0.5.1              pyh9f0ad1d_0    conda-forge
intervaltree              3.0.2                      py_0    conda-forge
ipopt                     3.14.4               hc501a57_0    conda-forge
ipykernel                 6.16.1             pyh736e0ef_0    conda-forge
ipython                   7.33.0          py310h2ec42d9_0    conda-forge
ipython_genutils          0.2.0              pyhd3eb1b0_1  
ipywidgets                7.7.2                    pypi_0    pypi
isort                     5.10.1             pyhd8ed1ab_0    conda-forge
jaraco.classes            3.2.2              pyhd8ed1ab_0    conda-forge
jbig                      2.1               h0d85af4_2003    conda-forge
jedi                      0.18.1          py310hecd8cb5_1  
jellyfish                 0.9.0           py310h1961e1f_1    conda-forge
jinja2                    3.0.3              pyhd3eb1b0_0  
jinja2-time               0.2.0              pyhd8ed1ab_3    conda-forge
jpeg                      9e                   hca72f7f_0  
json5                     0.9.6              pyhd3eb1b0_0  
jsoncpp                   1.9.5                h940c156_1    conda-forge
jsonschema                4.4.0           py310hecd8cb5_0  
jupyter                   1.0.0           py310hecd8cb5_8  
jupyter-cadquery          3.4.0                    pypi_0    pypi
jupyter-core              4.11.2                   pypi_0    pypi
jupyter_client            7.3.4              pyhd8ed1ab_0    conda-forge
jupyter_console           6.4.3              pyhd3eb1b0_0  
jupyter_server            1.18.1          py310hecd8cb5_0  
jupyterlab                3.4.4           py310hecd8cb5_0  
jupyterlab_pygments       0.1.2                      py_0  
jupyterlab_server         2.12.0          py310hecd8cb5_0  
jupyterlab_widgets        1.0.0              pyhd3eb1b0_1  
jxrlib                    1.1                  h35c211d_2    conda-forge
keras                     2.9.0                    pypi_0    pypi
keras-preprocessing       1.1.2                    pypi_0    pypi
keyring                   23.9.3          py310h2ec42d9_0    conda-forge
kiwisolver                1.4.4                    pypi_0    pypi
krb5                      1.19.2               hcd88c3b_0  
lame                      3.100             hb7f2c08_1003    conda-forge
lazy-object-proxy         1.7.1           py310h1961e1f_1    conda-forge
lcms2                     2.12                 h577c468_0    conda-forge
lerc                      3.0                  he9d5cce_0  
libblas                   3.9.0           13_osx64_openblas    conda-forge
libcblas                  3.9.0           13_osx64_openblas    conda-forge
libclang                  14.0.6                   pypi_0    pypi
libcurl                   7.81.0               hf45b732_0    conda-forge
libcxx                    12.0.0               h2f01273_0  
libdeflate                1.8                  h9ed2024_5  
libedit                   3.1.20210910         hca72f7f_0  
libev                     4.33                 haf1e3a3_1    conda-forge
libffi                    3.3                  hb1e8313_2  
libgfortran               5.0.0           10_4_0_h97931a8_25    conda-forge
libgfortran5              11.3.0              h082f757_25    conda-forge
libiconv                  1.16                 hca72f7f_2  
liblapack                 3.9.0           13_osx64_openblas    conda-forge
libllvm11                 11.1.0               hd011deb_3    conda-forge
libllvm12                 12.0.0               h9b2ccf5_3  
libnetcdf                 4.8.1           nompi_h6609ca0_101    conda-forge
libnghttp2                1.46.0               h6f36284_0    conda-forge
libogg                    1.3.4                h35c211d_1    conda-forge
libopenblas               0.3.18          openmp_h3351f45_0    conda-forge
libosqp                   0.6.2                he49afe7_3    conda-forge
libpng                    1.6.37               ha441bb4_0  
libpq                     12.9                 h1c9f633_3  
libraw                    0.20.2               hefd3b78_1    conda-forge
libsodium                 1.0.18               h1de35cc_0  
libspatialindex           1.9.3                he49afe7_4    conda-forge
libssh2                   1.10.0               h7535e13_3    conda-forge
libtheora                 1.1.1             h0d85af4_1005    conda-forge
libtiff                   4.3.0                hd146c10_2    conda-forge
libvorbis                 1.3.7                h046ec9c_0    conda-forge
libwebp                   1.2.2                h56c3ce4_0  
libwebp-base              1.2.2                hca72f7f_0  
libxml2                   2.9.12               h93ec3fd_0    conda-forge
libzip                    1.9.2                h3ad4413_1    conda-forge
libzlib                   1.2.12               hfe4f2af_2    conda-forge
llvm-openmp               12.0.0               h0dcd299_1  
logbook                   1.5.3           py310h90acd4f_6    conda-forge
loguru                    0.6.0           py310h2ec42d9_1    conda-forge
lxml                      4.9.1                    pypi_0    pypi
lz4                       4.0.2                    pypi_0    pypi
lz4-c                     1.9.3                h23ab428_1  
markdown                  3.4.1                    pypi_0    pypi
markupsafe                2.1.1           py310hca72f7f_0  
matplotlib                3.5.3                    pypi_0    pypi
matplotlib-inline         0.1.2              pyhd3eb1b0_2  
mccabe                    0.6.1                      py_1    conda-forge
metis                     5.1.0             h2e338ed_1006    conda-forge
mistune                   0.8.4           py310hca72f7f_1000  
more-itertools            9.0.0              pyhd8ed1ab_0    conda-forge
msgpack                   1.0.4                    pypi_0    pypi
multimethod               1.9                pyhd8ed1ab_0    conda-forge
mumps-include             5.2.1               h694c41f_11    conda-forge
mumps-seq                 5.2.1               hea8e22a_11    conda-forge
mypy_extensions           0.4.3           py310h2ec42d9_5    conda-forge
mysql-common              8.0.28               h694c41f_0    conda-forge
mysql-libs                8.0.28               h115446f_0    conda-forge
nbclassic                 0.3.5              pyhd3eb1b0_0  
nbclient                  0.5.13          py310hecd8cb5_0  
nbconvert                 6.5.4                    pypi_0    pypi
nbformat                  5.3.0           py310hecd8cb5_0  
ncurses                   6.3                  hca72f7f_3  
nest-asyncio              1.5.5           py310hecd8cb5_0  
nettle                    3.6                  hedd7734_0    conda-forge
networkx                  2.8.6                    pypi_0    pypi
nlopt                     2.7.1           py310h59dc6d6_0    conda-forge
notebook                  6.4.12          py310hecd8cb5_0  
nptyping                  2.0.1              pyhd8ed1ab_0    conda-forge
nspr                      4.33                 he9d5cce_0  
nss                       3.74                 h47edf6a_0  
numpy                     1.23.2                   pypi_0    pypi
numpy-quaternion          2022.4.1                 pypi_0    pypi
numpydoc                  1.5.0              pyhd8ed1ab_0    conda-forge
oauthlib                  3.2.0                    pypi_0    pypi
occt                      7.6.1                h244648f_0    conda-forge
ocp                       7.6.1.alpha             py310_0    cadquery
openexr                   2.5.5                h7fa7ffa_0    conda-forge
openh264                  2.1.1                hfd3ada9_0    conda-forge
openjpeg                  2.4.0                h6e7aa92_1    conda-forge
openssl                   1.1.1q               hfd90126_1    conda-forge
opt-einsum                3.3.0                    pypi_0    pypi
packaging                 21.3               pyhd3eb1b0_0  
pandas                    1.4.3                    pypi_0    pypi
pandocfilters             1.5.0              pyhd3eb1b0_0  
parso                     0.8.3              pyhd3eb1b0_0  
path                      16.5.0          py310h2ec42d9_0    conda-forge
pathspec                  0.10.1             pyhd8ed1ab_0    conda-forge
pcre                      8.45                 h23ab428_0  
pexpect                   4.8.0              pyhd3eb1b0_3  
pickleshare               0.7.5           pyhd3eb1b0_1003  
pillow                    9.2.0                    pypi_0    pypi
pip                       22.1.2          py310hecd8cb5_0  
platformdirs              2.5.2              pyhd8ed1ab_1    conda-forge
pluggy                    1.0.0           py310h2ec42d9_3    conda-forge
ply                       3.11            py310hecd8cb5_0  
proj                      8.2.1                h1512c50_0    conda-forge
prometheus_client         0.14.1          py310hecd8cb5_0  
prompt-toolkit            3.0.20             pyhd3eb1b0_0  
prompt_toolkit            3.0.20               hd3eb1b0_0  
protobuf                  3.19.4                   pypi_0    pypi
psutil                    5.9.3           py310h90acd4f_0    conda-forge
ptyprocess                0.7.0              pyhd3eb1b0_2  
pugixml                   1.11.4               he49afe7_0    conda-forge
pure_eval                 0.2.2              pyhd3eb1b0_0  
pyasn1                    0.4.8                    pypi_0    pypi
pyasn1-modules            0.2.8                    pypi_0    pypi
pycodestyle               2.8.0              pyhd8ed1ab_0    conda-forge
pycparser                 2.21               pyhd3eb1b0_0  
pydocstyle                6.1.1              pyhd8ed1ab_0    conda-forge
pyflakes                  2.4.0              pyhd8ed1ab_0    conda-forge
pygments                  2.11.2             pyhd3eb1b0_0  
pylint                    2.15.3             pyhd8ed1ab_0    conda-forge
pyls-spyder               0.4.0              pyhd8ed1ab_0    conda-forge
pyobjc-core               8.5             py310hc55c11b_0  
pyobjc-framework-cocoa    8.5             py310hca72f7f_0  
pyobjc-framework-coreservices 8.5             py310h6c45266_1    conda-forge
pyobjc-framework-fsevents 8.5             py310h2ec42d9_1    conda-forge
pyopenssl                 22.0.0             pyhd3eb1b0_0  
pyparsing                 3.0.4              pyhd3eb1b0_0  
pyqt                      5.12.3          py310h2ec42d9_8    conda-forge
pyqt-impl                 5.12.3          py310hea9ccf3_8    conda-forge
pyqt5-sip                 4.19.18         py310hd046c34_8    conda-forge
pyqtchart                 5.12            py310hea9ccf3_8    conda-forge
pyqtgraph                 0.12.4             pyhd8ed1ab_0    conda-forge
pyqtwebengine             5.12.1          py310hea9ccf3_8    conda-forge
pyrsistent                0.18.0          py310hca72f7f_0  
pysocks                   1.7.1           py310hecd8cb5_0  
python                    3.10.4               hdfd78df_0  
python-dateutil           2.8.2              pyhd3eb1b0_0  
python-fastjsonschema     2.15.1             pyhd3eb1b0_0  
python-lsp-black          1.2.1              pyhd8ed1ab_0    conda-forge
python-lsp-jsonrpc        1.0.0              pyhd8ed1ab_0    conda-forge
python-lsp-server         1.5.0                hd8ed1ab_1    conda-forge
python-lsp-server-base    1.5.0              pyhd8ed1ab_1    conda-forge
python-slugify            6.1.2              pyhd8ed1ab_0    conda-forge
python.app                1.4             py310he24745e_0    conda-forge
python_abi                3.10                    2_cp310    conda-forge
pytoolconfig              1.2.2              pyhd8ed1ab_0    conda-forge
pytz                      2022.1          py310hecd8cb5_0  
pywavelets                1.3.0                    pypi_0    pypi
pyyaml                    6.0             py310h1961e1f_4    conda-forge
pyzmq                     23.2.0          py310he9d5cce_0  
qdarkstyle                3.0.3              pyhd8ed1ab_0    conda-forge
qstylizer                 0.2.2              pyhd8ed1ab_0    conda-forge
qt                        5.12.9               h126340a_2    conda-forge
qtawesome                 1.2.0              pyhd8ed1ab_0    conda-forge
qtconsole                 5.3.2              pyhd8ed1ab_0    conda-forge
qtconsole-base            5.3.2              pyha770c72_0    conda-forge
qtpy                      2.2.1              pyhd8ed1ab_0    conda-forge
rapidjson                 1.1.0             hb1e8313_1002    conda-forge
ray                       1.13.0                   pypi_0    pypi
readline                  8.1.2                hca72f7f_1  
requests                  2.28.1          py310hecd8cb5_0  
requests-oauthlib         1.3.1                    pypi_0    pypi
rope                      1.4.0              pyhd8ed1ab_0    conda-forge
rsa                       4.9                      pypi_0    pypi
rtree                     1.0.1           py310had9ce37_0    conda-forge
scikit-image              0.19.3                   pypi_0    pypi
scipy                     1.9.0                    pypi_0    pypi
scotch                    6.0.9                h3da7401_2    conda-forge
send2trash                1.8.0              pyhd3eb1b0_1  
setuptools                61.2.0          py310hecd8cb5_0  
sip                       6.6.2           py310he9d5cce_0  
six                       1.16.0             pyhd3eb1b0_1  
sniffio                   1.2.0           py310hecd8cb5_1  
snowballstemmer           2.2.0              pyhd8ed1ab_0    conda-forge
sortedcontainers          2.4.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.3.1              pyhd3eb1b0_0  
sphinx                    5.0.0              pyh6c4a22f_1    conda-forge
sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_2    conda-forge
spyder                    5.3.3           py310h2ec42d9_0    conda-forge
spyder-kernels            2.3.3           py310h2ec42d9_0    conda-forge
sqlite                    3.39.2               h707629a_0  
stack_data                0.2.0              pyhd3eb1b0_0  
tabulate                  0.8.10                   pypi_0    pypi
tbb                       2021.5.0             h940c156_0    conda-forge
tbb-devel                 2021.5.0             h940c156_0    conda-forge
tensorboard               2.9.1                    pypi_0    pypi
tensorboard-data-server   0.6.1                    pypi_0    pypi
tensorboard-plugin-wit    1.8.1                    pypi_0    pypi
tensorboardx              2.5.1                    pypi_0    pypi
tensorflow                2.9.1                    pypi_0    pypi
tensorflow-estimator      2.9.0                    pypi_0    pypi
tensorflow-io-gcs-filesystem 0.26.0                   pypi_0    pypi
termcolor                 1.1.0                    pypi_0    pypi
terminado                 0.13.1          py310hecd8cb5_0  
testpath                  0.6.0           py310hecd8cb5_0  
text-unidecode            1.3                        py_0    conda-forge
textdistance              4.5.0              pyhd8ed1ab_0    conda-forge
three-merge               0.1.1              pyh9f0ad1d_0    conda-forge
tifffile                  2022.8.12                pypi_0    pypi
tinycss2                  1.2.1              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h5d9f67b_0  
toml                      0.10.2             pyhd3eb1b0_0  
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
tomlkit                   0.11.5             pyha770c72_0    conda-forge
torch                     1.12.1                   pypi_0    pypi
tornado                   6.1             py310hca72f7f_0  
traitlets                 5.1.1              pyhd3eb1b0_0  
typing                    3.10.0.0           pyhd8ed1ab_0    conda-forge
typing-extensions         4.3.0           py310hecd8cb5_0  
typing_extensions         4.3.0           py310hecd8cb5_0  
typish                    1.9.3              pyhd8ed1ab_0    conda-forge
tzdata                    2022a                hda174b7_0  
ujson                     5.4.0           py310he9d5cce_0  
unidecode                 1.3.6              pyhd8ed1ab_0    conda-forge
urdf-parser-py            0.0.4                    pypi_0    pypi
urllib3                   1.26.11         py310hecd8cb5_0  
utfcpp                    3.2.1                h694c41f_0    conda-forge
virtualenv                20.16.3                  pypi_0    pypi
voila                     0.3.6                    pypi_0    pypi
vtk                       9.1.0           qt_py310h414f686_204    conda-forge
watchdog                  2.1.9           py310h5027ba8_0    conda-forge
wcwidth                   0.2.5              pyhd3eb1b0_0  
webcolors                 1.12                     pypi_0    pypi
webencodings              0.5.1           py310hecd8cb5_1  
websocket-client          0.58.0          py310hecd8cb5_4  
websockets                10.3                     pypi_0    pypi
werkzeug                  2.2.2                    pypi_0    pypi
whatthepatch              1.0.2              pyhd8ed1ab_0    conda-forge
wheel                     0.37.1             pyhd3eb1b0_0  
widgetsnbextension        3.6.1                    pypi_0    pypi
wrapt                     1.14.1          py310h6c45266_0    conda-forge
wurlitzer                 3.0.2              pyhd8ed1ab_2    conda-forge
x264                      1!161.3030           h0d85af4_1    conda-forge
xacro                     1.13.3                   pypi_0    pypi
xz                        5.2.5                hca72f7f_1  
yaml                      0.2.5                h0d85af4_2    conda-forge
yapf                      0.32.0             pyhd8ed1ab_0    conda-forge
zeromq                    4.3.4                h23ab428_0  
zipp                      3.9.0              pyhd8ed1ab_0    conda-forge
zlib                      1.2.12               h4dc903c_2  
zstd                      1.5.2                hcb37349_0

Using: jupyter-cadquery on Jupyter Notebook

crides commented 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.

adam-urbanczyk commented 1 year ago

AFAICT the issue occurs only with intersecting circles. Do you confirm?

crides commented 1 year ago

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

crides commented 1 year ago

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
GabrielBlackfox commented 4 months ago

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