compas icon indicating copy to clipboard operation
compas copied to clipboard

polyline offset bug or extreme edge case ?

Open mattiskoh opened this issue 2 years ago • 0 comments

Describe the bug Disclaimer : This might not be a bug, but does lead to unexpected behavior. I'm personally comparing the functionality of this function with grasshopper's offset curve.

Background: I'm working a lot with polylines originating from mesh - plane slices (using slice_mesh from compas.cgal (trimesh). In my process I wish to offset these polylines (derived from the slice_mesh command) multiple times. As trimesh only works with triangular meshes, I convert my input mesh from quad to tri-mesh. Occasionally the input mesh has an area where 'curvature' is very small, e.g. almost straight, this combined with the slice plane intersecting very close to (but not on) a mesh vertex creates polylines with points very close to one another. These segments area also 'almost' parallel. For a typical scenario of my use case, the polylines are always open and have relatively large angles between segments i.e. not sharp corners.

To me it seems that the root of the problem lies in floating point arithmetic.

Alternatively there are ways around this i.e. clean[rebuild] the polyline however not available in compas, or sort through polyline points after offsetting, using quadmeshes.. I have been struggling with this for a while and have decided that it is an interesting problem worth solving...

If this post is not sufficient I can gladly talk via zoom etc..

To Reproduce

  • Use either .GH file to visualize the issue.. from internalized data, and to compare to GH behavior..
  • attached .py script to reproduce offsets and compare.

Expected behavior Expected behavior is that of Grasshopper's offset polyline curve.

Screenshots see attached polyline offset issue.zip

Desktop (please complete the following information):

  • OS: Windows
  • Python version 3.9.10
  • Python package manager conda:
