Java Utililty Methods Angle Difference

List of utility methods to do Angle Difference

Description

The list of methods to do Angle Difference are organized into topic(s).

Method

doubleangleDif(double a1, double a2)
Compute the difference between two angles.
double val = a1 - a2;
if (val > Math.PI) {
    val -= 2. * Math.PI;
if (val < -Math.PI) {
    val += 2. * Math.PI;
return val;
...
floatangleDif(float a, float b)
angle Dif
if (b > a)
    return b - a > PI ? (float) (a + 2 * PI - b) : b - a;
return a - b > PI ? (float) (b + 2 * PI - a) : a - b;
floatangleDif(float a1, float a2)
Compute the difference between two angles.
double val = a1 - a2;
if (val > Math.PI) {
    val -= 2. * Math.PI;
if (val < -Math.PI) {
    val += 2. * Math.PI;
return (float) val;
...
doubleangleDiff(double a, double b)
given two angels in radians, returns a difference in radians closest to zero such that a + angleDiff(a, b) represents b.
return angleDiff(a, b, Math.PI * 2);
doubleangleDiff(double alpha, double beta)
angle Diff
double angleDiff = alpha - beta;
return ((((angleDiff) % (2 * Math.PI)) + (3 * Math.PI)) % (2 * Math.PI)) - Math.PI;
doubleangleDiff(double angle1, double angle2, boolean normalized)
angle Diff
if (!normalized) {
    angle1 = normalizeAngle(angle1);
    angle2 = normalizeAngle(angle2);
return Math.min(Math.abs(angle1 - angle2),
        Math.min(Math.abs(angle1 - angle2 + TWO_PI), Math.abs(angle1 - angle2 - TWO_PI)));
doubleangleDiff(final double a1, final double a2)
Get the difference of angles (radians) as given from angle(x,z), from a1 to a2, i.e.
if (Double.isNaN(a1) || Double.isNaN(a1))
    return Double.NaN;
final double diff = a2 - a1;
if (diff < -Math.PI)
    return diff + 2.0 * Math.PI;
else if (diff > Math.PI)
    return diff - 2.0 * Math.PI;
else
...
floatangleDiff(float a, float b)
Returns the smallest signed difference between the two given angles, from a to b.
return reduceAngle(b - a);
intangleDiff(int ang1, int ang2)
angle Diff
int delta = ang2 - ang1;
delta %= ANGLE_2PI;
if (delta < 0)
    delta += ANGLE_2PI;
if (delta > ANGLE_PI)
    delta -= ANGLE_2PI;
return delta;
doubleangleDiff(int angle1, int angle2)
angle Diff
double diff = Math.abs(angle1 - angle2);
if (diff <= 180) {
    return diff;
} else {
    return 360 - diff;