subtract 180 Difference - Java java.lang

Java examples for java.lang:Math Geometry

Description

subtract 180 Difference

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double angle = 2.45678;
        double from_angle = 2.45678;
        System.out.println(sub180Diff(angle, from_angle));
    }/*ww  w .  j  av  a  2s  .  com*/

    public static double sub180Diff(double angle, double from_angle) {
        while (Math.abs(angle - from_angle) > 180.) {
            if (angle > 0) {
                angle = angle - 360.;
            } else {
                angle = angle + 360.;
            }
        }
        return angle;
    }
}

Related Tutorials