simplify Angle - Java 2D Graphics

Java examples for 2D Graphics:Angle

Description

simplify Angle

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double angle = 2.45678;
        System.out.println(simplifyAngle(angle));
    }/*from ww w .j ava 2  s .  c  o m*/

    public static double simplifyAngle(double angle) {
        angle = angle % (2.0 * Math.PI);
        if (angle < -Math.PI) {
            return angle + 2 * Math.PI;
        } else if (angle > Math.PI) {
            return angle - 2 * Math.PI;
        }
        return angle;
    }
}

Related Tutorials