相当于 Processing 的 map() 函数的 C++
C++ equivalent of Processing's map() function
Processing has a function map
那个
Re-maps a number from one range to another.
例如
int ans = map(5, 0, 10, 0, 100);
ans
将是 50
因为 5
介于 0
和 10
之间以及 0
和 [=18= 之间] 是 50
.
如果没有内置函数,我该如何编写自己的函数?
Processing是开源的,可以查看map()
函数here的源码。
具体来说,这是您关心的行:
float outgoing =
start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
Processing has a function map
那个
Re-maps a number from one range to another.
例如
int ans = map(5, 0, 10, 0, 100);
ans
将是 50
因为 5
介于 0
和 10
之间以及 0
和 [=18= 之间] 是 50
.
如果没有内置函数,我该如何编写自己的函数?
Processing是开源的,可以查看map()
函数here的源码。
具体来说,这是您关心的行:
float outgoing =
start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));