Here you can find the source of degreesDiff(double a1, double a2)
public static double degreesDiff(double a1, double a2)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w.ja va 2s . co m*/ * diff align difference between 2 angles ]-180, 180] * @return */ public static double degreesDiff(double a1, double a2) { double diff = a1 - a2; while (diff > 180) { diff -= 360; } while (diff <= -180) { diff += 360; } return diff; } }