Android Double Calculate angularDifference(double hdg, double brg)

Here you can find the source of angularDifference(double hdg, double brg)

Description

Calculate the absolute angular difference between the two headings

License

Open Source License

Parameter

Parameter Description
hdg angle 1 in degrees (typically the heading)
brg angle 2 in degrees (typically the bearing)

Return

difference between hdg and brg in degrees

Declaration

public static double angularDifference(double hdg, double brg) 

Method Source Code

//package com.java2s;

public class Main {
    /** Calculate the absolute angular difference between the two headings
     * /* w  w  w .ja  v  a 2 s  . c o  m*/
     * @param hdg angle 1 in degrees (typically the heading)
     * @param brg angle 2 in degrees (typically the bearing)
     * @return difference between hdg and brg in degrees
     */
    public static double angularDifference(double hdg, double brg) {
        double absDiff = Math.abs(hdg - brg);
        if (absDiff > 180) {
            return 360 - absDiff;
        }
        return absDiff;
    }
}

Related

  1. ceil(double double1, double double2)
  2. midpoint(double a, double b)