daxliar 122 Report post Posted June 3, 2009 Hi all. I'm working with cubic curves extracted from a character animations. For each couple of keyframes i get the four control points to evaluate che curve. I'm going a bit crazy trying to find the Y value of the curve given an X value. I've only found documentation about find a point on the curve given the parameter t with 0 <= t <= 1 where t=0 means the starting point and t=1.0 the end point. What it the realtion between t and X? Is there a function X(t)? Is it the right way? Any help will be appreciated! [Edited by - daxliar on June 4, 2009 1:59:56 PM] 0 Share this post Link to post Share on other sites
Numsgil 501 Report post Posted June 5, 2009 What do you mean by X value? Do you mean like where sin(x) = y, or do you mean where the curve(t) = some x,y,z vector, and you want to find the t such that the x value of the interpolated vector == some given value. 0 Share this post Link to post Share on other sites
eq 654 Report post Posted June 8, 2009 I had to deal with this some time ago and yes you need to solve for t in the equation: x = FX(t).Then to get y use: y = FY(t)Something like this:t = solve(FX, x);y = FY(t);A cubic equation solver is needed find t given an x.Also note that there might be up to three real roots in that equation, however most art packages make sure that there's only one valid t (within the range 0 to 1). 0 Share this post Link to post Share on other sites
daxliar 122 Report post Posted June 9, 2009 Ok, thanks.If you already soled the problem, can you suggest me the way to find the equation needed to get t given an x? I'm going crazy...Now I'm sampling the curve with some value of t and then I find a specific value of X with a liner interpolation between the sampled data. (I think isn't a good idea). 0 Share this post Link to post Share on other sites
Numsgil 501 Report post Posted June 9, 2009 Check out this link. 0 Share this post Link to post Share on other sites
eq 654 Report post Posted June 11, 2009 Here's the code I use:float CubicPatch::findTimeForX(const float a, const float b, const float c, const float d, const float x){ float roots[3]; const uint rootCount = CubicEquation::findRealRoots(roots, a, b, c, d - x); int count = 0; uint i; for (i = 0; i < rootCount; ++ i){ const float f = roots[i]; if ((f >= 0.0f) && (f <= 1.0f)) return f; ++ count; if (f < 0.5f) count -= 2; } return count > 0 ? 1.0f : 0.0f;}As for solving a cubic equation I bet that Dave Eberly comes to the rescue. 0 Share this post Link to post Share on other sites