Normalize degree angle - Android java.lang

Android examples for java.lang:Math Trigonometric Function

Description

Normalize degree angle

Demo Code


//package com.java2s;

public class Main {
    /**//from  w ww  .  j av  a 2  s .co  m
     * Normalize angle
     *
     * @param angle
     *         //TODO describe it
     * @return //TODO describe it
     */
    public static float normalizeAngle(float angle) {
        angle %= 360;
        if (angle < -180) {
            angle += 360;
        }
        if (angle > 180) {
            angle -= 360;
        }
        return angle;
    }
}

Related Tutorials