Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static float getAngleDifference(float ang1, float ang2) { float a = (float) Math.toDegrees(ang1) - (float) Math.toDegrees(ang2); a += (a > 180) ? -360 : (a < -180) ? 360 : 0; return (float) Math.toRadians(a); } }