C++ equivalent of Processing's map() function

蹲街弑〆低调 提交于 2019-12-08 08:03:26

问题


Processing has a function map that

Re-maps a number from one range to another.

For example

int ans = map(5, 0, 10, 0, 100);

ans will be 50 as 5 is halfway between 0 and 10 and halfway between 0 and 100 is 50.

If there is no built in function how would I write my own one?


回答1:


Processing is open source, and you can view the source for the map() function here.

Specifically, this is the line you care about:

float outgoing =
  start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));


来源:https://stackoverflow.com/questions/43683041/c-equivalent-of-processings-map-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!