Does anyone know how to fit a cubic Bezier curve to a given set of data points? If so, I'd appreciate some coaching on the methodology.(adsbygoogle = window.adsbygoogle || []).push({});

Bezier curves have separate equations for x and y in a parametric variable t that varies from 0 to 1:

x = at^{3}+ bt^{2}+ ct + d

y = et^{3}+ ft^{2}+ gt + h

the 8 unknowns are a function of 4 control points:

x_{c}= (x_{0}, x_{1}, x_{2}, x_{3})

y_{c}= (y_{0}, y_{1}, y_{2}, y_{3})

thus, for a given set of values for the 4 control points, all 8 coefficients are determined and the x,y values of the Bezier curve can be calculated.

But, the equations are de-coupled in the sense that a,b,c,d depend ONLY on the x-values of the 4 control points (x_{c}) and e,f,g,h depend ONLY on the y-values of the 4 control points (y_{c}).

I've been trying (in vain so far) to set up the curve fitting as a least squares problem. Part of the problem is the difficulty of finding the right value of t for a given x of a data point being fitted, since x is cubic in t. One approach is to solve the cubic equation, but I've found that Newton-Raphson works quite well.

It turns out that solving for the y-values of the 4 control points (y_{c}) is a straightforward linear least squares problem because the equations are linear in y_{c}. Thus, for an initial guess of the x-values of the control points (x_{c}) the values of t for each data point can be determined (e.g. by Newton-Raphson), and in a single least squares calculation, the y-values of the control points (y_{c}) can be determined to minimize the square error in vertical distance between the data points and the calculated curve.

The problem is how to get updated x-values of the control points (x_{c}).

I've searched the internet extensively and though have found references to least squares solutions to Bezier curves, I've never found enough detail to figure out how to do it.

Any/all hints/tips would be appreciated. Perhaps an approach other than least squares is better. Thanks!

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Data Fitting with Bezier curve

**Physics Forums | Science Articles, Homework Help, Discussion**