I am trying to make a function that takes a number and normalizes it from 0 to 1 between the boundaries of min and max. For example:
If I want to normalize the value of 10 between 5 and 15, I call this:
val = 10; normalize(val, 5, 15); Returns 0.5
normalizing a value of 0 between -10 and 5
val = 0; normalize(val, -10, 5); Returns 0.666
This is the function I came with:
function normalize(val, min, max){
My question is: is this the most efficient method for normalizing a one-dimensional value? I will call this function several thousand times per frame at a speed of 60 frames per second, so I would like it to be optimized as much as possible in order to reduce the load on the calculations. I have been looking for normalization formulas, but all I find is 2- or 3-dimensional solutions.
performance javascript math normalization
Marquizzo
source share