How Achieve This Specific Non-Linear Mapping

103 Views Asked by At

Let's say in a computer program, we have a Slider whereby a user selects a value.

The slider widget itself produces a value, X, from 0.0 to 1.0.

This value then maps to some other range.

Most people map the slider's value linearly onto the resulting value range.

But imagine we want the mapping to be non-linear.

For example, what if the value being selected is the beats-per-minute for a metronome (that is capable of producing bpm from zero to 999)... so our resulting range is from 0-999.

We want to make all possible BPMs selectable, but we also know that most people are not going to be interested in BPM, say, below 30 or above 240.

Therefore we decide we want a percentage, P, (say 75%), of the slider's length to be dedicated to this more common value range.

So to simplify(?), we have:

  • A: the "lower bound of the emphasized range" (between 0 and 1)
  • B: the "upper bound of the emphasized range" (between 0 and 1)
  • P: fraction of slider space that we want that range to occupy (between 0 and 1)
  • X: the actual input value from the slider (between 0 and 1)

So how can we make a function of X, A, B, and P such that the mapping is non-linear and looks something like

(1-cos(Pi*x))/2

... something like this:

enter image description here

Note:

PS - P doesn't have to be expressed as a decimal percentage.

PPS - In my drawing the y axis should max out at 1, not 999

PPPS - I know the title to this question is bad... but that's because I don't know what I'm talking about. :T