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 double[] bd_encrypt(double gg_lat, double gg_lon) {

    double x = gg_lon, y = gg_lat;
    double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
    double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
    double bd_lon = z * Math.cos(theta) + 0.0065;
    double bd_lat = z * Math.sin(theta) + 0.006;

    return new double[] { bd_lon, bd_lat };
}

From source file:Util.java

/** 
 * @param obj1X/*from  w w w. ja v  a 2  s  .  com*/
 * @param obj1Y
 * @param obj2X
 * @param obj2Y
 * @return float
 */
public final static float calculateAngleFrom(float obj1X, float obj1Y, float obj2X, float obj2Y) {
    float angleTarget = (float) Math.toDegrees(Math.atan2(obj2Y - obj1Y, obj2X - obj1X));
    if (angleTarget < 0)
        angleTarget = 360 + angleTarget;
    return angleTarget;
}

From source file:Main.java

public static double[] getGaoDePos(double[] baiDu) {
    double X_PI = 3.14159265358979324 * 3000.0 / 180.0;
    double x = baiDu[0] - 0.0065, y = baiDu[1] - 0.006;
    double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
    double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
    double[] gaode = new double[2];
    gaode[0] = z * Math.cos(theta);
    gaode[1] = z * Math.sin(theta);
    return gaode;
}

From source file:Main.java

public static double[] bd_decrypt(double bd_lat, double bd_lon) {
    double x = bd_lon - 0.0065, y = bd_lat - 0.006;
    double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
    double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
    double gg_lon = z * Math.cos(theta);
    double gg_lat = z * Math.sin(theta);
    return new double[] { gg_lon, gg_lat };
}

From source file:Main.java

public static double getAngleByTwoPostion(float[] startPoints, float[] endPoint) {
    double result = 0;

    float xDistance = endPoint[0] - startPoints[0];
    float yDistance = endPoint[1] - startPoints[1];

    result = Math.atan2((double) yDistance, (double) xDistance) * 180 / Math.PI;

    result += 270;//from w w  w.j  a  v a 2s. c  o  m

    return result;
}

From source file:Main.java

public static float angleInDegrees(float originX, float originY, float targetX, float targetY) {
    return (float) Math.toDegrees(Math.atan2(targetY - originY, targetX - originX));
}

From source file:Main.java

/**
 * converts cartesian coordinates (positive Y is down, positive X is right)
 * into an angle in degrees (0 degrees is up, clockwise is positive). The
 * angle is between 0 and 359, inclusive.
 * /*from w w  w  .j  a  va  2 s .  c o m*/
 * @param x
 * @param y
 * @return
 */
public static int toAngle(int x, int y) {
    return (int) ((Math.toDegrees(Math.atan2(y, x)) + 90) % 360);
}

From source file:Main.java

private static double[] bdToGaoDe(double bd_lat, double bd_lon) {
    double[] gd_lat_lon = new double[2];
    double PI = 3.1415926535897932384626 * 3000.0 / 180.0;
    double x = bd_lon - 0.0065, y = bd_lat - 0.006;
    double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI);
    double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * PI);
    gd_lat_lon[0] = z * Math.cos(theta);
    gd_lat_lon[1] = z * Math.sin(theta);
    return gd_lat_lon;
}

From source file:Main.java

public static void getEulerAngles(float[] headView, float[] output) {
    float pitch = (float) Math.asin((double) headView[6]);
    float yaw;/*  w  w  w  . j a v a  2s.co m*/
    float roll;
    if (Math.abs(headView[6]) < 0.9999999999D) {
        yaw = (float) Math.atan2((double) (-headView[2]), (double) headView[10]);
        roll = (float) Math.atan2((double) (-headView[4]), (double) headView[5]);
    } else {
        yaw = 0.0F;
        roll = (float) Math.atan2((double) headView[1], (double) headView[0]);
    }
    output[0] = -pitch;
    output[1] = -yaw;
    output[2] = -roll;
    float pitchAngle = (float) Math.toDegrees(output[0]);
    float yawAngle = (float) Math.toDegrees(output[1]);
    float rollAngle = (float) Math.toDegrees(output[2]);

    Log.e(TAG, String.format("pitchAngle=%f, yawAngle=%f, rollAngle=%f", pitchAngle, yawAngle, rollAngle));
}

From source file:Main.java

/**
 * Gets the angle from P(center, p1) to P(center, p2), the value range is [-180, 180].
 *
 * @param center center point//from ww w  . j  av  a2  s  . c om
 * @param p1     point 1
 * @param p2     point 2
 * @return angle
 */
public static float calculateRotationDegree(PointF center, PointF p1, PointF p2) {
    double angle1 = Math.atan2(p1.y - center.y, p1.x - center.x);
    double angle2 = Math.atan2(p2.y - center.y, p2.x - center.x);
    float angle = (float) Math.toDegrees(angle2 - angle1);
    if (angle > 180) {
        angle -= 360;
    } else if (angle < -180) {
        angle += 360;
    }
    return angle;
}