Example range 1 (minimum and maximum):
[40 ... 480]
Example numbers from range 1:
[42, 59.4, 78.18, 120.43, 416]
Example range 2:
[10 .. 140]
How can I translate the values of the numbers from range 1 to values within the second range? 42
should be equivalent to something between 10 and 11 in the new range.
I'm using PHP but this is more like a math problem.
I know how to align them to the second range:
$diff = $range[0] - $numbers[0];
foreach($numbers as $i => $number){
$numbers[$i] = $number + $diff;
}
But that's it :(
Do you mean something like this, which scales the values linearly to fit within the new range?
Sample usage:
You can transform one of the ranges into the other with this function (python)
In general the idea is that you want to rebase the ranges (make sure that they both start at zero) and then find how you need to stretch the first range to obtain the second range. So the steps would be
[0-440]
by subtracting40
and the second range to[0-130]
by subtracting10
. This is done to get intervals which start at zero which are easy to scale.[0-440]
to a corresponding value from[0-130]
you need to multiply it with130/440
. You can imagine this as shrinking the first interval to a[0-1]
interval by dividing with440
and then stretching it to a[0-130]
interval by multiplying.[0-440]
to[0-130]
and that means that to go from[40-440]
to[10-140]
you first need to rebase by subtracting40
multiply by130/440
and then add10
Example: