Java Lerp lerp(final float a, final float b, final float f)

Here you can find the source of lerp(final float a, final float b, final float f)

Description

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

License

Open Source License

Parameter

Parameter Description
a The first value.
b The second value.
f The amount to interpolate.

Return

the linear interpolation of two input values by the given amount.

Declaration

public static float lerp(final float a, final float b, final float f) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from www . j  a  va2 s.co m*/
     * <p>
     * With this function you can find the value that equates to the position between two other values for a given percentage. So if you do, for example:
     * </p>
     * {@code lerp(0, 10, 0.5)}
     * <p>
     * you would get the return value of 5, which is 50% of the input values. You can extrapolate using this function too, by supplying a positive or negative value for the interpolation amount so that doing something like:
     * </p>
     * {@code lerp(0, 10, 2)}
     * <p>
     * will return a value of 20.<br>
     * <br>
     * </p>
     *
     * @param a The first value.
     * @param b The second value.
     * @param f The amount to interpolate.
     * @return the linear interpolation of two input values by the given amount.
     * @see #lerp(int, int, float)
     */
    public static float lerp(final float a, final float b, final float f) {
        return a * (1.0f - f) + b * f;
    }

    /**
     * <p>
     * With this function you can find the value that equates to the position between two other values for a given percentage. So if you do, for example:
     * </p>
     * {@code lerp(0, 10, 0.5)}
     * <p>
     * you would get the return value of 5, which is 50% of the input values. You can extrapolate using this function too, by supplying a positive or negative value for the interpolation amount so that doing something like:
     * </p>
     * {@code lerp(0, 10, 2)}
     * <p>
     * will return a value of 20.<br>
     * <br>
     * </p>
     *
     * @param a The first value.
     * @param b The second value.
     * @param f The amount to interpolate.
     * @return the linear interpolation of two input values by the given amount.
     * @see #lerp(float, float, float)
     */
    public static int lerp(final int a, final int b, final float f) {
        //return (int) (a + f * (b - a));
        return (int) (a * (1.0f - f) + b * f);
    }
}

Related

  1. lerp(double v1, double v2, double amt)
  2. lerp(double x, double x1, double x2, double q00, double q01)
  3. lerp(double x, double x1, double x2, double q00, double q01)
  4. lerp(final double a, final double min, final double max)
  5. lerp(final double percent, final int startColor, final int endColor)
  6. lerp(final float percent, final float startValue, final float endValue)
  7. lerp(final float x, final float x1, final float x2, final float q00, final float q01)
  8. lerp(float a, float b, float f)
  9. lerp(float a, float b, float interpolation)