#
# Name                    Version                   Build  Channel
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
argh                      0.26.2          pyh9f0ad1d_1002    conda-forge
attrs                     21.4.0             pyhd8ed1ab_0    conda-forge
autobahn                  22.2.2             pyhd8ed1ab_0    conda-forge
automat                   20.2.0                     py_0    conda-forge
autopep8                  1.6.0              pyhd8ed1ab_1    conda-forge
bcrypt                    3.2.0            py39hb82d6ee_2    conda-forge
boost-cpp                 1.74.0               h9f4b32c_7    conda-forge
brotli                    1.0.9                h8ffe710_6    conda-forge
brotli-bin                1.0.9                h8ffe710_6    conda-forge
[polyline offset issue.zip](https://github.com/compas-dev/compas/files/8315579/polyline.offset.issue.zip)

bullet-cpp                3.21                 h2e25243_1    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2021.10.8            h5b45459_0    conda-forge
certifi                   2021.10.8        py39hcbf5309_1    conda-forge
cffi                      1.15.0           py39h0878f49_0    conda-forge
cgal-cpp                  5.4                  h3c2f9b9_0    conda-forge
compas                    1.14.1           py39hcbf5309_0    conda-forge
compas_cgal               0.4.0            py39h856da1f_0    conda-forge
compas_fab                0.22.0           py39hcbf5309_1    conda-forge
compas_rrc                1.1.0              pyhd8ed1ab_0    conda-forge
compas_view2              0.4.4            py39hcbf5309_0    conda-forge
constantly                15.1.0                     py_0    conda-forge
contextlib2               0.5.5                      py_2    conda-forge
cryptography              36.0.1           py39h7bc7c5c_0    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
cython                    0.29.28          py39h415ef7b_0    conda-forge
eigen                     3.3.9                h2d74725_1    conda-forge
ezdxf                     0.17.2           py39h2e07f2f_0    conda-forge
flake8                    4.0.1              pyhd8ed1ab_2    conda-forge
fonttools                 4.30.0           py39hb82d6ee_0    conda-forge
freeglut                  3.2.2                h0e60522_1    conda-forge
freetype                  2.10.4               h546665d_1    conda-forge
freetype-py               2.2.0              pyh9f0ad1d_0    conda-forge
hyperlink                 21.0.0             pyhd3deb0d_0    conda-forge
icu                       68.2                 h0e60522_0    conda-forge
idna                      3.3                pyhd8ed1ab_0    conda-forge
imageio                   2.16.1             pyhcf75d05_0    conda-forge
importlib-metadata        4.11.3           py39hcbf5309_0    conda-forge
importlib_resources       5.4.0              pyhd8ed1ab_0    conda-forge
incremental               21.3.0             pyhd8ed1ab_0    conda-forge
intel-openmp              2022.0.0          h57928b3_3663    conda-forge
jbig                      2.1               h8d14728_2003    conda-forge
jpeg                      9e                   h8ffe710_0    conda-forge
jsonschema                4.4.0              pyhd8ed1ab_0    conda-forge
kiwisolver                1.4.0            py39h2e07f2f_0    conda-forge
laspy                     2.1.2              pyh8a188c0_0    conda-forge
lcms2                     2.12                 h2a16943_0    conda-forge
lerc                      3.0                  h0e60522_0    conda-forge
libblas                   3.9.0              13_win64_mkl    conda-forge
libbrotlicommon           1.0.9                h8ffe710_6    conda-forge
libbrotlidec              1.0.9                h8ffe710_6    conda-forge
libbrotlienc              1.0.9                h8ffe710_6    conda-forge
libcblas                  3.9.0              13_win64_mkl    conda-forge
libclang                  11.1.0          default_h5c34c98_1    conda-forge
libdeflate                1.10                 h8ffe710_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libiconv                  1.16                 he774522_0    conda-forge
liblapack                 3.9.0              13_win64_mkl    conda-forge
libpng                    1.6.37               h1d00b33_2    conda-forge
libtiff                   4.3.0                hc4061b1_3    conda-forge
libwebp                   1.2.2                h57928b3_0    conda-forge
libwebp-base              1.2.2                h8ffe710_1    conda-forge
libxcb                    1.13              hcd874cb_1004    conda-forge
libxml2                   2.9.12               hf5bbc77_1    conda-forge
libxslt                   1.1.33               h65864e5_3    conda-forge
libzlib                   1.2.11            h8ffe710_1013    conda-forge
llvmlite                  0.38.0           py39ha0cd8c8_0    conda-forge
lz4-c                     1.9.3                h8ffe710_1    conda-forge
m2w64-gcc-libgfortran     5.3.0                         6    conda-forge
m2w64-gcc-libs            5.3.0                         7    conda-forge
m2w64-gcc-libs-core       5.3.0                         7    conda-forge
m2w64-gmp                 6.1.0                         2    conda-forge
m2w64-libwinpthread-git   5.0.0.4634.697f757               2    conda-forge
matplotlib-base           3.5.1            py39h581301d_0    conda-forge
mccabe                    0.6.1                      py_1    conda-forge
mesh-mould                0.1.0                     dev_0    <develop>
mkl                       2022.0.0           h0e2418a_796    conda-forge
mpfr                      4.1.0                h8d14728_1    conda-forge
mpir                      3.0.0             he025d50_1002    conda-forge
mpmath                    1.2.1              pyhd8ed1ab_0    conda-forge
msys2-conda-epoch         20160418                      1    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
networkx                  2.7.1              pyhd8ed1ab_0    conda-forge
nptyping                  1.4.4              pyhd8ed1ab_0    conda-forge
numba                     0.55.1           py39hb8cd55e_0    conda-forge
numpy                     1.21.5           py39h6331f09_0    conda-forge
openjpeg                  2.4.0                hb211442_1    conda-forge
openssl                   1.1.1l               h8ffe710_0    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pandas                    1.4.1            py39h2e25243_0    conda-forge
pillow                    9.0.1            py39ha53f419_2    conda-forge
pip                       22.0.4             pyhd8ed1ab_0    conda-forge
planarity                 3.0.0.5           hfa6e2cd_1002    conda-forge
pthread-stubs             0.4               hcd874cb_1001    conda-forge
pyasn1                    0.4.8                      py_0    conda-forge
pyasn1-modules            0.2.7                      py_0    conda-forge
pybullet                  3.21             py39h2e25243_1    conda-forge
pycodestyle               2.8.0              pyhd8ed1ab_0    conda-forge
pycollada                 0.7.2              pyhd8ed1ab_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pyflakes                  2.4.0              pyhd8ed1ab_0    conda-forge
pyopengl                  3.1.6              pyh6c4a22f_0    conda-forge
pyopenssl                 22.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.7              pyhd8ed1ab_0    conda-forge
pyrsistent                0.18.1           py39hb82d6ee_0    conda-forge
pyserial                  3.5                pyhd8ed1ab_0    conda-forge
pyside2                   5.13.2           py39hc084194_4    conda-forge
python                    3.9.10          h9a09f29_2_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-planarity          0.4.1            py39hb82d6ee_6    conda-forge
python_abi                3.9                      2_cp39    conda-forge
pytz                      2021.3             pyhd8ed1ab_0    conda-forge
pywin32                   303              py39hb82d6ee_0    conda-forge
pyyaml                    6.0              py39hb82d6ee_3    conda-forge
qt                        5.12.9               h5909a2a_4    conda-forge
roslibpy                  1.3.0              pyhd8ed1ab_0    conda-forge
schema                    0.7.5              pyhd8ed1ab_0    conda-forge
scipy                     1.8.0            py39hc0c34ad_1    conda-forge
service_identity          18.1.0                     py_0    conda-forge
setuptools                60.10.0          py39hcbf5309_0    conda-forge
shapely                   1.8.1.post1              pypi_0    pypi
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.37.1               h8ffe710_0    conda-forge
sympy                     1.10             py39hcbf5309_0    conda-forge
tbb                       2021.5.0             h2d74725_0    conda-forge
tk                        8.6.12               h8ffe710_0    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
trimesh                   3.10.5                   pypi_0    pypi
twisted                   22.2.0           py39hb82d6ee_0    conda-forge
twisted-iocpsupport       1.0.2            py39hb82d6ee_1    conda-forge
txaio                     21.2.1             pyhd8ed1ab_0    conda-forge
typing-extensions         4.1.1                hd8ed1ab_0    conda-forge
typing_extensions         4.1.1              pyha770c72_0    conda-forge
typish                    1.9.3              pyhd8ed1ab_0    conda-forge
tzdata                    2022a                h191b570_0    conda-forge
ucrt                      10.0.20348.0         h57928b3_0    conda-forge
unicodedata2              14.0.0           py39hb82d6ee_0    conda-forge
vc                        14.2                 hb210afc_6    conda-forge
vs2015_runtime            14.29.30037          h902a5da_6    conda-forge
watchdog                  2.1.6            py39hcbf5309_1    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
xorg-libxau               1.0.9                hcd874cb_0    conda-forge
xorg-libxdmcp             1.1.3                hcd874cb_0    conda-forge
xz                        5.2.5                h62dcd97_1    conda-forge
yaml                      0.2.5                h8ffe710_2    conda-forge
zipp                      3.7.0              pyhd8ed1ab_1    conda-forge
zlib                      1.2.11            h8ffe710_1013    conda-forge
zope.interface            5.4.0            py39hb82d6ee_1    conda-forge
zstd                      1.5.2                h6255e5f_0    conda-forge```

mattiskoh avatar Mar 21 '22 13:03 mattiskoh