Java Lerp lerp(double from, double to, double p)

Here you can find the source of lerp(double from, double to, double p)

Description

Linearly interpolates between two values.

License

Open Source License

Parameter

Parameter Description
from the start value
to the end value
p the current interpolation position, must be between 0 and 1

Return

the result of the interpolation

Declaration

public static double lerp(double from, double to, double p) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 - 2018 Roman Divotkey,
 * Univ. of Applied Sciences Upper Austria. 
 * All rights reserved./*  ww  w. java 2s  .  c  om*/
 *   
 * This file is subject to the terms and conditions defined in file
 * 'LICENSE', which is part of this source code package.
 *    
 * THIS CODE IS PROVIDED AS EDUCATIONAL MATERIAL AND NOT INTENDED TO ADDRESS
 * ALL REAL WORLD PROBLEMS AND ISSUES IN DETAIL.
 *******************************************************************************/

public class Main {
    /**
     * Linearly interpolates between two values.
     * 
     * @param from
     *            the start value
     * @param to
     *            the end value
     * @param p
     *            the current interpolation position, must be between 0 and 1
     * @return the result of the interpolation
     */
    public static double lerp(double from, double to, double p) {
        assert p >= 0 && p <= 1 : "interpolation position out of range";
        return from + (to - from) * p;
    }

    /**
     * Linearly interpolates between two values.
     * 
     * @param from
     *            the start value
     * @param to
     *            the end value
     * @param p
     *            the current interpolation position, must be between 0 and 1
     * @return the result of the interpolation
     */
    public static float lerp(float from, float to, float p) {
        assert p >= 0 && p <= 1 : "interpolation position out of range";
        return from + (to - from) * p;
    }
}

Related

  1. lerp(double a, double b, double f)
  2. lerp(double a, double b, double lambda)
  3. lerp(double a, double l, double h)
  4. lerp(double amt, double start, double end)
  5. lerp(double distance, double firstPoint, double secondPoint)
  6. lerp(double from, double to, double progress)
  7. lerp(double min, double max, double percentage)
  8. lerp(double min, double max, double val)
  9. lerp(double start, double distance, double factor)