Here you can find the source of interpolateYFromX(double x, double x0, double x1, double y0, double y1)
public static double interpolateYFromX(double x, double x0, double x1, double y0, double y1)
//package com.java2s; //License from project: Open Source License public class Main { public static double interpolateYFromX(double x, double x0, double x1, double y0, double y1) { if (x < x0 || x > x1) { throw new IllegalArgumentException("can't extrapolate"); }/*w w w. j a v a 2 s . c o m*/ if (x0 == x1) { return y0; } double dy = y1 - y0; double dx = x1 - x0; double v = y0 + (dy / dx) * (x - x0); if (Double.isNaN(v)) { throw new IllegalArgumentException("can't interpolate"); } return v; } }