Jump to content
  • Advertisement
Sign in to follow this  
RPTD

How to evaluate a Bezier Curve used as mapping function

This topic is 3065 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Blender uses for example for animations bezier curves. This is though not a normal curve but a mapping function type curve so the shape is limited so the curve is usable to uniquely map an X value to an Y value. Now I implemented a bezier curve like this which is mostly a common bezier curve just that I make sure the required constraints are met. My problem now is though how to evaluate the curve. A bezier curve Bi(t) yields for the i-th segment the (x,y) value for the given position t along the curve. For the mapping though we are not interested in evaluating Bi(t) but actually y=Bi(x). For a given X value there is exactly one t value and vice versa. So the task at hand is to calculate the t value which corresponds to the given X value. Now this boils down to solving the following equation: 0 = a*(t**3) + b*(t**2) + c*t + d whereas the constants a, b, c, and d are: a = p1.x - 3*p2.x + 3*p3.x - p4.x b = 3*p2.x - 6*p3.x + 3*p4.x c = 3*p3.x - 3*p4.x d = p4.x - x whereas p1, p2, p3 and p4 are the segment end points (p1,p4) and the respective handles (p2,p3) and x the input value with p1.x <= x <= p4.x . From a math article on the website I figured out that this 3rd degree equation can be solved using the following ( using a substitution x=y-b/(3a) ): p = (3*a*c - b**2)/(3*(a**2)) q = (2*(b**3))/(27*(a**3)) - (b*c)/(3*(a**2)) + d/a with the discriminant D = (q/2)**2 + (p/3)**3 which is positive or 0 due to the restrictions on the curve due to usage as a mapping function (limited in the sense as there can be at max one real solution and 2 imaginary ones). This gives then u = 3rd-root( -q/2 + 2nd-root(D) ) v = 3rd-root( -q/2 - 2nd-root(D) ) y = u + v and therefore (after back-substitution) t = y - b/(3*a) Now this does not seem to work at all. Furthermore this contains a square roots and cubic roots. Now what interests me is: - Would this procedure above actually return the correct t to obtain B(t) for a given x? - If not, what did I do wrong? - Is there a better way to evaluate a bezier curve used as mapping function?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!