Java Angle Difference angleDif(float a1, float a2)

Here you can find the source of angleDif(float a1, float a2)

Description

Compute the difference between two angles.

License

Apache License

Declaration

public static float angleDif(float a1, float a2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /** Compute the difference between two angles.
     * The resulting angle is in the range of -pi..+pi if the input angle are
     * also in this range.//from  ww w .j a v a 2 s .  c  o m
     */
    public static float angleDif(float a1, float a2) {
        double val = a1 - a2;
        if (val > Math.PI) {
            val -= 2. * Math.PI;
        }
        if (val < -Math.PI) {
            val += 2. * Math.PI;
        }
        return (float) val;
    }

    /** Compute the difference between two angles.
     * The resulting angle is in the range of -pi..+pi if the input angle are
     * also in this range.
     */
    public static double angleDif(double a1, double a2) {
        double val = a1 - a2;
        if (val > Math.PI) {
            val -= 2. * Math.PI;
        }
        if (val < -Math.PI) {
            val += 2. * Math.PI;
        }
        return val;
    }
}

Related

  1. angleDif(double a1, double a2)
  2. angleDif(float a, float b)
  3. angleDiff(double a, double b)
  4. angleDiff(double alpha, double beta)
  5. angleDiff(double angle1, double angle2, boolean normalized)
  6. angleDiff(final double a1, final double a2)