Java interpolate interpolate(double p0, double p1, double p2, double p3, double t)

Here you can find the source of interpolate(double p0, double p1, double p2, double p3, double t)

Description

Interpolation of Catmull-Rom Spline

License

Open Source License

Parameter

Parameter Description
p0 the p0 Spline point.
p1 the p1 Spline point.
p2 the p2 Spline point.
p3 the p3 Spline point.
t the value in range <0.0, 1.0>. The t in the function for a linear Bezier curve can be thought of as describing how far B(t) is from p0 to p3.

Return

the interpolated value.

Declaration

public static double interpolate(double p0, double p1, double p2, double p3, double t) 

Method Source Code

//package com.java2s;
/*/*w ww .  jav  a  2 s .  co  m*/
 * Copyright 2012 Alex Usachev, thothbot@gmail.com
 * 
 * This file is part of Parallax project.
 * 
 * Parallax is free software: you can redistribute it and/or modify it 
 * under the terms of the Creative Commons Attribution 3.0 Unported License.
 * 
 * Parallax 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 Creative Commons Attribution 
 * 3.0 Unported License. for more details.
 * 
 * You should have received a copy of the the Creative Commons Attribution 
 * 3.0 Unported License along with Parallax. 
 * If not, see http://creativecommons.org/licenses/by/3.0/.
 */

public class Main {
    /**
     * Interpolation of Catmull-Rom Spline
     *
     * @param p0 the p0 Spline point.
     * @param p1 the p1 Spline point.
     * @param p2 the p2 Spline point.
     * @param p3 the p3 Spline point.
     * @param t the value in range <0.0, 1.0>. The t in the
     *          function for a linear Bezier curve can be
     *          thought of as describing how far B(t) is from p0 to p3.
     *
     * @return the interpolated value.
     */
    public static double interpolate(double p0, double p1, double p2, double p3, double t) {
        double v0 = (p2 - p0) * 0.5;
        double v1 = (p3 - p1) * 0.5;
        double t2 = t * t;
        double t3 = t * t2;

        return (2.0 * p1 - 2.0 * p2 + v0 + v1) * t3 + (-3.0 * p1 + 3.0 * p2 - 2.0 * v0 - v1) * t2 + v0 * t + p1;
    }
}

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 x, double x1, double y1, double x2, double y2)
  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)