Finds the angle obtained by moving a distance of delta_x from x in a anti-clockwise direction. - Java java.lang

Java examples for java.lang:Math Geometry Distance

Description

Finds the angle obtained by moving a distance of delta_x from x in a anti-clockwise direction.

Demo Code

/*/*from w  w w  . ja v  a 2  s .  c  o  m*/
 * Copyright (C) 2011 apurv
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double x = 2.45678;
        double delta_x = 2.45678;
        System.out.println(addAntiClockwise(x, delta_x));
    }

    /**
     * Finds the angle obtained by moving a distance of delta_x from x in a anti-clockwise direction.
     * @param x
     * @param delta_x magnitude of the anti-clockwise shift.
     * @return the transformed angle obtained after anti-clockwise addition.
     */
    private static Double addAntiClockwise(Double x, Double delta_x) {
        Double y = null;
        delta_x = delta_x % 360;

        if (x - delta_x < -180.0) {
            y = (x - delta_x) + 360;

        } else {
            y = x - delta_x;

        }
        return y;
    }
}

Related Tutorials