Here you can find the source of angleDif(double a1, double a2)
public static double angleDif(double a1, double a2)
//package com.java2s; //License from project: Open Source License public class Main { /** Compute the difference between two angles. * The resulting angle is in the range of -pi..+pi if the input angle are * also in this range.//from w w w . j a v a 2 s .c o m */ public static double angleDif(double a1, double a2) { double val = a1 - a2; if (val > Math.PI) { val -= 2. * Math.PI; } if (val < -Math.PI) { val += 2. * Math.PI; } return val; } }