Java interpolate interpolate(double x, double x1, double y1, double x2, double y2)

Here you can find the source of interpolate(double x, double x1, double y1, double x2, double y2)

Description

Interpolate a value between two points.

License

Open Source License

Parameter

Parameter Description
x Value to interpolate
x1 Point 1 (x)
y1 Point 1 (y)
x2 Point 2 (x)
y2 Point 2 (y)

Return

Interpolated value

Declaration

public static double interpolate(double x, double x1, double y1, double x2, double y2) 

Method Source Code

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

public class Main {
    /**/*from ww  w  . jav  a2s .c  o  m*/
     * Interpolate a value between two points.
     * 
     * @param x Value to interpolate
     * @param x1 Point 1 (x)
     * @param y1 Point 1 (y)
     * @param x2 Point 2 (x)
     * @param y2 Point 2 (y)
     * @return Interpolated value
     */
    public static double interpolate(double x, double x1, double y1, double x2, double y2) {
        double alpha = (x - x1) / (x2 - x1);

        return y1 * (1 - alpha) + y2 * alpha;
    }
}

Related

  1. interpolate(double a, double b, double d)
  2. interpolate(double fromAngle, double toAngle, double ratio)
  3. interpolate(double oldP, double newP, float partialTicks)
  4. interpolate(double p0, double p1, double p2, double p3, double t)
  5. interpolate(double x1, double x2, double inbetween)
  6. interpolate(double x1, double x2, float zeroToOne)
  7. interpolate(final double min, final double max, final int currentClass, final int numOfClasses)
  8. interpolate(final float prev, final float curr, final float alpha)