Smooth transition between functions

1.8k Views Asked by At

Therefor that I don't really have a mathematical background, it is kind of difficult to me, to describe what I'm looking for (but I'll give it a try):

I'm looking for a way to parameterize a function to fulfill the following constraints:

  • function is a typical $y=f(x)$
  • lets call the parameter $p$
  • the following three coordinates shall be fixed: $f(0)=0$; $f(-100)=-100$; $f(100)=100$
  • $p$ shall have 100 valid values $([0-99];[1-100])$

now it comes to the tricky part:

  • when 'p' has its minimum value; I want $f(x)$ to be $x^2$
  • now with p increasing, I need f(x) become more and more bulgy like a $x^3$

I tried to separate the range from 1-3 in 100steps for $p$, and tried to use $y=x^p$, but that misses a lot of the above constraints (p.e. I never want the function to be $x^2$)

Maybe it becomes a little clearer, if you know what I need this for: I want to program an configurable exponential transmission for a computergame. If you set the parameter to the minimum, the transmission is 1:1 (a movement of a joystick by one, results in a in_game_change of the value by one. If you want maximum exponential control, you need to move the joystick a lot more, before you reach a change of the in_game_value (reduced sensitivity). But in every case, 100% joystick_movement shall result in a 100% ingame_change (thats why I need the three coordinates to be fixed).

I hope I could make clear what I'm looking for, and will be very glad if someone could point me to the right idea. Thanks in advance :)

2

There are 2 best solutions below

2
On BEST ANSWER

Define the functions

\begin{align} g_1(x) &= x \\ g_2(x) &= 100 (x/100)^3 \end{align}

Now define

$$ \sigma(p) = \frac{2}{1 + e^{-p/30}}-1 $$

The number 30 is kind of arbitrary, it just tells you how fast you want the transition between $g_1$ and $g_2$ to occur. Small means fast. One option is

$$ f_p(x) = g_1(x) + [g_2(x) - g_1(x)]\sigma(p) $$

Here is the result

enter image description here

0
On

You could set $f_p(x)=\mathrm{sgn}(x)|x|^p$ for $1\leq p\leq 3$, where $\mathrm{sgn}(x)$ is the sign of $x$ and $|x|$ is the absolute value of $x$. This reduces to the desired $x^p$ when $x\geq0$, with the added benefit of being an odd function, so for example $f(-1)=-1$.

Or, you can try linear interpolation between two functions, as in $f_p(x)=(1-p)x+px^3$ for $0\leq p\leq 1$. This may look more elegant on paper, but it might not feel as nice in practice, since it doesn't place a dead zone around $x=0$ unless $p$ is very close to $1$.

I assume you want a dead zone to compensate for the discontinuous jump in force that is required for the player's hand to move the joystick away from neutral. In other words, we want the derivative $f'_p(0)=0$ for all $p$ greater than the minimum setting. That's what you'll get with $\mathrm{sgn}(x)|x|^p$.