数学-映射数字 [英] Math - mapping numbers

查看:92
本文介绍了数学-映射数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在a和b之间线性映射数字以在c和d之间转换.

How do I map numbers, linearly, between a and b to go between c and d.

也就是说,我希望2到6之间的数字映射到10到20之间的数字...但是我需要广义的情况.

That is, I want numbers between 2 and 6 to map to numbers between 10 and 20... but I need the generalized case.

我的大脑被炸了.

推荐答案

如果您的数字X介于A和B之间,并且您希望Y介于C和D之间,则可以应用以下线性变换:

If your number X falls between A and B, and you would like Y to fall between C and D, you can apply the following linear transform:

Y = (X-A)/(B-A) * (D-C) + C

这应该会给您想要的,尽管您的问题有点模棱两可,因为您还可以反向绘制区间.只要当心被零除,就可以了.

That should give you what you want, although your question is a little ambiguous, since you could also map the interval in the reverse direction. Just watch out for division by zero and you should be OK.

这篇关于数学-映射数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