价值重映射 [英] Value Remapping

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

问题描述

我一直使用的处理功能非常强大:

Processing has a great function I use all the time:

map(value, low1, high1, low2, high2)

http://processing.org/reference/map_.html

它将value(预期范围为low1high1)重新映射到目标范围为low2high2).

It remaps value (that has an expected range of low1 to high1) into a target range of low2 to high2).

我想了解其背后的数学原理,以便可以将其用于其他语言. 有人想给我扔骨头并帮助我进行反向工程吗?我了解到,这是一条已被重新缩放和偏移的束缚……今天早晨感觉脑筋急转弯.

I want to understand the math behind it so I can use it in other languages. Anyone want to throw me a bone and help me reverse engineer it? I understand that it's a lerp that's been re-scaled and re-offset... feeling brain dead this morning.

推荐答案

根据您的描述,应该这样做,对吧?

From your description, it ought to be doing this, right?

low2 + (value - low1) * (high2 - low2) / (high1 - low1)

找到您在第一个范围内的距离,按范围的大小比例缩放该距离,这就是您应该在第二个范围内的距离.

Find how far you are into the first range, scale that distance by the ratio of sizes of the ranges, and that's how far you should be into the second range.

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

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