Here you can find the source of lerp(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.
Parameter | Description |
---|---|
a | The first value. |
b | The second value. |
f | The amount to interpolate. |
public static float lerp(final float a, final float b, final float f)
//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); } }