Ok so I’ve been looking into interpolation lately. Sadly almost every article I’ve read only discusses interpolation at a decimal level 0.0 to 1.0 to be exact. I would like to interpolate whole number integers regardless of how big they are or if there negative or whatever. I’ve accomplished this with linear interpolation:
public int interpolate(int y1, int y2, int length, int x){
return y1 + x * (y2 - y1) / (length-1);
}
However I’m stuck with cosine interpolation. This great article talks about cosine interpolation however it’s on a system of numbers from 0.0 to 1.0 as stated above. Here is what I have so far:
public int interpolate(int y1, int y2, int length, int x){
int v = (int)(y2 - Mathf.Cos(x * 3.1415f))/2;
return (y1 + x * (y2 - y1) / (length-1)) * v;
}
It doesn’t work though it returns an almost random number with no real direction making it not smooth at all. This is where I need your help. Long story short: How do I make a cosine interpolation function that deals with integers?
Output of cos θ varies from 1 to -1 to 1 as its input ranges from [0, 2π]. We need something from [0, 1]. So
You’ve get a nice function that goes from 0 to 1. The rest is transforming the argument.
Essentially you need