- #1
- 1,008
- 7
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.
Bezier curves have separate equations for x and y in a parametric variable t that varies from 0 to 1:
x = at3 + bt2 + ct + d
y = et3 + ft2 + gt + h
the 8 unknowns are a function of 4 control points:
xc = (x0, x1, x2, x3)
yc = (y0, y1, y2, y3)
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 (xc) and e,f,g,h depend ONLY on the y-values of the 4 control points (yc).
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 (yc) is a straightforward linear least squares problem because the equations are linear in yc. Thus, for an initial guess of the x-values of the control points (xc) 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 (yc) 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 (xc).
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!
Bezier curves have separate equations for x and y in a parametric variable t that varies from 0 to 1:
x = at3 + bt2 + ct + d
y = et3 + ft2 + gt + h
the 8 unknowns are a function of 4 control points:
xc = (x0, x1, x2, x3)
yc = (y0, y1, y2, y3)
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 (xc) and e,f,g,h depend ONLY on the y-values of the 4 control points (yc).
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 (yc) is a straightforward linear least squares problem because the equations are linear in yc. Thus, for an initial guess of the x-values of the control points (xc) 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 (yc) 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 (xc).
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!
Last edited: