Returns the difference between two angles in degrees between -180 and 180 - Java 2D Graphics

Java examples for 2D Graphics:Angle

Description

Returns the difference between two angles in degrees between -180 and 180

Demo Code


//package com.java2s;

public class Main {


    /**//from   ww w  .ja  va2  s  .c  om
     * Returns the difference between two angles in degrees between -180 and 180
     */
    public static double minimumDifference(double a, double b) {
        double diffAngle = b - a;
        if (diffAngle > 180)
            diffAngle -= 360;
        else if (diffAngle < -180)
            diffAngle += 360;
        return diffAngle;
    }
}

Related Tutorials