Here you can find the source of angleInRange(float theta1, float theta2, float tolerance)
public static boolean angleInRange(float theta1, float theta2, float tolerance)
//package com.java2s; //License from project: Open Source License public class Main { public static boolean angleInRange(float theta1, float theta2, float tolerance) { theta1 = boundAngle(theta1);//from w ww . j ava 2 s .c o m theta2 = boundAngle(theta2); float dtheta = Math.abs(theta1 - theta2); if (dtheta > Math.PI) { if (2 * Math.PI - dtheta <= tolerance) return true; } else { if (dtheta <= tolerance) return true; } return false; } public static float boundAngle(float theta) { theta /= Math.PI; theta = (theta + 1) / 2; if (theta > 1 || theta < 0) theta -= (int) (theta); theta = theta * 2 - 1; return theta * (float) Math.PI; } }