0

I'm using the answer posted here to fit a curve through a set of datapoints

import numpy as np
import matplotlib.pyplot as plt
from scipy.special import binom

def Bernstein(n, k):
    """Bernstein polynomial.

    """
    coeff = binom(n, k)

    def _bpoly(x):
        return coeff * x ** k * (1 - x) ** (n - k)

    return _bpoly


def Bezier(points, num=200):
    """Build Bézier curve from points.

    """
    N = len(points)
    t = np.linspace(0, 1, num=num)
    curve = np.zeros((num, 2))
    for ii in range(N):
        curve += np.outer(Bernstein(N - 1, ii)(t), points[ii])
    return curve
xp = np.array([2,3,4,5])
yp = np.array([2,1,4,0])
x, y = Bezier(list(zip(xp, yp))).T

plt.plot(x,y)
plt.plot(xp,yp,"ro")
plt.plot(xp,yp,"b--")

plt.show()

I would like to find the polynomial function of the fitted curve.

Suggestions on how to do this will be really helpful.

Natasha
  • 1,111
  • 5
  • 28
  • 66
  • 1
    What do you mean with "the polynomial function of the fitted curve"? If you have the bezier coefficients, you're done. The rest is [just boilerplate](https://pomax.github.io/bezierinfo/#explanation). – Mike 'Pomax' Kamermans Sep 06 '22 at 18:11
  • @Mike'Pomax'Kamermans The primer shared is extremely useful. Thanks so much for the wonderful write-up. Could you please let me know if there is a non-parametric form of the Bezier method? – Natasha Sep 07 '22 at 08:42
  • 1
    A Bezier curve is by definition a multi-dimensional parametric curve with the same basis function in each dimension, so strictly speaking "no" (which is why you use it for contour fitting, but generally not for data fitting, you use normal polynomial regression to get "the" best fitting normal polynomial) – Mike 'Pomax' Kamermans Sep 07 '22 at 14:57

0 Answers0