🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Brain fart. How can I reduce some number ranges to another range?
Hey all, Im working on a radar of sorts and am having a huge brain fart.. and google isnt helping much either.
I have three number ranges..
1 - 10,000, 1 - 30,000 & 1 - 55,000
I need to be able to convert each to a range from 1-64.. and for the life of me, the math just isn't working in my favor..
Any ideas?
I suspect you're after linear interpolation.
Take the value, and subtract the lower bound of its current range (-1), then divide by the difference between the upper bound and lower bound of that range (/9999). This gives you a value between 0 and 1, where 0 corresponds to the lower bound of the old range and 1 corresponds to the upper bound of the old range. Now multiply by the difference between the upper bound and lower bound of the new range (*63) and add the lower bound of the new range (+1).
Take the value, and subtract the lower bound of its current range (-1), then divide by the difference between the upper bound and lower bound of that range (/9999). This gives you a value between 0 and 1, where 0 corresponds to the lower bound of the old range and 1 corresponds to the upper bound of the old range. Now multiply by the difference between the upper bound and lower bound of the new range (*63) and add the lower bound of the new range (+1).
You can always perform linear normalisation,
For each value x in the range ( 1, 10000 )
new_value = ( x - 1 ) / ( 10000 - 1 )
This would give you a range between 0-1, so,
For each value x,
new_value = 63*x+1
For example,
The value x=1 will become 1;
The value x=10000 will become 64;
The value 5000 will become ~0.5
Hope this helps!
For each value x in the range ( 1, 10000 )
new_value = ( x - 1 ) / ( 10000 - 1 )
This would give you a range between 0-1, so,
For each value x,
new_value = 63*x+1
For example,
The value x=1 will become 1;
The value x=10000 will become 64;
The value 5000 will become ~0.5
Hope this helps!
new_value = (old_value - old_min) / old_range * new_range + new_min
For 1 to 10,000, old_min is 1 and old_range is 9,999. Your new range and minimum is 63 and 1, respectively.
EDIT: Whoah. It took me less than a minute to type that, but benryves' post hadn't shown up yet. Is there some update lag between the database clusters on the GD net forums or something?
For 1 to 10,000, old_min is 1 and old_range is 9,999. Your new range and minimum is 63 and 1, respectively.
EDIT: Whoah. It took me less than a minute to type that, but benryves' post hadn't shown up yet. Is there some update lag between the database clusters on the GD net forums or something?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement