Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let's say you want to scale a range <code>[min,max]</code> to <code>[a,b]</code>. You're looking for a (continuous) function that satisfies</p> <pre><code>f(min) = a f(max) = b </code></pre> <p>In your case, <code>a</code> would be 1 and <code>b</code> would be 30, but let's start with something simpler and try to map <code>[min,max]</code> into the range <code>[0,1]</code>.</p> <p>Putting <code>min</code> into a function and getting out 0 could be accomplished with</p> <pre><code>f(x) = x - min ===&gt; f(min) = min - min = 0 </code></pre> <p>So that's almost what we want. But putting in <code>max</code> would give us <code>max - min</code> when we actually want 1. So we'll have to scale it:</p> <pre><code> x - min max - min f(x) = --------- ===&gt; f(min) = 0; f(max) = --------- = 1 max - min max - min </code></pre> <p>which is what we want. So we need to do a translation and a scaling. Now if instead we want to get arbitrary values of <code>a</code> and <code>b</code>, we need something a little more complicated:</p> <pre><code> (b-a)(x - min) f(x) = -------------- + a max - min </code></pre> <p>You can verify that putting in <code>min</code> for <code>x</code> now gives <code>a</code>, and putting in <code>max</code> gives <code>b</code>.</p> <p>You might also notice that <code>(b-a)/(max-min)</code> is a scaling factor between the size of the new range and the size of the original range. So really we are first translating <code>x</code> by <code>-min</code>, scaling it to the correct factor, and then translating it back up to the new minimum value of <code>a</code>.</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload