Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting from CubicBezier to Poly1D doesnt work correctly #193

Open
Fischchen opened this issue Dec 27, 2022 · 0 comments
Open

Converting from CubicBezier to Poly1D doesnt work correctly #193

Fischchen opened this issue Dec 27, 2022 · 0 comments

Comments

@Fischchen
Copy link

Hey everyone!

I'm currently having a problem with this libary where CubicBezier curves when turned into poly1d sometimes end up being linear or end in other garbage.

This is the wanted path:
image
And this is what I get:
image

As you can see, for some reason it converts all curves into diagonals or some weird mix.
I'd appreciate any help or pointers in the right direction.
This is my Code:

import turtle

import numpy as np
from svgpathtools import svg2paths, Line, CubicBezier


from pprint import pprint
from PIL import Image, ImageDraw

s = turtle.getscreen()
t = turtle.Turtle()
t.speed(0)

paths, attributes = svg2paths("Logo - Kopie.svg")  # type: ignore


scale_factor = -0.25

t.penup()
for path in paths:
    for curve in path:
        pprint(curve)
        if isinstance(curve, Line):
            t.goto(-curve.start.real * scale_factor, curve.start.imag * scale_factor)
            t.pendown()
            t.goto(-curve.end.real * scale_factor, curve.end.imag * scale_factor)
            t.penup()

        elif isinstance(curve, CubicBezier):
            #! Something is wrong here
            poly_curve = curve.poly()
            poly_curve = np.poly1d(poly_curve)
            print(poly_curve)
            x_values = np.linspace(curve.start.real, curve.end.real, 250)
            y_values = np.linspace(curve.start.imag, curve.end.imag, 250)

            t.goto(-curve.start.real * scale_factor, curve.start.imag * scale_factor)
            t.pendown()
            for x, y in zip(x_values, y_values):

                t.goto(-x * scale_factor, y * scale_factor)
            t.penup()

input("Press Enter to continue...")
print("Done")

Best regards,
Fischchen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant