2019-12-27 17:23:08 +00:00
|
|
|
package util
|
|
|
|
|
2021-10-12 17:28:56 +00:00
|
|
|
// MapRange Linear mapping between two ranges of values
|
2019-12-27 17:23:08 +00:00
|
|
|
func MapRange(x, xmin, xmax, ymin, ymax float64) int {
|
|
|
|
Xrange := xmax - xmin
|
|
|
|
Yrange := ymax - ymin
|
|
|
|
XYratio := Xrange / Yrange
|
|
|
|
|
|
|
|
y := (x-xmin)/XYratio + ymin
|
|
|
|
|
|
|
|
return int(y)
|
|
|
|
}
|