# Y value in Cubic Spline given X

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

## Recommended Posts

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]

##### Share on other sites
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.

##### Share on other sites
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).

##### Share on other sites
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).

##### Share on other sites
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;		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.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011722
• ### Who's Online (See full list)

There are no registered users currently online

×