Java Angle angleEquals(double angle1, double angle2, double epsilon)

Here you can find the source of angleEquals(double angle1, double angle2, double epsilon)

Description

angle Equals

License

Open Source License

Declaration

public static boolean angleEquals(double angle1, double angle2, double epsilon) 

Method Source Code

//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);
    }
}

Related

  1. angle2degree(double angle)
  2. angle2pixels(double angle)
  3. angle360Limit(float angle)
  4. angleAdd(int i, final int i1)
  5. angleDistance(double angle1, double angle2)
  6. AngleEvaluation(double angle, int effectIndex, int angleNeeded, int orbValue)
  7. angleFromDirection(float dirX, float dirY)
  8. angleFromR(final double[][] R)
  9. angleInDegrees(float ownerRotation, float x1, float y1, float x2, float y2)