How do I find the optimal control points to fit a cubic Bézier curve to a known function?

69 Views Asked by At

I have the function $f(x) = \frac{x^3 − x^2 \sqrt{2 x^2 + 2} + 4 x} {x^2 + 2}$. I want to find the optimal control points $\{P_0, P_1, P_2, P_3\}$ for a cubic Bézier curve $B(t) = (1 − t)³ P_0 + 3(1 − t)² t P_1 + 3 (1 − t) t² P_2 + t³ P_3$ that most closely matches the function over the interval $0 ≤ x ≤ 1$.

I know that $f(0) = 0$ and $f(1) = 1$, so $P_0 = (0, 0)$ and $P_3 = (1, 1)$. I also know that $f′(0) = 2$, so $P_1$ lies on the line $y = 2 x$ and can be represented as $P_1 = (a, 2 a)$, and $f′(1) = 0$, so $P_2$ lies on the line $y = 1$ and can be represented as $P_2 = (b, 1)$. Thus I only need to find two values, $a$ and $b$, to get the full set of four points completely determined.

However, I don't know how to calculate the optimal values of $a$ and $b$ to make the Bézier curve most closely match the function, and I haven't been able to find the answer online.

1

There are 1 best solutions below

0
On

You have to tell us what you mean by “most closely matches”, because there are several possible ways to measure the deviation between two curves.

One simple approach is to choose your $a$ and $b$ so that the Bézier curve interpolates another point on the curve, say the point $Q = \bigl(\tfrac12, f(\tfrac12)\bigr)$.

If we want $B(\tfrac12)= Q$, then we need $$ \frac18P_0 + \frac38P_1 + \frac38P_2 + \frac18P_3 = Q $$ You have decided that you want to match the curve’s start and end points and tangents. This may or may not be a good idea, depending on the definition of “close” that you choose, but let’s go with it, for now. Substituting, we get $$ (0,0) + \frac38(a,2a) +\frac38(b,1) + \frac18(1,1) = \bigl(\tfrac12, f(\tfrac12)\bigr) $$ Now solve for $a$ and $b$.

I don’t claim that this will give you an optimal result. But it’s easy, and “optimal” doesn’t make sense until you decide how you want to measure closeness.