Here you can find the source of linearInterpolation(double x, double x1, double x2, double y1, double y2)
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 |
public static double linearInterpolation(double x, double x1, double x2, double y1, double y2)
//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)); } }