# Q：非线性图的公式。你滑的越远，它移动的越少

There's a name for a graph that does this, and I am trying to figure out an algorithm that calculates a result based on a DOUBLE input.

I am trying to create a method that accomplishes what you see in apps that basically slows down velocity the further you pull. So for instance, if you slide your finger, a box appears easily, but then the further you pull, the slower it moves.

The full requirement is to have a "free pull" amount, i.e.: it's a 1:1 relationship where the amount you slide your finger, the output value is that much as well. And have a theoretical "max result", which I assume is theoretical, because the more your finger moves, the smaller the amount changes by.

I have a feeling there is a formula for this. So any Maths guys, please help :)

You will have to try and see which formula works best for you.

Let's say the length of a finger pull is D and the distance of how far the box moves is D'. You can start with something very simple, like:

``````D' = D / 2
``````

Then if you need some "free pull" distance of F, you would probably include it like this:

``````D' = if D < F
then D
else F + (D - F) / 2
``````

To see which behavior of D' works best, you'll need to try different formulas. For example, a square root:

``````D' = if D < F
then D
else F + sqrt(D - F)
``````

Edit: Here's a version with an upper boundary of F + M. It works because arctan's upper asymptote is Pi/2.

``````D' = if D < F
then D
else F + arctan((D - F) / M) * M * (2 / Pi)
``````

Sample graph for F = 5, M = 3.D' will never reach 8 in this example.

``````D' = D / 2
``````

``````D' = if D < F
then D
else F + (D - F) / 2
``````

``````D' = if D < F
then D
else F + sqrt(D - F)
``````

``````D' = if D < F
then D
else F + arctan((D - F) / M) * M * (2 / Pi)
``````

c#  formula  nonlinear-functions