-1

I have an input between 0 and 1, inclusive, which produces a linear result. I need to convert this to a hyperbola curve, where the result is also between 0 and 1, inclusive. This should produce a rapidly ascending value at first, then slowly increasing to 1 at the end.

I'm coding this in Swift, but really I am looking for the formula (or pointers) and I don't know where to start.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
RopeySim
  • 423
  • 4
  • 11
  • 1
    Belongs on a math forum? – matt Dec 15 '20 at 14:03
  • 2
    I’m voting to close this question because it is not a programming, but a maths question. It might belong to the [Maths Stack Exchange site](https://math.stackexchange.com), but please check their [on-topic](https://math.stackexchange.com/help/on-topic) help page before posting a question there. – Dávid Pásztor Dec 15 '20 at 14:11
  • Specifically a hyperbola, or just something that looks like a hyperbola? – Matt Timmermans Dec 15 '20 at 14:13

1 Answers1

1

You can apply any exponent to a value between 0 and 1 without changing the range. So you probably could do something of that kind easily, for instance by using a power to a curve whose the two axis are inverted (or any other formula maybe closer to your exact needs) :

0, 0.25, 0.5, 0.75 1

Apply an exponent of 2 as an example :

0, 0.0625, 0.25, 0.5625, 1

Invert the curve :

1, 1-0.0625, 1-0.25, 1-0.5625, 1-1

And finally reverse it to get the final result :

0, 0.4375, 0.75, 0.9375,  1
dspr
  • 2,383
  • 2
  • 15
  • 19
  • I don’t understand why this was closed, this is actually a wgoos question. Thanks for your answer! – RopeySim Dec 15 '20 at 19:56
  • I think this is because the question is more focused on maths than coding. Rules are often applied very strictly here, maybe a little too much sometimes... – dspr Dec 15 '20 at 20:06
  • Thank you though. I ended up with this, and it works really well. let blurColorThreshold = Double(min(1, max(0, 1 - pow(1 - softEdges, 2))) * 8) let inputColorThreshold = Double(min(0.99, max(0, pow(softEdges, 2)))) let featherBlurRadius = Double(min(1, max(0, softEdges)) * 4) With this I can control the various effects. – RopeySim Dec 15 '20 at 21:00