Skip to content
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

loft() chooses "incorrect" wire? #523

Closed
yarikoptic opened this issue Nov 27, 2020 · 3 comments · Fixed by #1156
Closed

loft() chooses "incorrect" wire? #523

yarikoptic opened this issue Nov 27, 2020 · 3 comments · Fixed by #1156

Comments

@yarikoptic
Copy link

I am trying to achieve something like what is described in https://stackoverflow.com/questions/61186339/how-to-iteratively-loft-wires-in-cadquery 👍

import cadquery as cq
wp = cq.Workplane("XY").rect(1,2).workplane()
result = None
for i in range(0,5):
    wp2 = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
    if result == None:
        result = wp2.loft(combine=True)
    else:
        nextpart = wp2.loft(combine=True)
        result = result.union(nextpart)
    wp = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
show_object(result, options=dict(alpha=0.5,color='red'))

(in my case it would be not just a .rect but a .polyline with different at each step shape), but for my this example renders differently than on that page, and seems incorrect -- wide side face connects to the wire of 2nd rect instead of the one before:

image

re-installed clean using conda create -n cq-editor2 -c cadquery -c conda-forge cq-editor=master to the same result.

versions I have installed in conda
$> conda list    
# packages in environment at /home/yoh/anaconda-5.2.0-2.7/envs/cq-editor2:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       1_gnu    conda-forge
alabaster                 0.7.12                     py_0    conda-forge
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
argh                      0.26.2          pyh9f0ad1d_1002    conda-forge
astroid                   2.4.2            py38h32f6830_1    conda-forge
async_generator           1.10                       py_0    conda-forge
atomicwrites              1.4.0              pyh9f0ad1d_0    conda-forge
attrs                     20.3.0             pyhd3deb0d_0    conda-forge
autopep8                  1.5.4              pyh9f0ad1d_0    conda-forge
babel                     2.9.0              pyhd3deb0d_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.1                      py_0    conda-forge
black                     20.8b1                     py_1    conda-forge
bleach                    3.2.1              pyh9f0ad1d_0    conda-forge
brotlipy                  0.7.0           py38h8df0ef7_1001    conda-forge
bzip2                     1.0.8                h516909a_3    conda-forge
c-ares                    1.17.1               h36c2ea0_0    conda-forge
ca-certificates           2020.11.8            ha878542_0    conda-forge
cadquery                  master                    py3.8    cadquery
certifi                   2020.11.8        py38h578d9bd_0    conda-forge
cffi                      1.14.4           py38ha312104_0    conda-forge
chardet                   3.0.4           py38h924ce5b_1008    conda-forge
click                     7.1.2              pyh9f0ad1d_0    conda-forge
cloudpickle               1.6.0                      py_0    conda-forge
cq-editor                 master                    py3.8    cadquery
cryptography              3.2.1            py38h7699a38_0    conda-forge
curl                      7.71.1               he644dc0_8    conda-forge
dataclasses               0.7                pyhb2cacf7_7    conda-forge
dbus                      1.13.6               hfdff14a_1    conda-forge
decorator                 4.4.2                      py_0    conda-forge
defusedxml                0.6.0                      py_0    conda-forge
diff-match-patch          20200713           pyh9f0ad1d_0    conda-forge
docutils                  0.16             py38h924ce5b_2    conda-forge
double-conversion         3.1.5                he1b5a44_2    conda-forge
eigen                     3.3.8                h0efe328_0    conda-forge
entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
expat                     2.2.9                he1b5a44_2    conda-forge
ezdxf                     0.14.2                     py_0    conda-forge
ffmpeg                    4.3.1                h3215721_1    conda-forge
flake8                    3.8.4                      py_0    conda-forge
fontconfig                2.13.1            h7e3eb15_1002    conda-forge
freetype                  2.10.4               h7ca028e_0    conda-forge
future                    0.18.2           py38h578d9bd_2    conda-forge
gettext                   0.19.8.1          hf34092f_1004    conda-forge
gl2ps                     1.4.2                he06d7ca_0    conda-forge
glew                      2.1.0                he1b5a44_0    conda-forge
glib                      2.66.3               h58526e2_0    conda-forge
gmp                       6.2.1                h58526e2_0    conda-forge
gnutls                    3.6.13               h85f3911_1    conda-forge
gst-plugins-base          1.14.5               h0935bb2_2    conda-forge
gstreamer                 1.14.5               h36ae1b5_2    conda-forge
hdf4                      4.2.13            hf30be14_1003    conda-forge
hdf5                      1.10.6          nompi_h2750804_1111    conda-forge
helpdev                   0.7.1              pyhd8ed1ab_0    conda-forge
icu                       67.1                 he1b5a44_0    conda-forge
idna                      2.10               pyh9f0ad1d_0    conda-forge
imagesize                 1.2.0                      py_0    conda-forge
importlib-metadata        3.1.0              pyhd8ed1ab_0    conda-forge
importlib_metadata        3.1.0                hd8ed1ab_0    conda-forge
intervaltree              3.0.2                      py_0    conda-forge
ipykernel                 5.3.4            py38h81c977d_1    conda-forge
ipython                   7.19.0           py38h81c977d_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
isort                     5.6.4                      py_0    conda-forge
jedi                      0.17.2           py38h578d9bd_1    conda-forge
jeepney                   0.6.0              pyhd8ed1ab_0    conda-forge
jinja2                    2.11.2             pyh9f0ad1d_0    conda-forge
jpeg                      9d                   h36c2ea0_0    conda-forge
jsoncpp                   1.8.4             hc9558a2_1002    conda-forge
jsonschema                3.2.0                      py_2    conda-forge
jupyter_client            6.1.7                      py_0    conda-forge
jupyter_core              4.7.0            py38h578d9bd_0    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
keyring                   21.5.0           py38h578d9bd_0    conda-forge
krb5                      1.17.2               h926e7f8_0    conda-forge
lame                      3.100             h14c3975_1001    conda-forge
lazy-object-proxy         1.4.3            py38h1e0a361_2    conda-forge
ld_impl_linux-64          2.35.1               hed1e6ac_0    conda-forge
libblas                   3.9.0                3_openblas    conda-forge
libcblas                  3.9.0                3_openblas    conda-forge
libclang                  10.0.1          default_hde54327_1    conda-forge
libcurl                   7.71.1               hcdd3856_8    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libevent                  2.1.10               hcdb4288_3    conda-forge
libffi                    3.2.1             he1b5a44_1007    conda-forge
libgcc-ng                 9.3.0               h5dbcf3e_17    conda-forge
libgfortran-ng            9.3.0               he4bcb1c_17    conda-forge
libgfortran5              9.3.0               he4bcb1c_17    conda-forge
libglib                   2.66.3               hbe7bbb4_0    conda-forge
libglu                    9.0.0             he1b5a44_1001    conda-forge
libgomp                   9.3.0               h5dbcf3e_17    conda-forge
libiconv                  1.16                 h516909a_0    conda-forge
liblapack                 3.9.0                3_openblas    conda-forge
libllvm10                 10.0.1               he513fc3_3    conda-forge
libnetcdf                 4.7.4           nompi_hefab0ff_106    conda-forge
libnghttp2                1.41.0               h8cfc5f6_2    conda-forge
libogg                    1.3.2             h516909a_1002    conda-forge
libopenblas               0.3.12          pthreads_h4812303_1    conda-forge
libpng                    1.6.37               h21135ba_2    conda-forge
libpq                     12.3                 h5513abc_2    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libspatialindex           1.9.3                he1b5a44_3    conda-forge
libssh2                   1.9.0                hab1572f_5    conda-forge
libstdcxx-ng              9.3.0               h2ae2ef3_17    conda-forge
libtheora                 1.1.1             h516909a_1004    conda-forge
libtiff                   4.1.0                h4f3a223_6    conda-forge
libuuid                   2.32.1            h14c3975_1000    conda-forge
libvorbis                 1.3.7                he1b5a44_0    conda-forge
libwebp-base              1.1.0                h36c2ea0_3    conda-forge
libxcb                    1.13              h14c3975_1002    conda-forge
libxkbcommon              0.10.0               he1b5a44_0    conda-forge
libxml2                   2.9.10               h68273f3_2    conda-forge
logbook                   1.5.3            py38h1e0a361_3    conda-forge
loguru                    0.5.3            py38h32f6830_2    conda-forge
lz4-c                     1.9.2                he1b5a44_3    conda-forge
markupsafe                1.1.1            py38h8df0ef7_2    conda-forge
mccabe                    0.6.1                      py_1    conda-forge
mistune                   0.8.4           py38h25fe258_1002    conda-forge
mypy_extensions           0.4.3            py38h32f6830_2    conda-forge
mysql-common              8.0.21                        2    conda-forge
mysql-libs                8.0.21               hf3661c5_2    conda-forge
nbclient                  0.5.1                      py_0    conda-forge
nbconvert                 6.0.7            py38h578d9bd_3    conda-forge
nbformat                  5.0.8                      py_0    conda-forge
ncurses                   6.2                  h58526e2_4    conda-forge
nest-asyncio              1.4.3              pyhd8ed1ab_0    conda-forge
nettle                    3.6                  he412f7d_0    conda-forge
nptyping                  1.3.0              pyh9f0ad1d_1    conda-forge
nspr                      4.29                 he1b5a44_1    conda-forge
nss                       3.59                 h2c00c37_0    conda-forge
numpy                     1.19.4           py38hf0fd68c_1    conda-forge
numpydoc                  1.1.0                      py_1    conda-forge
occt                      7.4.0                h9121d39_5    cadquery
ocp                       7.4                     1_py3.8    cadquery
openh264                  2.1.1                h8b12597_0    conda-forge
openssl                   1.1.1h               h516909a_0    conda-forge
packaging                 20.4               pyh9f0ad1d_0    conda-forge
pandoc                    2.11.2               h36c2ea0_0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
parso                     0.7.0              pyh9f0ad1d_0    conda-forge
path                      15.0.0           py38h578d9bd_1    conda-forge
path.py                   12.5.0                        0    conda-forge
pathspec                  0.8.1              pyhd3deb0d_0    conda-forge
pathtools                 0.1.2                      py_1    conda-forge
pcre                      8.44                 he1b5a44_0    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       20.2.4                     py_0    conda-forge
pluggy                    0.13.1           py38h924ce5b_3    conda-forge
proj                      7.1.1                h966b41f_3    conda-forge
prompt-toolkit            3.0.8              pyha770c72_0    conda-forge
psutil                    5.7.3            py38h8df0ef7_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.6.0                   py_1001    conda-forge
pugixml                   1.10                 he1b5a44_1    conda-forge
pycodestyle               2.6.0              pyh9f0ad1d_0    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pydocstyle                5.1.1                      py_0    conda-forge
pyflakes                  2.2.0              pyh9f0ad1d_0    conda-forge
pygments                  2.7.2                      py_0    conda-forge
pylint                    2.6.0            py38h32f6830_1    conda-forge
pyls-black                0.4.6              pyh9f0ad1d_0    conda-forge
pyls-spyder               0.2.1              pyhd3deb0d_0    conda-forge
pyopenssl                 19.1.0                     py_1    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyqt                      5.12.3           py38ha8c2ead_4    conda-forge
pyqt5-sip                 4.19.18                  pypi_0    pypi
pyqtchart                 5.12                     pypi_0    pypi
pyqtgraph                 0.11.0             pyh9f0ad1d_1    conda-forge
pyqtwebengine             5.12.1                   pypi_0    pypi
pyrsistent                0.17.3           py38h25fe258_1    conda-forge
pysocks                   1.7.1            py38h924ce5b_2    conda-forge
python                    3.8.6           h852b56e_0_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python-jsonrpc-server     0.4.0              pyh9f0ad1d_0    conda-forge
python-language-server    0.36.1             pyhd8ed1ab_1    conda-forge
python_abi                3.8                      1_cp38    conda-forge
pytz                      2020.4             pyhd8ed1ab_0    conda-forge
pyxdg                     0.26                       py_0    conda-forge
pyyaml                    5.3.1            py38h8df0ef7_1    conda-forge
pyzmq                     20.0.0           py38h1d1b12f_1    conda-forge
qdarkstyle                2.8.1              pyhd8ed1ab_2    conda-forge
qt                        5.12.9               h1f2b2cb_0    conda-forge
qtawesome                 1.0.1              pyhd8ed1ab_1    conda-forge
qtconsole                 5.0.1              pyhd8ed1ab_0    conda-forge
qtpy                      1.9.0                      py_0    conda-forge
readline                  8.0                  he28a2e2_2    conda-forge
regex                     2020.11.13       py38h25fe258_0    conda-forge
requests                  2.25.0             pyhd3deb0d_0    conda-forge
rope                      0.18.0             pyh9f0ad1d_0    conda-forge
rtree                     0.9.4            py38h02d302b_2    conda-forge
scipy                     1.5.3            py38hb2138dd_0    conda-forge
secretstorage             3.3.0            py38h578d9bd_0    conda-forge
setuptools                49.6.0           py38h924ce5b_2    conda-forge
six                       1.15.0             pyh9f0ad1d_0    conda-forge
snowballstemmer           2.0.0                      py_0    conda-forge
sortedcontainers          2.3.0              pyhd8ed1ab_0    conda-forge
sphinx                    3.3.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    1.0.3                      py_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.4                      py_0    conda-forge
spyder                    4.2.0            py38h578d9bd_0    conda-forge
spyder-kernels            1.10.0           py38h578d9bd_0    conda-forge
sqlite                    3.33.0               h4cf870e_1    conda-forge
tbb                       2020.2               hc9558a2_0    conda-forge
tbb-devel                 2020.2               hc9558a2_0    conda-forge
testpath                  0.4.4                      py_0    conda-forge
three-merge               0.1.1              pyh9f0ad1d_0    conda-forge
tk                        8.6.10               hed695b0_1    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tornado                   6.1              py38h25fe258_0    conda-forge
traitlets                 5.0.5                      py_0    conda-forge
typed-ast                 1.4.1            py38h25fe258_1    conda-forge
typing_extensions         3.7.4.3                    py_0    conda-forge
typish                    1.9.1              pyh9f0ad1d_0    conda-forge
ujson                     4.0.1            py38h950e882_1    conda-forge
urllib3                   1.25.11                    py_0    conda-forge
utfcpp                    3.1.2                         0    conda-forge
vtk                       9.0.1           no_osmesa_py38h31de780_102    conda-forge
watchdog                  0.10.4           py38h578d9bd_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.35.1             pyh9f0ad1d_0    conda-forge
wrapt                     1.11.2           py38h1e0a361_1    conda-forge
wurlitzer                 2.0.0            py38h32f6830_2    conda-forge
x264                      1!152.20180806       h14c3975_0    conda-forge
xorg-kbproto              1.0.7             h14c3975_1002    conda-forge
xorg-libice               1.0.10               h516909a_0    conda-forge
xorg-libsm                1.2.3             h84519dc_1000    conda-forge
xorg-libx11               1.6.12               h516909a_0    conda-forge
xorg-libxau               1.0.9                h14c3975_0    conda-forge
xorg-libxdmcp             1.1.3                h516909a_0    conda-forge
xorg-libxext              1.3.4                h516909a_0    conda-forge
xorg-libxt                1.2.0                h516909a_0    conda-forge
xorg-xextproto            7.3.0             h14c3975_1002    conda-forge
xorg-xproto               7.0.31            h14c3975_1007    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
yaml                      0.2.5                h516909a_0    conda-forge
yapf                      0.30.0             pyh9f0ad1d_0    conda-forge
zeromq                    4.3.3                h58526e2_3    conda-forge
zipp                      3.4.0                      py_0    conda-forge
zlib                      1.2.11            h516909a_1010    conda-forge
zstd                      1.4.5                h6597ccf_2    conda-forge

