Placing a number in a scale

256 Views Asked by At

I've broken down everything that I can, I'm having trouble figuring out this calculation:

  • Given I have a MIN number and a MAX number, with MIN < MAX
  • I have a number X, where MIN <= X <= MAX
  • Where MIN represents 0 on a scale
  • And MAX represents 5 on a scale
  • I want to calculate the, what I'm calling scale number, of X where 0 <= X <= 5

I know that if:

  • X = MIN, the scale number would equal 0
  • X = MAX the scale number would equal 5

But I can't seem to wrap my head around this. Can someone point me in the right direction?

I'm not entirely sure what to tag this.

EDIT

My first attempts was:

Figure out the scale length say 0-5, where MIN = 0 and MAX = 5, so S = 5 Then figure out the steps, where (MAX-MIN)/(S-1), But that would really only be able to give me the ability to say if 1 <= X <= 2 OR 2 <= X <= 3 and so on.

It seems like I have to normalize the numbers of MIN and MAX to equal 0 and 5(scale size) respectively. Than figure out the calculation to put X between those 2 numbers.

2

There are 2 best solutions below

2
On

If you want find the number $n$ that ''represents'' in the interval $[0,5]$ a given $x$ , in a directly proportional way than you have: $$ x:(Max-Min)=n:5 $$

find $n$ ...

0
On

Generally if you want to scale a variable $x$ with a minimum and maximum value to a variable $y$ with a minimum and maximum value, you are best describing the system in terms of Cartesian co-ordinates, with m being the slope or in this case scale factor which cancels out

$$\frac{ (y-y_{min})}{ (y_{max}-y_{min}) }=\frac{m(x-x_{min})}{m(x_{max}-x_{min})}=\frac{(x-x_{min})}{(x_{max}-x_{min})}$$

then by rearranging $y$ is easily calculated given $x$, $x_{min}$, $x_{max}$, $y_{min}$ and $y_{max}$

$$y=(x-x_{min} ) \;\frac{ (y_{max}-y_{min}) }{(x_{max}-x_{min})}+y_{min}$$

(But is that the answer to the question you are asking, I'm not entirely sure, your prose is far from clear)