Java interpolate interpolateYFromX(double x, double x0, double x1, double y0, double y1)

Here you can find the source of interpolateYFromX(double x, double x0, double x1, double y0, double y1)

Description

interpolate Y From X

License

Open Source License

Declaration

public static double interpolateYFromX(double x, double x0, double x1,
            double y0, double y1) 

Method Source Code

//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;
    }
}

Related

  1. interpolateRound(double a, double b, double t)
  2. interpolateSmoothly(final float position, final float startPosition, final float endPosition, final float startValue, final float endValue)
  3. interpolateValue(double current, double prev, float partialTickTime)
  4. interpolateValues(float prevVal, float nextVal, float partialTick)
  5. interpolateYawDegrees(float angle1, float ratio1, float angle2, float ratio2)