Java Linear Interpolate linearInterp(double xa, double ya, double xb, double yb, double x)

Here you can find the source of linearInterp(double xa, double ya, double xb, double yb, double x)

Description

solves the equation (yb-ya)/(xb-xa) = (y-ya)/(x-xa) for y given x.

License

Open Source License

Declaration

public static final double linearInterp(double xa, double ya, double xb, double yb, double x) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   w w w . j  a  v  a2s.  co m
     * solves the equation (yb-ya)/(xb-xa) = (y-ya)/(x-xa) for y given x. Useful
     * for finding the pixel for a value given the dimension of the area and the
     * range of values it is supposed to cover. Note, this does not check for xa ==
     * xb, in which case a divide by zero would occur.
     */
    public static final double linearInterp(double xa, double ya, double xb, double yb, double x) {
        if (x == xa) {
            return ya;
        }
        if (x == xb) {
            return yb;
        }
        return (yb - ya) * (x - xa) / (xb - xa) + ya;
    }
}

Related

  1. LinearInterp(double n0, double n1, double a)
  2. linearInterp(long firstPoint, long lastPoint, int numValues, long currentPoint)
  3. linearInterpolate(double v0, double v1, double t)
  4. linearInterpolate(double v1, double v2, double amount)
  5. linearInterpolate(double[] x)