Java Angle Difference angleDiff(final double a1, final double a2)

Here you can find the source of angleDiff(final double a1, final double a2)

Description

Get the difference of angles (radians) as given from angle(x,z), from a1 to a2, i.e.

License

Open Source License

Parameter

Parameter Description
a1 a parameter
a2 a parameter

Return

Difference of angle from -pi to pi

Declaration

public static final double angleDiff(final double a1, final double a2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  w  w.j  a  v a  2  s .c o  m*/
     * Get the difference of angles (radians) as given from angle(x,z), from a1 to a2, i.e. rather a2 - a1 in principle.
     * @param a1
     * @param a2
     * @return Difference of angle from -pi to pi
     */
    public static final double angleDiff(final double a1, final double a2) {
        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
            return diff;
    }
}

Related

  1. angleDif(float a, float b)
  2. angleDif(float a1, float a2)
  3. angleDiff(double a, double b)
  4. angleDiff(double alpha, double beta)
  5. angleDiff(double angle1, double angle2, boolean normalized)
  6. angleDiff(float a, float b)
  7. angleDiff(int ang1, int ang2)
  8. angleDiff(int angle1, int angle2)
  9. angleDiff360(final double angleOne, final double angleTwo)