Normalize an angle so that it is between 0 and 360. - Android java.lang

Android examples for java.lang:Math Trigonometric Function

Description

Normalize an angle so that it is between 0 and 360.

Demo Code


//package com.java2s;

public class Main {
    /**/* w w w.jav  a 2 s  . co m*/
     * Normalize an angle so that it is between 0 and 360.
     *
     * @param angle Angle in degrees to normalize
     * @return Normalized angle.
     */
    public static float normalize(final float angle) {
        return (angle >= 0 ? angle : (360 - ((-angle) % 360))) % 360;
    }
}

Related Tutorials