[Math] Find control points of Bézier curve in order to approximate a function

bezier-curvecalculus

Let y(t) be a function that goes like $\dfrac{a t} { b + a t – b t}$
and has domain $[0, 1]$ and codomain $[0, 1]$ for every pair of a and b values.

For example, when a = 2 and b = 1 the function looks like
enter image description here

I want to translate the function to a cubic Bézier curve with P1 = { 0, 0 } and P4 = { 1, 1 } (which is $x(t) = 3 t (1-t)^2 P_{2x} + 3 t^2 (1 – t) P_{3x} + t ^ 3$ and $y(t) = 3 t (1-t)^2 P_{2y} + 3 t^2 (1 – t) P_{3y} + t ^ 3$ in the algebraic form) but I'm not able to wrap my head around it. How can I calculate the two remaining control points coordinates?

Could you please show me the process to find them?

Best Answer

Calculate the derivative of your function $y(t)$ with respect to $t$. Set $t=0$ and $t=1$ in the resulting expression, and this will give you the slope of your curve at its start and end points. You will find that these slopes are $a/b$ at $t=0$ and $b/a$ at $t=1$.

So, at its start point (where $t=0$), your curve's tangent line has equation $y=(a/b)x$. It's a good idea to put the second control point of the Bézier curve somewhere on this line. This will ensure that the direction of the Bézier curve matches the direction of the original curve at $t=0$. This means that the second control point should have coordinates $(hb,ha)$, where $h$ is some number that we don't know, yet.

By similar reasoning, the third Bézier control point should have coordinates $(1-ka, 1-kb)$, where $k$ is another number that we don't yet know.

There are various ways to choose $h$ and $k$ to improve the accuracy of the approximation. But there are also several ways to measure "accuracy", and you didn't tell us which one you want to use.

If we set $h= \tfrac1{15}\sqrt{10}$ and $k=\tfrac1{15}\sqrt{10}$, then the first and last legs of the Bezier control polygon will have length that is 1/3 of the length of the chord joining the curve end-points, which is often a decent choice. This gives
$P_2 = (0.42164, 0.21082)$
$P_3 = (0.79818, 0.57836)$
See if you're happy with the results you get from this. If you're not, tell us what's wrong with them, and we can try something a bit more sophisticated.

Using a much more complex technique, I got control points
$P_2 = (0.457527667343, 0.228763833672)$
$P_3 = (0.771236166328,0.542472332657)$
but the simpler approach above might be good enough for your purposes.