Returns true whenever the angle is between min Angle and max Angle, false otherwise. - Java 2D Graphics

Java examples for 2D Graphics:Angle

Description

Returns true whenever the angle is between min Angle and max Angle, false otherwise.

Demo Code



public class Main{
    public static void main(String[] argv) throws Exception{
        float angle = 2.45678f;
        float minAngle = 2.45678f;
        float maxAngle = 2.45678f;
        System.out.println(between(angle,minAngle,maxAngle));
    }//  w  w w .jav  a 2s.  com
    /**
     * Returns true whenever the angle is between minAngle and maxAngle, false otherwise.
     * 
     * @param angle
     *            The angle to evaluate.
     * @param minAngle
     *            The minimum angle.
     * @param maxAngle
     *            the maximum angle.
     */
    public static boolean between(float angle, float minAngle,
            float maxAngle) {
        return (AngleUtils.minimumDifference(angle, minAngle) < 0)
                && (AngleUtils.minimumDifference(angle, maxAngle) > 0);
    }
    /**
     * 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