Lookup table help

» Mon Dec 01, 2008 4:03 pm

Hi
I'm wondering how I could make an array do linear interpolation (ideally a 'cubic spline' or something) between the two closest known values to fill in the gaps from a limited set of data. What I'm trying to make is a torque/rpm lookup table for a car game.
Cheers!
B
1
S
1
G
4
Posts: 4
Reputation: 1,183

» Mon Dec 01, 2008 6:46 pm

Well, suppose you want to get the value interpolated at X = 4.7. First you want the integer part and float part (4 and 0.7), which are floor(X) and X - floor(X) respectively.

The expression lerp(a, b, x) does linear interpolation - so we want to interpolate between the two nearest array entries, floor(X) and floor(X) + 1.

Which is something like:

lerp(Array(Floor(X)), Array(Floor(X) + 1), X - floor(X))
Scirra Founder
B
413
S
244
G
92
Posts: 25,082
Reputation: 199,732

» Wed Dec 03, 2008 12:43 pm

Thanks, but I couldn't get that to work. I'm not sure it's what i need.
I have 12 or so known values with 500 unknown between each, all 6000 values need numbers.
Basically increasing 12 numbers to a resolution of 6000.
I might need a specific example, I'm pretty dumb.
B
1
S
1
G
4
Posts: 4
Reputation: 1,183

» Wed Dec 03, 2008 3:30 pm

The lerp function linearly interpolates between values, so you'd get an unlimited number of in-between values - if you want the 3000th (half way) value between the 8th and 9th item, you'd use that formula with X = 8.5 (ie. half way between 8 and 9). Does that help?
Scirra Founder
B
413
S
244
G
92
Posts: 25,082
Reputation: 199,732