Java Utililty Methods Lerp

List of utility methods to do Lerp

Description

The list of methods to do Lerp are organized into topic(s).

Method

doublelerp(double start, double distance, double factor)
lerp
return start + (distance * factor);
doublelerp(double v1, double v2, double amt)
lerp
return v1 + (v2 - v1) * amt;
doublelerp(double x, double x1, double x2, double q00, double q01)
lerp
return ((x2 - x) / (x2 - x1)) * q00 + ((x - x1) / (x2 - x1)) * q01;
doublelerp(double x, double x1, double x2, double q00, double q01)
Linear interpolation.
return ((x2 - x) / (x2 - x1)) * q00 + ((x - x1) / (x2 - x1)) * q01;
doublelerp(final double a, final double min, final double max)
lerp
return min + a * (max - min);
intlerp(final double percent, final int startColor, final int endColor)
lerp
if (startColor == endColor) {
    return startColor;
} else if (percent <= 0.0) {
    return startColor;
} else if (percent >= 1.0) {
    return endColor;
final int r = (int) ((1.0 - percent) * (startColor >> 24 & 0xFF) + percent * (endColor >> 24 & 0xFF));
...
floatlerp(final float a, final float b, final float f)

With this function you can find the value that equates to the position between two other values for a given percentage.

return a * (1.0f - f) + b * f;
floatlerp(final float percent, final float startValue, final float endValue)
lerp
if (startValue == endValue) {
    return startValue;
return (1 - percent) * startValue + percent * endValue;
floatlerp(final float x, final float x1, final float x2, final float q00, final float q01)
lerp
return (x2 - x) / (x2 - x1) * q00 + (x - x1) / (x2 - x1) * q01;
floatlerp(float a, float b, float f)
Linearly interpolates between two floats
return a + f * (b - a);