Here you can find the source of angleDiffAbs(double a, double b)
Parameter | Description |
---|---|
a | angle a |
b | angle b |
public static double angleDiffAbs(double a, double b)
//package com.java2s; /*/*from w w w . j a v a 2 s .c o m*/ * Copyright (c) 2016 Fraunhofer IGD * * All rights reserved. This program and the accompanying materials are made * available under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution. If not, see <http://www.gnu.org/licenses/>. * * Contributors: * Fraunhofer IGD <http://www.igd.fraunhofer.de/> */ public class Main { /** * given two angels in radians, returns a difference in radians closest to * zero and >= zero. * * @param a angle a * @param b angle b * @return the angular difference in radians */ public static double angleDiffAbs(double a, double b) { return Math.abs(angleDiff(a, b)); } /** * given two angels in radians, returns a difference in radians closest to * zero and >= zero, depending on the scale. For example, while two angles * pi/2 and -pi/2 may differ on a full circle (scale 1), they are considered * equal at scale 2. At scale 3, also orthogonal angles would match, and so * on. * * @param a angle a * @param b angle b * @param scale the scale to base the difference on * @return the angular difference in radians */ public static double angleDiffAbs(double a, double b, int scale) { return Math.abs(angleDiff(a, b, Math.scalb(Math.PI, 2 - scale))); } /** * given two angels in radians, returns a difference in radians closest to * zero such that a + angleDiff(a, b) represents b. * * @param a angle a * @param b angle b * @return the angular difference in radians */ public static double angleDiff(double a, double b) { return angleDiff(a, b, Math.PI * 2); } /** * given two angels in radians, returns a difference in radians closest to * zero such that a + angleDiff(a, b) represents b. * * @param a angle a * @param b angle b * @param ring the ring in which the difference is meaningful (2PI is full * circle) * @return the angular difference in radians */ public static double angleDiff(double a, double b, double ring) { double c = b - a; c %= ring; if (c >= -ring / 2 && c <= ring / 2) return c; c += (-ring) * Math.signum(c); return c; } }