# Error in Bicubic Interpolation algorithm

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

## Recommended Posts

Hi there, I'm implementing a bicubic interpolation algorithm that maps textures in a ray tracer. I'm using the algorithm as described in this post: http://www.gamedev.net/community/forums/topic.asp?topic_id=336744&whichpage=1#2197591 which seems very straightforward to me, and the results look great. However, for some values, the 'cubic' function returns values outside the input values, which should not be possible, but I'm unable to figure out what is wrong. Can anybody help me out and have a look at that function? I'll duplicate it here for convenience. A combination that returns a negative value is 254,8,8,8 and 0.3:
        public static float Cubic(int v0, int v1, int v2, int v3, float t)
{
int p = (v3 - v2) - (v0 - v1);
int q = (v0 - v1) - p;
int r = v2 - v0;
int s = v1;
float tSqrd = t * t;
return (p * (tSqrd * t)) + (q * tSqrd) + (r * t) + s;
}


##### Share on other sites
I'm not a math genius, but isn't this expected for cubic interpolation? With the step from 254 to 8, you'll get a very steep tangent at v1, so the interpolated value will first sweep downward a bit from v1 before catching up and aiming for v2 again.

Are you by any chance mixing this up with quadratic interpolation?

Quadratic interpolation would be guaranteed to stay between the left and right interpolated values because it doesn't use tangents.

    public static float quadraticInterpolate(float a, float b, float t) {      float t2 = t * t;      float t3 = t2 * t;      return a * (2 * t3 - 3 * t2 + 1) + b * (3 * t2 - 2 * t3);    }

1. 1
2. 2
3. 3
frob
14
4. 4
5. 5
Rutin
12

• 12
• 9
• 57
• 14
• 15
• ### Forum Statistics

• Total Topics
632112
• Total Posts
3004177

×