Here you can find the source of angleDif(float a1, float a2)
public static float angleDif(float a1, float a2)
//package com.java2s; //License from project: Apache 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 ww w .j a v a 2 s . c o m */ public static float angleDif(float a1, float a2) { double val = a1 - a2; if (val > Math.PI) { val -= 2. * Math.PI; } if (val < -Math.PI) { val += 2. * Math.PI; } return (float) val; } /** 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. */ 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; } }