Example usage for java.lang Math atan2

List of usage examples for java.lang Math atan2

Introduction

In this page you can find the example usage for java.lang Math atan2.

Prototype

@HotSpotIntrinsicCandidate
public static double atan2(double y, double x) 

Source Link

Document

Returns the angle theta from the conversion of rectangular coordinates ( x ,  y ) to polar coordinates (r, theta).

Usage

From source file:Main.java

public static void main(String[] args) {

    // get a variable x which is equal to PI/2
    double x = Math.PI / 2;

    // get a variable y which is equal to PI/3
    double y = Math.PI / 3;

    // convert x  and y to degrees
    x = Math.toDegrees(x);/*w  w  w.java2  s  .c  o m*/
    y = Math.toDegrees(y);

    // get the polar coordinates
    System.out.println("Math.atan2(" + x + "," + y + ")=" + Math.atan2(x, y));

}

From source file:org.jlab.clas.clas.math.Test.java

public static void main(String[] args) {
    for (int i = 0; i < 100; i++) {
        double x = -100 + (double) (i + 1);
        for (int j = 0; j < 100; j++) {
            double y = -100 + (double) (j + 1);
            System.out.println("angle " + (float) Math.toDegrees(Math.atan2(y, x)) + "  " + "I1-D "
                    + (Icecore.atan2((float) y, (float) x) - org.apache.commons.math3.util.FastMath.atan2(y, x))
                    + "  " + "I2-D "
                    + (Icecore2.atan2((float) y, (float) x)
                            - org.apache.commons.math3.util.FastMath.atan2(y, x))
                    + "  " + "K-D "
                    + (Kappa.atan2((float) y, (float) x) - org.apache.commons.math3.util.FastMath.atan2(y, x)));
        }//  ww  w.  j a  v  a 2  s  . co m
    }
}

From source file:Main.java

public static final float atan2(final float dY, final float dX) {
    return (float) Math.atan2(dY, dX);
}

From source file:Main.java

public static double pointTotoDegrees(double x, double y) {
    return Math.toDegrees(Math.atan2(x, y));
}

From source file:Main.java

public static double calcRadian(double x, double y, double x2, double y2) {
    double radian = Math.atan2(x2 - x, y2 - y);
    return radian;
}

From source file:Main.java

public static float atan2(float y, float x) {
    return (float) Math.atan2(y, x);
}

From source file:Main.java

public static float getAngle(float x1, float y1, float x2, float y2) {
    return (float) Math.atan2(y1 - y2, x2 - x1);
}

From source file:Main.java

static public double angle(Point center, Point target) {
    double angle = Math.toDegrees(Math.atan2(target.y - center.y, target.x - center.x));

    if (angle < 0) {
        angle += 360;//from w w  w.j av  a 2 s.  c  o  m
    }
    return angle;

}

From source file:Main.java

public static double smallestAngularDifferenceDegrees(double firstAngleDeg, double secondAngleDeg) {
    double d = ((firstAngleDeg - secondAngleDeg) * 3.141592653589793d) / 180.0d;
    return (Math.atan2(Math.sin(d), Math.cos(d)) * 180.0d) / 3.141592653589793d;
}

From source file:Main.java

public static double getBearing(Point posTo, Point posFrom) {
    double x = posTo.getX() - posFrom.getX();
    double y = posTo.getY() - posFrom.getY();

    return Math.atan2(x, y);
}