Java Linear Interpolate linearInterpolation(double x, double x1, double x2, double y1, double y2)

Here you can find the source of linearInterpolation(double x, double x1, double x2, double y1, double y2)

Description

Method returns a linearly interpolated value

License

Open Source License

Parameter

Parameter Description
x is X value you want to interpolate at
x1 is X value for previous point
x2 is X value for following point
y1 is Y value for previous point
y2 is Y value for following point

Return

Y interpolated value

Declaration

public static double linearInterpolation(double x, double x1, double x2, double y1, double y2) 

Method Source Code

//package com.java2s;
/*//from ww w . ja v a2 s  .  c  om
* Open-Source tuning tools
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

public class Main {
    /**
     * Method returns a linearly interpolated value
     * @param x is X value you want to interpolate at
     * @param x1 is X value for previous point
     * @param x2 is X value for following point
     * @param y1 is Y value for previous point
     * @param y2 is Y value for following point
     * @return Y interpolated value
     */
    public static double linearInterpolation(double x, double x1, double x2, double y1, double y2) {
        return (x1 == x2) ? 0.0 : (y1 + (x - x1) * (y2 - y1) / (x2 - x1));
    }
}

Related

  1. linearInterpolate(double v0, double v1, double t)
  2. linearInterpolate(double v1, double v2, double amount)
  3. linearInterpolate(double[] x)
  4. linearInterpolate(float y1, float y2, float mu)
  5. linearInterpolation(double min, double max, double factor)
  6. linearInterpolation(double x0, double y0, double x1, double y1, double x)
  7. linearInterpolation(double y2, double y1, double deltaX, double x1)
  8. LinearInterpolation(float a, float b, float f)
  9. linearInterpolation(float min, float max, float min2, float max2, float value)