将间隔映射到较小间隔的算法

编程入门 行业动态 更新时间:2024-10-10 00:26:17
本文介绍了将间隔映射到较小间隔的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试搜索,但是由于问题的性质,我无法找到满意的东西.

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)

更多推荐

将间隔映射到较小间隔的算法

本文发布于:2023-11-30 22:00:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间隔   较小   算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!