Here you can find the source of angleDiff(double a, double b)
Parameter | Description |
---|---|
a | angle a |
b | angle b |
public static double angleDiff(double a, double b)
//package com.java2s; /*/*from w ww. j a v a 2 s. co 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 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; } }