Maps a number from one range to another range.
- Return
num
mapped betweenoutMin
–outMax
frominMin
–inMax
.
代码实现
def num_to_range(num, inMin, inMax, outMin, outMax):
return outMin + (float(num - inMin) / float(inMax - inMin) * (outMax
- outMin))
使用样例
num_to_range(5, 0, 10, 0, 100) # 50.0