# Range Formula Between Two Values?

I'm in the middle of programming something, and I really need a formula that can go from 0 to 1 depending on the distance an object is to another one. I can get the formula to return 1 if the objects' distance equals 0, but I need it to also take into account a minimum variable.

In short (and perhaps more accurately), if an object is beyond maxdist away, the formula should return 0 or less. If it's closer than mindist, it should return 1 or greater. I can clamp the values when necessary. This is what I have so far.

 blenddist = 1.0 - ( ( 1.0 / gimaxdist) * dist)


Where would I work in mindist to allow me to set the 'zero-point'?

-

Let $d$ be the distance, let $m$ be what you're calling $mindist$, let $M$ be what you're calling $maxdist$, let $b$ be what you're calling $blenddist$. Then $$b={d-M\over m-M}$$ does what you ask.