我尝试搜索,但是由于问题的性质,我无法找到满意的东西.
I tried searching, but due to the nature of my question, I was unable to find something satisfactory.
我的问题如下:我试图将范围从0到2000的数字映射(虽然理想情况下上限是可调的)到较小的间隔(范围从10到100).上限将映射(2000-> 100)以及下限.除此之外,在[0; 2000]间隔内大于另一个条目的条目将比[0; 100]中的映射条目更大.
My problem is the following: I am trying to map numbers ranging from 0 to 2000 (though ideally the upper limit would be adjustable) to the much smaller interval ranging from 10 to 100. The upper limits would map (2000->100) and the lower limits as well. Other than that, an entry that is bigger than another entry in the interval [0;2000] would ideally be bigger than that mapped entry in [0;100]
我想这个问题不是特定于语言的,但是如果您想知道,我今天正在使用Javascript.
I'm thinking that this question is not language specific, but in case you are wondering, I'm working with Javascript today.
推荐答案To map [A, B] --> [a, b] use this formula (val - A)*(b-a)/(B-A) + a
在另一个答案中正确提到的是线性映射.
as correctly mentioned in the other answer it's linear mapping.
基本上
y = m*x + c c = intersection at y-axis m = slope determined by two known point (A, a), (B, b) = (b-a)/(B-A)更多推荐
将间隔映射到较小间隔的算法
发布评论