Clamp presentable value

182 views Asked by At

I'm sitting here and trying to resolve an issue I have, with alternating between 0 and 1 of a variable.

Basicly, I want to do something like this:

float distance = 32f;
float maxDistance = 32f;
float clampedDistance = Math.ClampPresentableValue(distance, maxDistance);

The variable "clampedDistance", would receive the clamped value from the math method. "ClampPresentableValue" should in this case, be able to take the "distance" value, and calculate, where it is in the "0 to 1" timeline, in comparison to the maxDistance.

In this case, since "distance" is the same as "maxDistance", the clamped value would be 1.0f. But if we cut "distance" down to 16f, the clamped value would present 0.5f, in the "clampedDistance" variable.

What is something like this called? Does it have a name, or is it just an algorithm that i'd have to build myself?

1

There are 1 answers

1
mrzli On BEST ANSWER

It should probably be called 'normalize' or something like that. If I understood you correctly, you should simply do this:

float normalizedDistance = distance / maxDistance;