Java examples for java.lang:Math Calculation
Computes an inverse linear interpolation, returning an interpolation fraction.
//package com.java2s; public class Main { private static final double EPSILON = 1e-30d; /**//w ww .j av a 2 s .co m * Computes an inverse linear interpolation, returning an interpolation * fraction. Returns 0.5 if the min and max values are the same. * @param x the interpolated value * @param min the minimum value (corresponds to f==0) * @param min the maximum value (corresponds to f==1) * @return the inferred interpolation fraction */ public static double invLinearInterp(final double x, final double min, final double max) { final double denom = max - min; return denom < EPSILON && denom > -EPSILON ? 0 : (x - min) / denom; } }