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?


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.

  • $\begingroup$ First of all, thank for your response. Then, I'm sorry for being this late but I had no time recently. Now, let's get to the point: your first suggestion (the one with h and k) doesn't work. I need way better approximation. However, the results you got using the second technique are just perfect. I really need to know how you got them $\endgroup$ – DoNotDownvote_JustUpvote Oct 10 '17 at 15:01

Hint: You have the derivatives at the extreme points.

  • $\begingroup$ Unfortunately, I haven't studied derivatives that well yet... I barely know what they are. Could you please show me the process? $\endgroup$ – DoNotDownvote_JustUpvote Oct 5 '17 at 19:45
  • $\begingroup$ I found another question about bezier curves that uses derivatives. Is that what you meant? PS: the 5 minutes available to edit my previous comment were over $\endgroup$ – DoNotDownvote_JustUpvote Oct 5 '17 at 20:00
  • $\begingroup$ I have the tangent lines at the extreme points. What's next? $\endgroup$ – DoNotDownvote_JustUpvote Oct 6 '17 at 13:54
  • $\begingroup$ @DoNotDownvote_JustUpvote, you have the exact tangent vectors, not just the tangent lines. This is 4 numbers. Set up a linear system to find the four numbers that define $P_2$ and $P_3$. $\endgroup$ – lhf Oct 6 '17 at 14:00
  • $\begingroup$ Ok, I'm lost. I'm searching on the internet but I don't get what's a tangent vector and, moreover, how to calculate it. $\endgroup$ – DoNotDownvote_JustUpvote Oct 6 '17 at 14:43

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.