将一个范围内的数字转换为另一个范围内的数字
可能的重复:
将数字范围转换为另一个范围,保持比率
所以我有一个返回 0 到 255 之间的值的函数,我需要将这些值转换为 -255 到 255 之间的值 所以 200 大约等于 145,150 大约等于 45,依此类推。 我看过 将数字范围转换为另一个范围,保持比率 但那里的公式不起作用。 我还可以使用其他公式吗?
Possible Duplicate:
Convert a number range to another range, maintaining ratio
So I have a function that returns values within 0 and 255 and I need to convert these values to something between -255 and 255
So 200 would be roughly 145, 150 would be roughly 45 and so on..
I have looked at Convert a number range to another range, maintaining ratio but the formulas there won't work.
Any other formula I could use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
试试这个:
Try this:
任意范围的通用解决方案...
General solution for arbitrary range...
调整后 = 原始值 / 255 * 510 - 255
Adjusted = original / 255 * 510 - 255