For example, I have a number between 1~100 and I need to scale it to be between 20~80.
Examples:
1 scales to 20
100 scales to 80
50 scales to 50
You're looking for a function f such that :
f(x) = ax +b
f(1)=20
f(100)=80
Then
a+b=20
100a+b=80
You get :
99a +20 = 80
then a =60/99=20/33
and b = 20 - 20/33 = 20*(32/33)
Have a look at this question for more information :
Invert and convert slider value
Note: if 50 scales to 40 your transformation is not linear. So you need to look for another type of function:
f(x) = ax**2 + b x + c
You need to be more specific about what you're looking for. The rules you given do not produce a consistent LINEAR scaling.
For, if it were linear:
(1, 20) is on the line
(100, 80) is one the line
Slope is:
(80 - 20) / (100 - 1) = 60 / 99
Line is
y - 20 = (60 / 99) * (x - 1)
Then:
y = (60 / 99) * (x - 1) + 20
Then, testing x = 50
:
y = (60 / 99) * (50 - 1) + 20 = 2940 / 99 + 20 != 40
Thus, there is no such LINEAR scaling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With