Here you can find the source of clamp180(float r1, float r2)
public static float clamp180(float r1, float r2)
//package com.java2s; //License from project: Open Source License public class Main { public static float clamp180(float r1, float r2) { return clamp180(r1, r2, 0); }//from w w w. j a v a 2 s. c o m public static float clamp180(float r1, float r2, float var3) { float dr = r2 - r1; while (dr < -180.0F) { dr += 360.0F; } while (dr >= 180.0F) dr -= 360.0F; if (dr > var3) dr = var3; if (dr < -var3) dr = -var3; return r1 + dr; } }