PS if someone could share a code snippet for similar, no rotation just vertically loft-ing up polylines -- would be VERY much appreciated, I am cadquery newbee and still fighting how to do it properly

@Andy-Valentine
Copy link

Hi,

it seems like you are facing the same issue as I described in #520. Loft sometimes flips wires which you assign to it resulting in self-intersecting lofts. And the use of .union() on self-intersecting pieces produces glitches like you described.

I made a workaround which you can lookup in the other thread. Just need to replace .rect() with .polyline()

@adam-urbanczyk
Copy link
Member

This is not related to #520, you can make your code work like so (clean=False in the union):

import cadquery as cq
wp = cq.Workplane("XY").rect(1,2).workplane()
result = None

for i in range(0,5):
    wp2 = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()
    if result == None:
        result = wp2.loft(combine=True)
    else:
        nextpart = wp2.loft(combine=True)
        result = result.union(nextpart,clean=False)
    wp = wp.transformed(offset=cq.Vector(0, -0.5, 1.0),rotate=cq.Vector(10, 0, 0)).rect(1,2).workplane()

@adam-urbanczyk
Copy link
Member

@yarikoptic note that you can also use sweep to get smoothly varying sections

@adam-urbanczyk adam-urbanczyk changed the title .loft() chooses "incorrect" wire? loft() chooses "incorrect" wire? Sep 22, 2022
@adam-urbanczyk adam-urbanczyk linked a pull request Sep 22, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants