Java interpolate interpolateAngle(double oldAngle, double newAngle, double scale)

Here you can find the source of interpolateAngle(double oldAngle, double newAngle, double scale)

Description

Interpolate between two angles.

License

Open Source License

Parameter

Parameter Description
oldAngle the previous angle.
newAngle the new angle.
scale the relative angle between oldAngle (0%) and newAngle (100%).

Return

the interpolated angle.

Declaration

public static double interpolateAngle(double oldAngle, double newAngle, double scale) 

Method Source Code

//package com.java2s;
/*//w  w w  . j  a  v  a2  s .  c o  m
 * @(#) CourseUtils.java
 *
 * This code is part of the JAviator project: javiator.cs.uni-salzburg.at
 * Copyright (c) 2009  Clemens Krainer
 *
 * This program 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 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

public class Main {
    /**
     * Interpolate between two angles. This method is only visible within this
     * package.
     * 
     * @param oldAngle the previous angle.
     * @param newAngle the new angle.
     * @param scale the relative angle between oldAngle (0%) and newAngle (100%).
     * @return the interpolated angle.
     */
    public static double interpolateAngle(double oldAngle, double newAngle, double scale) {
        while (newAngle - oldAngle > 360)
            newAngle -= 360;

        while (newAngle - oldAngle < -360)
            newAngle += 360;

        double result = oldAngle + (newAngle - oldAngle) * scale;

        while (result < 0)
            result += 360;

        while (result >= 360)
            result -= 360;

        return result;
    }
}

Related

  1. interpolate(Long t, Long t1, Double m1, Long t2, Double m2)
  2. interpolate(long x1, long x2, double y1, double y2, long x)
  3. interpolate(String input, String parameter, String value)
  4. interpolate(String value)
  5. interpolate2D(final float wi, final float wj, final float x00, final float x10, final float x01, final float x11)
  6. interpolateAO(float a, float b, float c, float d)
  7. interpolateBrightness(int a, int b, int c, int d)
  8. interpolateClamp(final double position, final double startPosition, final double endPosition, final double startValue, final double endValue)
  9. interpolateColor(double x, double y, int c0, int c1, int c2, int c3)