Here you can find the source of interpolate(double x, double x1, double y1, double x2, double y2)
Parameter | Description |
---|---|
x | Value to interpolate |
x1 | Point 1 (x) |
y1 | Point 1 (y) |
x2 | Point 2 (x) |
y2 | Point 2 (y) |
public static double interpolate(double x, double x1, double y1, double x2, double y2)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from ww w . jav a2s .c o m*/ * Interpolate a value between two points. * * @param x Value to interpolate * @param x1 Point 1 (x) * @param y1 Point 1 (y) * @param x2 Point 2 (x) * @param y2 Point 2 (y) * @return Interpolated value */ public static double interpolate(double x, double x1, double y1, double x2, double y2) { double alpha = (x - x1) / (x2 - x1); return y1 * (1 - alpha) + y2 * alpha; } }