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[] bd09togcj02(double bd_lon, double bd_lat) {
    double x = bd_lon - 0.0065;
    double 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_lng = z * Math.cos(theta);
    double gg_lat = z * Math.sin(theta);
    return new double[] { gg_lng, gg_lat };
}

From source file:uk.co.modularaudio.util.math.FastMath.java

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

From source file:webservice.GPSDistance.java

public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
    double earthRadius = 6371000; //meters
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    float dist = (float) (earthRadius * c);

    return dist;//from w w w .  jav a 2  s  .  c o  m
}

From source file:Main.java

static void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) {
    // x1 and y1 are coordinates of circle or rectangle
    // x2 and y2 are coordinates of circle or rectangle, to this point is directed the arrow
    Graphics2D g = (Graphics2D) g1.create();
    double dx = x2 - x1;
    double dy = y2 - y1;
    double angle = Math.atan2(dy, dx);
    int len = (int) Math.sqrt(dx * dx + dy * dy);
    AffineTransform t = AffineTransform.getTranslateInstance(x1, y1);
    t.concatenate(AffineTransform.getRotateInstance(angle));
    g.transform(t);/*  w w  w  .jav  a2s . c  o m*/
    g.drawLine(0, 0, len, 0);
    int basePosition = len - ARROW_HEAD_SIZE.width;
    int height = ARROW_HEAD_SIZE.height;
    g.fillPolygon(new int[] { len, basePosition, basePosition, len }, new int[] { 0, -height, height, 0 }, 4);
}

From source file:Main.java

@SuppressWarnings("unused")
public static int getMatrixRotateDegrees(Matrix matrix) {
    synchronized (MATRIX_VALUES) {
        matrix.getValues(MATRIX_VALUES);
        final float skewX = MATRIX_VALUES[Matrix.MSKEW_X];
        final float scaleX = MATRIX_VALUES[Matrix.MSCALE_X];
        //noinspection SuspiciousNameCombination
        final int degrees = (int) Math.round(Math.atan2(skewX, scaleX) * (180 / Math.PI));
        if (degrees < 0) {
            return Math.abs(degrees);
        } else if (degrees > 0) {
            return 360 - degrees;
        } else {//from w  w  w. ja v a  2 s .c o  m
            return 0;
        }
    }
}

From source file:Main.java

public static double getAbsAngle(double y, double x) {

    double angle = 0.0F;
    // atan2 is positive in the lower right quadrant and negative in upper right quadrant and measured
    // from the horizontal (positive x-axis)
    angle = Math.IEEEremainder(360 + Math.toDegrees(Math.atan2(y, x)), 360);

    return angle;
}

From source file:Main.java

public static float computeCurvatureHK2003(float x0, float y0, float x1, float y1, float x2, float y2) {

    double kappa = 0.0D;

    float lB = distanceBetween2Points(x1, y1, x0, y0);
    float lF = distanceBetween2Points(x1, y1, x2, y2);
    float thetaB = (float) Math.atan2(x0 - x1, y0 - y1);
    float thetaF = (float) Math.atan2(x2 - x1, y2 - y1);

    float delta = Math.abs(thetaB - thetaF) / 2;

    kappa = (1 / lB + 1 / lF) * delta / 2;
    return (float) kappa;
}

From source file:Main.java

private static float transformAngle(Matrix m, float angleRadians) {
    // Construct and transform a vector oriented at the specified clockwise
    // angle from vertical.  Coordinate system: down is increasing Y, right is
    // increasing X.
    float[] v = new float[2];
    v[0] = (float) Math.sin(angleRadians);
    v[1] = (float) Math.cos(angleRadians);
    m.mapVectors(v);/*from w  ww  .  ja  v a2 s. c o  m*/
    // Derive the transformed vector's clockwise angle from vertical.
    float result = (float) Math.atan2(v[0], -v[1]);
    if (result < -Math.PI / 2) {
        result += Math.PI;
    } else if (result > Math.PI / 2) {
        result -= Math.PI;
    }
    return result;
}

From source file:Main.java

public static double accurateDistanceMeters(double lat1, double lng1, double lat2, double lng2) {
    double dlat = Math.sin(0.5 * (lat2 - lat1));
    double dlng = Math.sin(0.5 * (lng2 - lng1));
    double x = dlat * dlat + dlng * dlng * Math.cos(lat1) * Math.cos(lat2);
    return (2 * Math.atan2(Math.sqrt(x), Math.sqrt(Math.max(0.0, 1.0 - x)))) * EARTH_RADIUS_METERS;
}

From source file:Main.java

/**
 * Computes the bearing in radians between two points on Earth.
 *
 * @param lat1 Latitude of the first point
 * @param lon1 Longitude of the first point
 * @param lat2 Latitude of the second point
 * @param lon2 Longitude of the second point
 * @return Bearing between the two points in radians. A value of 0 means due
 *         north.//from w  ww .  j  av a 2s .co m
 */
public static double bearingRad(double lat1, double lon1, double lat2, double lon2) {
    double lat1Rad = Math.toRadians(lat1);
    double lat2Rad = Math.toRadians(lat2);
    double deltaLonRad = Math.toRadians(lon2 - lon1);

    double y = Math.sin(deltaLonRad) * Math.cos(lat2Rad);
    double x = Math.cos(lat1Rad) * Math.sin(lat2Rad)
            - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad);
    return Math.atan2(y, x);
}