SebKuzminsky / pycam

Other
340 stars 98 forks source link

Polygon offsetting / pocketing fails #114

Open sumpfralle opened 6 years ago

sumpfralle commented 6 years ago

The self-made polygon offsetting algorithm in pycam is fragile und fails to work even with seemingly trivial polygons.

Some problems of the algorithm are discussed in #79.

The offsetting algorithm fails with the following symptoms:

The polygon offsetting algorithm in pycam is broken beyond repair. We need to replace it with something stable.

The following external libraries could provide an alternative:

I propose to use this issue / thread in the following way:

SebKuzminsky commented 6 years ago

I've spent the past several weeks playing with https://github.com/mathandy/svgpathtools.

It's a pure python module that reads SVG files and parses the paths into an internal representation. The path itself and the path elements (lines, elliptic arcs, and quadratic & cubic splines) are all represented by python classes with many geometric primitives defined on them.

There is currently no path offsetting function, but the required primitives are there, and some sample code is provided that implements the beginning of a path offsetting function. I extended that example code into a rough implementation of Chen & McCains algorithm "Polygon Offsetting by Computing Winding Numbers".

This exposed several bugs in svgpathtools (mathandy/svgpathtools#35, mathandy/svgpathtools#37, mathandy/svgpathtools#41, and mathandy/svgpathtools#43). I fixed some but not all of the bugs (mathandy/svgpathtools#40, mathandy/svgpathtools#42), but the fixes have not been accepted (yet?).

The result so far is a robust path offsetting function, and a simple pocketing function based on it. The only remaining flaw I know of is a bug in Arc/Arc intersections (mathandy/svgpathtools#43) that often crashes the offsetting code.

The offsetting algorithm isn't tied to svgpathtools, and we may be better off using a different geometry library, hopefully one that's more actively maintained.

offset4 offset3 offset2 offset1 offset0

jf--- commented 6 years ago

duly impressive work, what a cool reference to Chen & McCains algorithm. could you perhaps share a pointer to the pocketing example you mention?

SebKuzminsky commented 6 years ago

The pocketing is implemented in a program called svg2gcode, in this repo: https://github.com/SebKuzminsky/svg2gcode

It's super quick and hacky, and not really intended for anything other than me playing with svgpathtools and testing the offsetting algorithm. You've been warned!