Add and normalize two angles - Java java.lang

Java examples for java.lang:Math Curve

Description

Add and normalize two angles

Demo Code


//package com.java2s;

public class Main {
    /**/*from w  w  w. ja v  a  2  s  .c om*/
     * Add and normalize two angles
     *
     * @param a
     *            An angle
     * @param b
     *            An angle
     * @return The sum of the two angles between 0.0 (0PIr) and 360.0 (2PIr)
     *         degrees
     */
    public static double addAngle(double a, double b) {
        return normaliseAngle(a + b);
    }

    /**
     * Normalize an angle between 0.0 and 360.0 degrees
     *
     * @param a
     *            The angle
     * @return A normalized angle between 0.0 (0PIr) and 360.0 (2PIr) degrees
     */
    public static double normaliseAngle(double a) {
        a %= 360.0;
        if (a < 0.0)
            a += 360.0;
        return a;
    }
}

Related Tutorials