Android Angle Convert constrainAngle(float degree)

Here you can find the source of constrainAngle(float degree)

Description

Constrain a given degree to between 0-359

Declaration

public static float constrainAngle(float degree) 

Method Source Code

//package com.java2s;

public class Main {
    /**//ww w.  j a v  a 2  s.co  m
     * Constrain a given degree to between 0-359
     */
    public static float constrainAngle(float degree) {
        while (degree < 0.0f || degree >= 360.0f) {
            if (degree < 0.0f)
                degree = 360.0f + degree;
            else if (degree >= 360.0f)
                degree -= 360.0f;
        }
        return degree;

    }
}

Related

  1. difference(final float from, final float to)
  2. normalize(final float angle)