Here you can find the source of angleEquals(double angle1, double angle2, double epsilon)
public static boolean angleEquals(double angle1, double angle2, double epsilon)
//package com.java2s; /*//from www . j a va 2 s . c om * Copyright ? 2015 Alexander Kindel. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * You may request to purchase an alternative licence for this software * by contacting Alexander Kindel <alexkindel@gmail.com>. */ public class Main { public static final double TWO_PI = 2.d * Math.PI; /** * */ public static boolean angleEquals(double angle1, double angle2, double epsilon) { // Because angles must wrap, two angles that are within epsilon of one another may wrap to opposite ends of the // wrapping range. To fix this, add some constant larger than epsilon to both angles (PI is used) and test for // equality again. return Math.abs(wrapAngle2Pi(angle1) - wrapAngle2Pi(angle2)) < epsilon || Math.abs(wrapAngle2Pi(angle1 + Math.PI) - wrapAngle2Pi(angle2 + Math.PI)) < epsilon; } /** * Return an equivalent angle in the range [0, 2pi). * * @param angle * The angle to wrap. * * @return The angle in the range [0, 2pi) which is equivalent to the argument angle. */ public static double wrapAngle2Pi(double angle) { return angle - TWO_PI * Math.floor(angle / TWO_PI); } }