You can find the function mapLinear in the Library of Soley Studio under Basics and then Math: basics_math_mapLinear.
This library element first calculates the coordinate of an initial value with reference to the minimum and maximum boundaries of its interval. Then it returns the new coordinates determined by a new interval defined by zero point offset and upper limit.
INITIAL_VALUE:double – Is the variable’s coordinate in the initial domain.
MIN_BOUNDARY:double – Is the lowest value of this domain.
MAX_BOUNDARY:double – Is the highest value of this domain.
ZERO_POINT_OFFSET:double – Is the lowest value of the codomain.
UPPER_LIMIT:double – Is the highest value of the codomain.
RESULT:double – Is the variable’s coordinate in the new codomain.
emit(Basics_Math_mapLinear(5.0, 0.0, 10.0, 10.0, 110.0) + "\n");
The emit statement will write “60” to the Output pad. First, the function calculates the coordinate of 5 with reference to the interval [0,10] (it is exactly in the middle). Then it transferes this coordinate to the new interval [10,110].
In the next example you can see that you can use negative numbers as well:
emit(Basics_Math_mapLinear(10.0, -10.0, 20.0, -5.0, 70.0) + "\n");
Actually, the following formula shows how the result is calculated:
(10.0-(-10.0))/(20.0-(-10.0))*(70.0-(-5.0)) + (-5) = 45
Simplified, you first locate the variable’s coordinates in proportion to the initial domain boundaries: This is 1/2 with example 1 and 2/3 with example 2. Then you transfer this to the interval of the new domain (50 in both examples). FInally, the last step is adjusting it by the shift factor, which is the lower limit of the new domain.