0

How do I converted a digitalized curve into a list of piecewise Bezier curves for export into SVG PATH.

I have a sampled signal which I'd like to present as a polar graph in SVG with Bezier curves.

How do I curve fit this with Bezier curves and export to SVG (real data is a bit less predictable, sin is just an example that looks similar).

from matplotlib import pyplot as plt
import numpy as np

x=np.linspace(0,np.pi*2*5,500)
y=np.abs(np.sin(x)) + np.random.random(x.shape)*0.2
plt.plot(x,y,".")

x,y plot

# polar 
Th = x / 5
r = y + 2

xp = np.cos(Th) * r
yp = np.sin(Th) * r
plt.figure(figsize=(10,10))
plt.plot(xp,yp,".")

enter image description here

pkuhar
  • 581
  • 6
  • 17
  • Does this answer your question? [Bézier curve fitting with SciPy](https://stackoverflow.com/questions/12643079/b%c3%a9zier-curve-fitting-with-scipy) or is that only half the solution? Also have a look at the data science stackexchange: https://datascience.stackexchange.com/questions/8457/python-library-for-segmented-regression-a-k-a-piecewise-regression – Mike 'Pomax' Kamermans Feb 25 '21 at 19:08
  • Not a full solution. It's easy to fit a single bezier,but figuring out where to do split for piecewise and make the connected curves smooth is nontrivial. I ended up rendering to PNG than using potrace to get the svg http://potrace.sourceforge.net/ work pretty well, although a bit slow. – pkuhar Feb 26 '21 at 06:02
  • That it does, and that it is. It is pretty much the grandfather of all Bezier fitting software. Remember to write an answer for this so that other visitors with the same problem can learn about this completely-not-python-or-numpy-related answer =) – Mike 'Pomax' Kamermans Feb 26 '21 at 17:03

0 Answers0