1

I am trying to place a current position on a real line where each steps are non linear.
Here is a screenshot of what I am trying to achieve (the current slider should be slightly below).

Given:

  • the total length of the slider (end of the slider matches the last step)
  • the different steps $[5,20,40,42,76,\ldots ]$.
  • the length between two consecutive steps (constant)

How can I deduce the slider ratio ($0.25$ means position on the $\frac{1}{4}$ of the slider total length) to place the current position correctly ?

non linear slider

N. F. Taussig
  • 76,571

1 Answers1

0

What you're trying to do seems to be to fit a function. Let's say the slider's actual position is $x$ and the output value you want to get is $y$. So, from your picture, you want to get $y=5$ when $x=0$, $y=8$ when $x=0.25$, $y=20$ when $x=0.5$, $y=40$ when $x=1$ or something, and interpolate between these different values.

This is something of an open ended question, since there are any number of functions which would do. For example a polynomial like $$ 5+15x+20x^2+5x^3 $$ roughly fits your points. Look up "polynomial interpolation" to get an exact result. But if I was to suggest a function like this which worked for the values you've given, it might not produce the results you want for parts you haven't specified.

What you probably need to do is to decide what the actual relationship is between $x$ and $y$ and then program that accordingly. If you just want to fit the points then look up interpolation.

Suzu Hirose
  • 11,660
  • Thanks for reminding me some math concepts, I will think about it I am not 100% sure this solves my issue, the problem looks to me more like several linear functions on each line step e.g. from 5 to 20, the steps are more close together than from 20 to 40.

    Another approach I was thinking was more like:

    1. Get length between two steps
    2. Find which segment a number is on
    3. Place cursor on the left point of a segment
    4. Move cursor to the right by (right - left) * length between two steps

    ; I will think of the two approaches. Thanks :)

    – michael-martinez Jun 17 '22 at 08:18