Java Array Interpolate interpolate(double[] end0, double[] end1, double[] mid)

Here you can find the source of interpolate(double[] end0, double[] end1, double[] mid)

Description

interpolate

License

Open Source License

Declaration

public static double[] interpolate(double[] end0, double[] end1, double[] mid) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This file is part of logisim-evolution.
 *
 *   logisim-evolution is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   logisim-evolution is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with logisim-evolution.  If not, see <http://www.gnu.org/licenses/>.
 *
 *   Original code by Carl Burch (http://www.cburch.com), 2011.
 *   Subsequent modifications by :/*from   w ww.  j  a v  a  2s . c  om*/
 *     + Haute ?cole Sp?cialis?e Bernoise
 *       http://www.bfh.ch
 *     + Haute ?cole du paysage, d'ing?nierie et d'architecture de Gen?ve
 *       http://hepia.hesge.ch/
 *     + Haute ?cole d'Ing?nierie et de Gestion du Canton de Vaud
 *       http://www.heig-vd.ch/
 *   The project is currently maintained by :
 *     + REDS Institute - HEIG-VD
 *       Yverdon-les-Bains, Switzerland
 *       http://reds.heig-vd.ch
 *******************************************************************************/

public class Main {
    /**
     * getBounds and findNearestPoint are based translated from the ActionScript
     * of Olivier Besson's Bezier class for collision detection. Code from:
     * http://blog.gludion.com/2009/08/distance-to-quadratic-bezier-curve.html
     */

    // a value we consider "small enough" to equal it to zero:
    // (this is used for double solutions in 2nd or 3d degree equation)
    private static final double zeroMax = 0.0000001;

    public static double[] interpolate(double[] end0, double[] end1, double[] mid) {
        double dx = mid[0] - end0[0];
        double dy = mid[1] - end0[1];
        double d0 = Math.sqrt(dx * dx + dy * dy);

        dx = mid[0] - end1[0];
        dy = mid[1] - end1[1];
        double d1 = Math.sqrt(dx * dx + dy * dy);

        if (d0 < zeroMax || d1 < zeroMax) {
            return new double[] { (end0[0] + end1[0]) / 2, (end0[1] + end1[1]) / 2 };
        }

        double t = d0 / (d0 + d1);
        double u = 1.0 - t;
        double t2 = t * t;
        double u2 = u * u;
        double den = 2 * t * u;

        double xNum = mid[0] - u2 * end0[0] - t2 * end1[0];
        double yNum = mid[1] - u2 * end0[1] - t2 * end1[1];
        return new double[] { xNum / den, yNum / den };
    }
}

Related

  1. interpolate(double x, double xLeft, double yLeft, double xRight, double yRight, double[] weights)
  2. interpolate(double x, double[] begin, double[] end)
  3. interpolate(double xa[], double ya[], double x)
  4. interpolate(double[] array, int[] translation, double index)
  5. interpolate(double[] points, double[] values, double interpolateAt)
  6. interpolate(double[] x, double D)
  7. interpolate(double[] X, double[] Y, double[] Z)
  8. interpolate(double[] x, int newLength)