The red dots are my data:

enter image description here

I know that they are on a Bézier curve of order 5 (6 control points). There are extra restrictions on the 6 control points A,B,C,D,E & F:

  • A & B are on a horizontal line
  • B & C are on a vertical line
  • C & D are on a horizontal line
  • D & E are on a vertical line
  • E & F are on a horizontal line

(the black arrows in the image)

Now there is a lot of material on this site and on the internet on how to do a least squares fit of points to a Bézier curve. But the method in that case is that the first control point is equal to the first data point, and the last control point is on the last data point, which makes it easy to "synchronize" your t variable (that goes from 0 to 1) in your Bézier equation with the data.

But what if we know that the last (most-right) control point is to the right of the last data point? I can do it manually in a flash script or in Geogebra, so it should be doable mathematically. But how?

So to recap: the data ends at the red arrow, but to get the best fit under the restrictions, how do I calculate the control points so the fitted green curve ends at the green arrow?

Probably something related to the fact that the tangent line in the last control point is also horizontal under my restrictions, but yeah..

  • $\begingroup$ Do you want an answer that gives $y$ as a function of $x$? Or do you want $x$ and $y$ as functions of some parameter $t$? The first is easy. The second will get you into the parameter assignment issues discussed in the answer from @fang. $\endgroup$ – bubba Apr 6 '15 at 2:23

Here is how you can fit $y$ as a function of $x$. Suppose that

  • Points A and B have $y$-coordinate $a$
  • Points C and D have $y$-coordinate $b$
  • Points E and F have $y$-coordinate $c$
  • Point A has $x$-coordinate $h$
  • Point F has $x$-coordinate $k$

Let $u = (x-h)/(k-h)$. Then the general equation of a curve of degree 5 that satisies your constraints is: $$ y(u) = a(1-u)^5 + 5au(1-u)^4 + 10bu^2(1-u)^3 + 10bu^3(1-u)^2 + 5cu^4(1-u) + cu^5 $$ for $0 \le u \le 1$.

Now use standard least-squares fitting techniques to find the values of $a$, $b$, $c$ that give the best fit to your data points.


You would be doing the same thing as you would when the last control point is on the last data point. But the parameters assigned to the data point need to be adjusted as they are no longer from 0.0 to 1.0. For example, if you decide that the parameter for the last data point is t=0.5, you can scale the original parameters (that are from 0.0 to 1.0) accordingly.

  • $\begingroup$ Thanks fang, I did that, but my goal is exactly not to have to decide the t-value of the last data point: it should be part of the regression: the fit of the Bézier curve through the last few data points will be better/worse, depending on how far to the right I place the last control point. There is only 1 solution that automatically finds the best way through all points while respecting the restrictions that does not have t ouse any assumptions or manual settings (like the t-value at the last data point). $\endgroup$ – MisterH Apr 3 '15 at 10:17
  • $\begingroup$ Theoretically speaking, the parameters assigned to each data point can be part of the regression as well. But that is not how spline fitting is done typically. In 'normal' spline fitting, we assign parameters first, then use LS fitting (or interpolation) to find the control points. We can always come back to fine tune the parameters based on the fitted result and start some sort of iteration. But in the LS fitting process, the parameter values are typically fixed. $\endgroup$ – fang Apr 3 '15 at 16:21
  • $\begingroup$ So I guess I am looking for the ab-normal way to do this. It really should not require an iterative process. Could you suggest another spline with similar properties that would not have this problem? $\endgroup$ – MisterH Apr 3 '15 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.