/* * @(#)InterpolationControl.java 1.0 99/02/14 23:00:00 * * Copyright (c) 1999. All Rights Reserved. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. WE SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. * * @Author: Dr. Richard Parent * @Author: Kovalan Muniandy * * Provides ease-in ease-out implementation discussed in the Chapter 4. Using * this object, one could control the speed along which an interpolation * proceeds. * */ public class InterpolationControl { public static double ease( double t ) { return (( Math.sin( t*Math.PI - Math.PI/2.0 ) + 1 ) / 2.0); } public static double ease( double t, double t1, double t2 ) { double e1 = (t1 * 2)/Math.PI; // distance after t1 acceleration double e2 = (1 - t2)*2/Math.PI; // distance after (1-t2) deceleration double rt, nt, s; if (t < t1) { // if in accelaration stage nt = t/t1; // fraction into accelaration s = Math.sin( -Math.PI/2.0 + nt*Math.PI/2.0 ) + 1; // use sin quadrant for acceleration rt = s*e1; // distance after s } else if (t > t2) { nt = (t - t2)/(1.0 - t2); // fraction into deceleration s = Math.sin( nt*Math.PI/2.0 ); // use sine quadrant for accerleration rt = e1 + (t2 - t1) + s*e2; // distance after s } else { rt = e1 + t - t1; // distance after t } rt = (rt / (e1 + (t2 - t1) + e2)); return (rt); } /* public static double parabolicEase( double t, double a, double b ) { double v0, a1, a2; v0 = 2.0/(1 + b - a); if ( t & } */ }