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");
		}
		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;
	}