views:

169

answers:

4

I've found functions which follow the pattern of 1 / bc produce nice curves which can be coupled with interpolation functions really nicely.

The way I use the function is by treating 'c' as the changing value, i.e. the interpolation value between 0 and 1, while varying b for 'sharpness'. I use it to work out an interpolation value between 0 and 1, so generelly the function I use is as such:

float interpolationvalue = 1 - 1/pow(100,c);
linearinterpolate( val1, val2, interpolationvalue);

Up to this point I've been using a hacked approach to make it 'work' since when interpolation value = 1 the value is very close to but not quite 0.

So I was wondering, is there a function in the form of or one which can reproduce similar curves to the ones produced by 1 / bc where at c = 0 result = 1 and c = 1 result = 0.

Or even C = 0, result = 0 and C = 1 result = 1.

Thanks for any help!

+1  A: 

1 - c ^ b with small values for b? Another option would be to use a cubic polynomial and specifying the slope at 0 and 1.

Andreas Brinck
A: 

Hi

In real numbers, the ones that mathematician use, no function of the form you specify is ever going to return 0, division can't do that. (1/x)==0 has no real solutions. In floating point arithmetic, the poor relation of real arithmetic that computers use, you could write 1/(MAX_FP_VALUE^1) which will give you as close to 0 as you are ever going to get (actually, it might give you a NaN or one of the other odd returns that IEEE 754 allows).

And, as I'm sure you've noticed, 1/(b^0) always returns 1 since b^0 is, by definition of 0-th power, always 1.

So, no function with c = 0 will produce a result of 0.

For c = 1, result = 1, set b = 1

But I guess this is only a partial answer, I'm not terribly sure I understand what you are trying to do.

Regards

Mark

High Performance Mark
And now, reading the other response, I'm certain I misunderstood the question. Please will someone downvote my answer, I can't.
High Performance Mark
If you think your answer is wrong, it's better to delete it than leave it to be downvoted.
Mike Seymour
No, I think the public humiliation is an essential part of my recovery.
High Performance Mark
you deserve an upvote on your comment for that.
Martin
+2  A: 

For interpolation the approach offering the most flexibility is using splines, in your case quadratic splines would seem sufficient. The wikipedia page is math heavy, but you can find adapted desciptions on google.

Martin
hmm, that's pretty intriguing except it's hard to model a cubic interpolation in a graph. Is there a tool online I could use to visually create and modify a cubiclly interpolated graph?
meds
I found this http://www.vias.org/simulations/simusoft_spline.html. Once you get what you want, feed the derivatives and other values to the wikipedia page to get the desired equation.
Martin
+1  A: 

You could use a similar curve of the form A - 1 / b^(c + a), choosing values of A and a to match your constraints. So, for c = 0, result = 1:

1 = A - 1/b^a   =>   A = 1 + 1/b^a

and for c = 1, result = 0:

0 = A - 1/b^(1+a)  =>  A = 1/b^(1+a)

Combining these, we can find a in terms of b:

1 + 1/b^a = 1/b^(1+a)
b^(1+a) + b = 1
b * (b^a - 1) = 1
b^a = 1/b - 1

So:

a = log_b(1/b - 1) = log(1/b - 1) / log(b)
A = 1 + 1/b^a = 1 / (1-b)
Mike Seymour