This method calculates tangent of Spline Curve. - Java java.lang

Java examples for java.lang:Math Curve

Description

This method calculates tangent of Spline Curve.

Demo Code

/*/* ww w .j  a  v  a2 s .c  o  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/.
 */
//package com.java2s;

public class Main {
    /**
     * This method calculates tangent of Spline Curve.
     * 
     * @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.
     * @param p0 the p0 Spline point.
     * @param p1 the p1 Spline point.
     * @param p2 the p2 Spline point.
     * @param p3 the p3 Spline point.
     * 
     * @return the tangent of Spline Curve
     */
    public static double tangentSpline(double t, double p0, double p1,
            double p2, double p3) {
        // To check if my formulas are correct
        double h00 = 6.0 * t * t - 6.0 * t; // derived from 2t^3 ? 3t^2 + 1
        double h10 = 3.0 * t * t - 4.0 * t + 1.0; // t^3 ? 2t^2 + t
        double h01 = -6.0 * t * t + 6.0 * t; // ? 2t3 + 3t2
        double h11 = 3.0 * t * t - 2.0 * t; // t3 ? t2

        return h00 + h10 + h01 + h11;
    }
}

Related Tutorials