Recursively fixes the given angle to be within 0 -> 2*PI radians - Java java.lang

Java examples for java.lang:Math Geometry

Description

Recursively fixes the given angle to be within 0 -> 2*PI radians

Demo Code


//package com.java2s;

public class Main {
    /**//from   w  ww.jav  a2  s .c o m
     * Recursively fixes the given angle to be within 0 -> 2*PI radians
     * 
     * @param radians
     *            The given angle
     * @return An angle between [0, 2*PI] radians
     */
    public static float reduceAngle(float radians) {
        if (radians > Math.PI * 2) {
            return reduceAngle(radians - (float) Math.PI * 2);
        } else if (radians < 0) {
            return reduceAngle(radians + (float) Math.PI * 2);
        }
        return radians;
    }
}

Related Tutorials