mathandy / svgpathtools

A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves.
MIT License
543 stars 137 forks source link

Intersect_method for Arc not fully implemented: interscections returned outside of the arc #121

Open piscvau opened 4 years ago

piscvau commented 4 years ago

The doc string invite people to mention their interest with such a feature. I am extremely interested in such a feature. I am developing an application for machine knitting which uses svg files as input, for example Inkscape files. Svgpathtools is really a great tool . But Arcs are much involved in designing patterns and machine knitting calculations involve many cutting of the shape with horizontal lines!... Unfortunately my competences in maths are no sufficient to be able to submit an implementation. However I am able to offer to test the implementation. Here is a first issue : it seems intersections points outside of the Arc are returned by Path.intersect.

https://bpa.st/MKOQ contains 2 files : the python code and the svg file generated with wsvg to visualize the intersection points.

piscvau commented 3 years ago

Hello I Have written extensive tests for function intersect with arc, cubicBezier and quadratic Bezier. The test file is in my forked repository www.github.com/piscvau under the name tests_path_intersect_with_horizontal.py. The results are pretty bad ; there are 3 out of 8 tests which fail for cubicBezier. and many more which fail for Arc which is coherent with the documentation in the code saying that the intersect is not fully implemented. I wrote those tests with the hope that someone would comlete the code for the arc and correct if for CubicBezier. I do need badly this intersect function for my application and yet I do not have mathmatical expertise to do the code. So if someone is willing???? The person who developped the spli_extremum_y function for me said scipy might be useful to enhance terminate the intersect code for the arc.

mathandy commented 3 years ago

Hi @piscvau, this tests_path_intersect_with_horizontal.py file looks quite nice. Could you give me a simple example or two I can paste into my terminal to play around with?

piscvau commented 3 years ago

Hello Here is a list of all tests which fail. failing_tests.txt

you will find the coordinates of the curves (arc or Bezier) in the test code. for example the test i2_arc_30_0_0](i=2) fails. the coordinates of the curve are in the class Test Intersect_Arc parse_path . It corresponds to the arc with a rotation angle of 30 and flag 0 0 . parse_path(f"M 50, 200 a 100, 50 0 {flag} 250,50")

All tests compute the intersection with 3 horizontal lines. 1 passes through the curve start, the second through the curve end the third roughly in the middle of the curve. The lines are computed in the compute_lines method. for the first failing test i2_arc_30_0_0 the 3 computed lines are : Line(start=100j, end=(1150+100j)) Line(start=125j, end=(1150+125j)) Line(start=150j, end=(1150+150j)

The coordinates of the Bezier curve corresponding to the tests which fail are in the class Test_Intersect_quadratic_bezier parse_path which are numbered starting with 1.

I hope this information helps. Piscvau

piscvau commented 3 years ago

Hi @mathandy Did the above message provide any help. Do you foresee any possible progress with the finishing of arc.intersect_method?

piscvau commented 3 years ago

I would really appreciate if the owner of the repository could please comment on whether the completion of the arc intersect is envisaged in the package or not envisaged at all. Given the comments that are in the package I believe this would be fair to package users!.....