Looking for something like InverseLerp()

I’m working with a noise function that returns values between -1.0f and 1.0f. I want to Lerp this value into a new coord system from 0 to 1000. In Unity I would use the InverseLerp() like this:

// example values
float x = 0;
float y = 1000;
float xx = 0.3443;
float yy = -0.1743;

Mathf::Lerp(x, y, Mathf::InverseLerp(xx, yy, value));

The above code would basically allow me to “scale up” my values to the new coord system while keeping my ratios the same. UE4 (FMath) does not have this function, so how would I go about doing this?


Mathf::InverseLerp(float xx, float yy, float value)
    return (value - xx)/(yy - xx);

I’m not sure why a lerp or inverse anything is required here, it looks like all you want is (value + 1.f) * 500.f?

Thanks, this is exactly what I was looking for.

Great question. It’s very possible you are right. I’ll do some experimenting and find out. Thank you.

/** Returns Value normalized to the given range.  (e.g. 20 normalized to the range 10->50 would result in 0.25) */
UFUNCTION(BlueprintPure, Category="Math|Float")
float UKismetMathLibrary::NormalizeToRange(float Value, float RangeMin, float RangeMax)
    if (RangeMin == RangeMax)
        if (Value < RangeMin)
            return 0.f;
            return 1.f;

    if (RangeMin > RangeMax)
        Swap(RangeMin, RangeMax);
    return (Value - RangeMin) / (RangeMax - RangeMin);

You probably want FMath::GetMappedRangeValue. There are clamped and unclamped versions.