Reduces a given angle to a value between ? - Java java.lang

Java examples for java.lang:Math Value

Description

Reduces a given angle to a value between ?

Demo Code


//package com.java2s;

public class Main {
    /**//from  www  .ja va 2s . c  om
     * Reduces a given angle to a value between ? and -?.
     * 
     * @param angle
     *        The angle to reduce, in radians.
     * @return The new angle, in radians.
     */
    public static float wrapAngle(float angle) {
        angle = (float) Math.IEEEremainder((double) angle,
                6.2831854820251465);
        if (angle <= -3.14159274f) {
            angle += 6.28318548f;
        } else {
            if (angle > 3.14159274f) {
                angle -= 6.28318548f;
            }
        }
        return angle;
    }
}

Related Tutorials