Here you can find the source of lerp(double from, double to, double p)
Parameter | Description |
---|---|
from | the start value |
to | the end value |
p | the current interpolation position, must be between 0 and 1 |
public static double lerp(double from, double to, double p)
//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; } }