Reputation: 852
I'm having some issues figuring out the best way to go about this. I want to display a percent of 0-100. My input(X) is a distance in meters. The closer X is to 0 I want the percent to be closer to 100.
My issue is that the person has to be able to know if they are getting closer to 0. No matter how far the range is. So if they are 10000 meters away and get to 9900 meters I need the percent to increase. But the same if they are 50 meters away and get to 45 meters.
Right now i'm doing
100 - ((playerDistance / max) * 100)
where max is the maximum value of meters someone can be. which for my situation is around 300,000. This works if they travel far. But once they get within a couple thousand meters it loses all precision since it will be 99% for a long time.
Upvotes: 0
Views: 71
Reputation: 80197
You can apply any function that has value 1 (100%) for argument 0 and smoothly decreases.
A pair of examples (Python syntax)
100.0 * math.exp( - dist / 1000.0)
100.0 * math.pow(1 + dist, -0.3)
Note that you cannot provide integer percent values covering all needed range, so you have to show at least three decimal digits after point (like 54.321).
Aslo note that exponent approach provides equal percent increments for equal distance1/distance2
ratios
Upvotes: 1