Linearly interpolates between two values. - Java java.lang

Java examples for java.lang:Math Value

Description

Linearly interpolates between two values.

Demo Code


//package com.java2s;

public class Main {
    /**/*from   ww w.j a va  2s  .c  om*/
     * Linearly interpolates between two values.
     * 
     * <p>
     * This method performs the linear interpolation based on the following formula :
     * {@code value1 + (value2 - value1) * amount} Passing amount a value of 0 will cause value1 to
     * be returned, a value of 1 will cause value2 to be returned.
     * 
     * @param value1
     *        Source value.
     * @param value2
     *        Source value.
     * @param amount
     *        Value between 0 and 1 indicating the weight of value2.
     * @return Interpolated value.
     */
    public static float lerp(float value1, float value2, float amount) {
        return value1 + (value2 - value1) * amount;
    }
}

Related Tutorials