mathandy / svgpathtools

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

Split path at turning point #153

Closed jindili closed 3 years ago

jindili commented 3 years ago

Hi, I have a path triangle like path like this: image

And I need to split this path into three parts at turning point P1, P2, P3

paths, attributes = svg2paths('tmp_svg_3.svg')
list_x = []
list_y = []

for path in paths:
    for pathele in path:
        pstart = pathele.start
        pend = pathele.end
        list_x.append(pstart.real)
        list_x.append(pend.real)
        list_y.append(pstart.imag)
        list_y.append(pend.imag)

print("X Min: ", min(list_x))
print("X Max: ", max(list_x))
print("Y Min: ", min(list_y))
print("Y Max: ", max(list_y))

Now I can find the Min, Max value from all start, end points, And need some help to go further.

Here is the svg file used: tmp_svg_3.zip

mathandy commented 3 years ago

Looks like you could just check the unit_tangent vector just before and just after each segment endpoint to look for big changes.

jindili commented 3 years ago

Thanks @mathandy, it works,

Limit_Delta = 0.5
Delta = abs(cmath.phase(pathele.unit_tangent(0)) - lastPhase)
if Delta > Limit_Delta:
      print("Turning Here")
mathandy commented 3 years ago

Great! Glad I could help @jindili