Polygon clipping and offset #1151
Replies: 7 comments 1 reply
-
Hi, Yes, that would indeed be useful. Ideally this would be done through the plugin mechanism. This means that we would define a bunch of pluggable functions in Perhaps you can help get this started by compiling a list of useful pluggables? |
Beta Was this translation helpful? Give feedback.
-
My though exactly, so we can also offer an implementation using Rhino. I can compile a list of pluggables that is would be defined using one of the aforementioned libraries and post a new comment! I've been working with @baehrjo using shapely, and have already developed a few function in this direction. |
Beta Was this translation helpful? Give feedback.
-
Shapely defines the following methods for geometry clipping:
For offset, it defines the buffer method. Additionally, @baehrjo has developed a function for a multi-offset, where a list of distances can be entered, one per polygon side, resulting in a non-uniform offset. Wrapping these methods should be relatively straightforward, perhaps with the exception of handling multipolygons (a collection of polygons) and polygons with holes. In our workflow, a polygon with holes is represented as a tuple containing first the outer polygon and then any hole polygon or None, and a multipolygon is a tuple containing tuples of the previously defined polygons. |
Beta Was this translation helpful? Give feedback.
-
check the prerelease of COMPAS 2.0 (latest changes on the main branch). some 2D booleans already implemented with shapely as backend... |
Beta Was this translation helpful? Give feedback.
-
from compas.geometry import Polygon, Translation
from compas_view2.app import App
a = Polygon.from_sides_and_radius_xy(4, 1.0)
b = Polygon.from_sides_and_radius_xy(4, 1.0)
b.transform(Translation.from_vector([0.5, 0, 0]))
c = a.boolean_intersection(b)
d = a.boolean_symmetric_difference(b)
viewer = App()
viewer.add(c)
for item in d:
mesh = item.to_mesh(earclip=True)
viewer.add(mesh, facecolor=(1, 0, 0), show_lines=False)
viewer.run() |
Beta Was this translation helpful? Give feedback.
-
It looks very exciting! Let me know if I could help somehow with other boolean or offset methods :) |
Beta Was this translation helpful? Give feedback.
-
Hello! I am working on a project that requires plenty of (mostly 2D) polygon clipping and offsetting operations. I know that COMPAS already supports offsetting, however, it can get pretty messy when the resulting offset is a complex or concave polygon. I was wondering if you have considered adding such operations as native COMPAS functions or perhaps creating an extension wrapping functionality either from Shapely or Clipper2 libraries. I did some tries with these two, and the result in offsetting is much more consistent with what you'd get from running it in Rhino for instance (I used Pyclipper as a wrapper). The results are as follows:
In black you can see the original polygon, red the COMPAS offset, blue the Pyclipper, and green the Shapely offset.
Beta Was this translation helpful? Give feedback.
All reactions