Pymel / Python Coding

Normalized Values

Sometimes its helpful to have a data range scaled into another range aka normalised.
I’ve used this for things like having numbers scale into a color ramp that works in the 0-1 range

inputVal = 2.1
minVal = 1.2
maxVal = 4.5
normalizedValue = (inputVal - minVal) / (maxVal - minVal)
print normalizedValue

In this example I needed to set minutes to fit into a 0-10 range
and the inputVal is minutes

inputVal = 15
minVal = 0.0
maxVal = 59.0
normalizedValue = (inputVal - minVal) / (maxVal - minVal) * 10
finalValue = round(normalizedValue,1)
print finalValue

Comments are closed.