math behind animation curve?

I am writing a program, and I need to know how to find the value on a curve on a given frame. I looked around and found a lot of information about bezier curves, but I only know how to draw them. I cannot seem to figure out how to find the y value for a given x value of the curve (the curve will always be used without overlaping back on itself, like the IPOs in Blender). The problem is that the value of the y componant of the curve is only linked to the x componant by t (a value ranging from 0 to 1 representing the points along the curve.) Since the bezier curve is defined with a third degree polynomial I don’t know how to find a function for t derived from the function for the x componant of the bezier curve to be plugged into the y componant of the bezier curve to find a function who’s curve matches the bezier (and uses the control points), but could return the y value for a given x value.

My head hurts.

Does anyone at least know of the name of a function which would be like this? Or know of how Blender’s IPO curves work? I guess I could download the source code and find it, but I want to be able to understand how exactly this would work. Also, I didn’t just want to take someone else’s code and make it my own. I have never done that before, and I don’t want to start now!

Well for a given x you can use Newton’s Method or similar to find the value of t, then plug that t into the formula for y

But there’s proably a better way…

  • me tries something *
    Hmm, no matter how warped I make the control points, I still can’t get the curve to double back on itself… They’re not true 2D beziers?
    Maybe a 1D bezier, with t as the time axis? That would make calculation easier…

There’s nothing wrong with copying blender’s code (it’s GPL after all) as long as you read it and understand it… It’s the best way to learn!