Calculate percentage in an irregular Slider

percentages

Het guys,

Let's say we have a slider like this

enter image description here

As you can see the slider have irregular Steps positions, so I managed to draw the steps like this 0% 33.33% 66.66% 100%.

My question is how can i calculate the correct percentage of the value (200 as example) in that slider based on the current position of 0, 100, 500 and 1000.

Best Answer

My first guess would be to create a linear interpolation between the points and the grid.

For example, 200, we have that between 100 and 500, assuming that we have a linear equation to describe this particular piece

$$ y = mx + c $$ we can determine the parameters as follows $$ y(100) = m \cdot x_{100} + C\\ y(500) = m\cdot x_{500} + C $$ solving for m and c we find $$ m = \frac{y(500) - y(100)}{x_{500} - x_{100}} = \frac{500-100}{x_{500} - x_{100}}\\ $$ now we can figure out what x has to be to fit to that particular scale $$ \frac{500-100}{x_{500} - x_{100}} = \frac{200-100}{x_{200} - x_{100}} $$ and re-arrange. I have used the fact that the gradient would be constant.

If you have some other scale in mind - i.e. a nonlinear curve to fit through the range then you can apply interpolation to obtain a curve fit, $y=f(x)$ and solve for the inverse of that equation for x. Alternatively, you can try to convert to a log scale and see if that achieves what you want.

Related Question