• Calculates the inverse linear interpolation (inverse lerp) factor based on a value between two numbers. The inverse lerp factor indicates where the given value falls between start and end.

    If value is equal to start, the function returns 0. If value is equal to end, the function returns 1.

    Parameters

    • start: number

      The starting value.

    • end: number

      The ending value.

    • value: number

      The value to calculate the inverse lerp factor for.

    Returns number

    The inverse lerp factor, a value in the range [0, 1], indicating where value falls between start and end.

    • If start and end are equal, the function returns 0.
    • If value is less than start, the factor is less than 0, indicating it's before start.
    • If value is greater than end, the factor is greater than 1, indicating it's after end.
    • If value is between start and end, the factor is between 0 and 1, indicating where value is along that range.
    // Calculate the inverse lerp factor for a value between two points.
    const startValue = 10;
    const endValue = 20;
    const targetValue = 15; // The value we want to find the factor for.
    const result = inverseLerp(startValue, endValue, targetValue);
    // result is 0.5, indicating that targetValue is halfway between startValue and endValue.

    // Handle the case where start and end are equal.
    const equalStartAndEnd = 5;
    const result2 = inverseLerp(equalStartAndEnd, equalStartAndEnd, equalStartAndEnd);
    // result2 is 0, as start and end are equal.
MMNEPVFCICPMFPCPTTAAATR