Sum of two angles. - Java java.lang

Java examples for java.lang:Math Geometry

Description

Sum of two angles.

Demo Code


//package com.java2s;

public class Main {
    /** Sum of two angles.
     * The resulting angle is in the range of -pi..+pi if the input angle are
     * also in this range.//ww  w  .  ja va  2  s  . com
     */
    public static float angleSum(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;
    }
}

Related Tutorials