Maps a number from one range to another range.
Returns num
mapped between oMin
–oMax
from iMin
–iMax
.
代码实现
func MapNumRange(num, iMin, iMax, oMin, oMax float64) float64 {
return ((num-iMin)*(oMax-oMin))/(iMax-iMin) + oMin
}
使用样例
MapNumRange(5.0, 0.0, 10.0, 0.0, 100.0) // 50.0