1
$\begingroup$

I'm programming a game and am looking to create a non-linear relationship between input and output, such that as the input increases, the output increases, but the higher the input value, the corresponding output increment is less and less.

I've looked at logarithms, and that seems to be the effect I'm looking at.

o = log(i), where o is the output value and i is the input value.

But this is too extreme - the curve is too steep. If I try to modify this with

o = log(i)k, where k is some constant multiplier, creates too steep of a curve in the lower end.

I'd like to find a way to make the falloff more gradual. Unfortunately, I can't seem to find any other functions in my programming language (ActionScript 3) that will do the trick.

Where should I be looking? Are there any functions I should be trying to replicate?

Thanks in advance - I realize this is a pure maths forum, but it seemed like the best place to ask.

  • 0
    What's the domain for your inputs, and what do you want the curve to look like at the lower end? It seems like you could simply move the logarithm to the left appropriately and that would resolve your problems...2011-08-04
  • 0
    the inputs would be positive real numbers. The curve should be fairly linear in the lower end. I'd like to then be able to "play" with the factor to tweak the slope of the curve. How do you "move the logarithm to the left?" log(i-n)?2011-08-04
  • 1
    You're close: $\log(\mathrm{input}+x)$, for some translation distance $x$. Try it out for yourself. (Have you heard of Wolfram|Alpha yet?)2011-08-04
  • 0
    If $\log i$ ultimately grows too slowly for you, you can try $i^k$ for some $k$ between $0$ and $1$, like $k=1/2$, or $1/3$. There is still the steepness problem, which can be fixed for example with $(1+i)^{1/3}-1$, which is in the spirit of what @anon suggested. You will need to fool around, tweak parameters until things look good.2011-08-04
  • 0
    @anon, wow Wolfram|Alpha is pretty sweet. So this formula gets me reasonable close: (log(n+30)-log(30))70 with the problem that the slope doesn't fall off to 0 at the outer end. That would be ideal. Note that I found that when you add to n, you have to subtract the log of that same amount in order to keep the line above 02011-08-04
  • 0
    @Andre, thanks for this alternative. I can't seem to correlate x and y in (x + i)^k - y to a) get the slope to approach 0 (admittedly, this was not a requirement I stated in my original post) or b) tweak the slope and still maintain an output value of 0 when i = 0. In other words I'm having difficulty using those two values to control the starting and ending points of my curve. I'm not sure I'm expressing myself very well here.2011-08-04
  • 0
    The slope of say $(1+i)^{1/2}-1$ does approach $0$ as $i$ gets large. But maybe not fast enough for you. What about $1-2^{-i}$, for $i \ge 0$? Slope approaches $0$ very fast, and we are linear near $0$. To make the effect less extreme, divide $i$ by $3$ or $4$.2011-08-04

2 Answers 2