OK, I was able to create a relatively simple example, all done with Excel. First, some preliminaries. The standard form of a quadratic Bezier is: B(t) = (1-t)
2P
0 + 2t(1-t)P
1 + t
2P
2……….0 ≤ t ≤ 1
Expanding and collecting terms, the equation can be put in classic polynomial form: B(t) = at
2 + bt + c, where:
a = P
0 – 2 P
1 + P
2
b = 2P
0 + 2 P
1
c = P
0
The above expressions really represent two equations, one for x and the other for y:
x(t) = a
xt
2 + b
xt + c
x
y(t) = a
yt
2 + b
yt + c
y
Calling the control points P
0 = (p
0x, p
0y), P
1 = (p
1x, p
1y), P
2 = (p
2x, p
2y)
a
x = p
0x – 2 p
1x + p
2x
a
y = p
0y – 2 p
1y + p
2y
b
x = 2p
0x + 2 p
1x
b
y = 2p
0y + 2 p
1y
c
x = p
0x
c
y = p
0y
Thus, we’ve established a relationship between the Bezier control points the polynomial coefficients.
Least Squares analysis involves fitting a desired function f to a set of points p = [p
1, p
2, ..p
n] = [(x
1, y
1), (x
2, y
2), … (x
n, y
n)]. A standard means of determining ‘quality of fit’ is to sum the squares of the differences in vertical distance between the data points and the points generated by the function:
sum of squares = (f(x
1) - y
1)
2 + (f(x
2) - y
2)
2 … + (f(x
n) – y
n)
2
The idea is to make the sum of squares as small as possible. The key is that the same value of x must be used for each point, so only vertical distance is being used). This is a challenge when using parametric curves because x is a function of the independent variable t. Thus, for each data point, the proper t needs to be determined such that the resulting x is identical to the x of the data point.
Here is a specific example. Suppose we wish to fit a quadratic Bezier to the following data points:
[(x
1, y
1), (x
2, y
2), (x
3, y
3), (x
4, y
4), (x
5, y
5)] = [(0, 0), (0.2, 0.01), (0.7, 0.4), (0.9, 0.8), (1, 1)]
Here is the simple approach I used:
1. Make an initial guess at control point P
1 (P
0 = (0, 0) and P
2 = (1, 1) are given). I used P
1 = (0.7, 0) as an initial guess.
2. Calculate the polynomial coefficients:
a
x = p
0x – 2 p
1x + p
2x = 0 – 2(0.7) + 1 = -0.4
b
x = 2p
0x + 2 p
1x = 2(0) + 2(0.7) = 1.4
c
x = p
0x = 0
3. Generate x, y points for t = 0 to 1 and plot the Bezier curve. Plot the original data points and see how close the fit is. (It is instructive to play around with various values for p
1x and p
1y and see how the shape of the curve changes in relation to the data points).
4. Calculate the sum of squares. Here’s the tricky part. To calculate (f-y)
2, you need to find t that results in the same x as the data point. For example, x
2 = a
xt
22 + b
xt
2 + c
x. To find the t
2 that produces x
2, a quadratic equation needs to be solved (i.e.[ –b ± sqrt(b
2-4ac)]/2a). This needs to be done for all interior points (the end points are already known). Thus, for the initial control points used:
t
1 = 0...==> x
1 = 0, y
1 = 0
t
2 = 0.149...==> x
2 = 0.2, y
2 = 0.022
t
3 = 0.604...==> x
3 = 0.7, y
3 = 0.365
t
4 = 0.849……….==> x
4 = 0.9, y
4 = 0.72
t
5 = 1……….==> x
5 = 1, y
5 = 1
Now we can calculate the sum of squares = (0 – 0)
2 + (0.022 – 0.01)
2 + (0.365 – 0.04)
2 + (0.72 – 0.8)2 + (1 – 1)
2 = 0.008
5. Try new values of P
1 until the sum of squares is minimized. Each time that p
1x is changed, three sets of quadratic equations must be solved to find t associated with each x. As an example, suppose we try P
1 = (0.6, 0). Then:
a
x = p
0x – 2 p
1x + p
2x = 0 – 2(0.6) + 1 = -0.2
b
x = 2p
0x + 2 p
1x = 2(0) + 2(0.6) = 1.2
c
x = p
0x = 0
t
1 = 0...==> x
1 = 0, y
1 = 0
t
2 = 0.172...==> x
2 = 0.2, y
2 = 0.029
t
3 = 0.655...==> x
3 = 0.7, y
3 = 0.429
t
4 = 0.879……….==> x
4 = 0.9, y
4 = 0.772
t
5 = 1……….==> x
5 = 1, y
5 = 1
sum of squares = (0 – 0)
2 + (0.029 – 0.01)
2 + (0.429 – 0.04)
2 + (0.772 – 0.8)2 + (1 – 1)
2 = 0.002
If Excel is used and the formulas are set up correctly, the quadratic equations will be automatically solved each time P
1 is changed.
For this example, I just used the Excel built-in solver function to minimize the cell containing the sum of squares and allowing p
1 (i.e. p
1x and p
1y) to be changed. The net result:
P
1 = (0.543, -0.108)
(a
x, a
y) = (-0.087, 1.216)
(b
x, b
y) = (1.087, -0.216)
(c
x, c
y) = (0, 0)
sum of squares = 0.001
It should be noted that forcing the end points of the Bezier curve to be coincident with the first and last data points is an artificial restriction that limits the quality of fit. If p
0y and p
2y are also allowed to be adjusted, a better fit can be achieved. Also, since parametric curves are so flexible, it is relatively easy to get into a situation where the best fit curve has a loop somewhere in the middle or the curve otherwise takes on a completely unexpected and undesirable shape. Such are the caveats of least squares fitting with parametric curves.

.