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:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java

/**
 * // http://www.movable-type.co.uk/scripts/latlong.html
 * // Under Creative Commons License http://creativecommons.org/licenses/by/3.0/
 * Calculate distance between two GPS co-ordinate
 * @param lat1//  w  w  w  . j  a v a  2s .c  om
 * @param lon1
 * @param lat2
 * @param lon2
 * @return
 */
public static double getDistanceMeters(double lat1, double lon1, double lat2, double lon2) {
    int r = 6371;
    double dLat = Math.abs(lat2 - lat1) * (Math.PI / 180);
    double dLon = Math.abs(lon2 - lon1) * (Math.PI / 180);
    double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) + (Math.cos(lat1 * (Math.PI / 180))
            * Math.cos(lat2 * (Math.PI / 180)) * Math.sin(dLon / 2) * Math.sin(dLon / 2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = r * c * 1000; // show as meters

    return Double.parseDouble(mDecimalFormat.format(d));
}

From source file:GraphicsUtil.java

static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) {
    double offs = headAngle * Math.PI / 180.0;
    double angle = Math.atan2(y0 - y1, x0 - x1);
    int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1,
            x1 + (int) (headLength * Math.cos(angle - offs)) };
    int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1,
            y1 + (int) (headLength * Math.sin(angle - offs)) };
    g.drawLine(x0, y0, x1, y1);/*from  w ww.  java  2s .  co m*/
    g.drawPolyline(xs, ys, 3);
}

From source file:edu.mit.fss.tutorial.part2.MobileElement.java

@Override
public double getLongitude() {
    return Math.toDegrees(Math.atan2(position.getY(), position.getX()));
}

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static Number opPow(MutableNumber out, Number a, double b) {
    double m = Math.pow(FastMath.hypot(a.r(), a.i()), b);
    double f = Math.atan2(a.i(), a.r()) * b;
    return out.set(m * Math.cos(f), m * Math.sin(f));
}

From source file:org.gearvrf.keyboard.util.Util.java

public static float getYRotationAngle(Vector3D rotatingVector, GVRSceneObject targetObject) {
    return (float) Math.toDegrees(Math.atan2(targetObject.getTransform().getPositionX() - rotatingVector.getX(),
            targetObject.getTransform().getPositionZ() - rotatingVector.getZ()));
}

From source file:com.example.aaron.test.poseView.java

public double getYaw() {
    return Math.atan2(2 * (w * k), (w * w - k * k)) * 57.2957795;
}

From source file:com.duy.pascal.interperter.libraries.math.MathLib.java

@PascalMethod(description = "Return Arctangent of (y/x)")
public double ArcTan2(double y, double x) {
    return Math.atan2(y, x);
}

From source file:ceptraj.tool.Bearing.java

public static double bearing(Point p1, Point p2) {
    double bearing = 0;
    if (p1 != null && p2 != null) {

        switch (ConfigProvider.getSpaceType()) {
        case lat_lon:
            //In case of lat-lon space
            double p1LatRad = Math.toRadians(p1.getLat());
            double p2LatRad = Math.toRadians(p2.getLat());

            double p1LonRad = Math.toRadians(p1.getLon());
            double p2LonRad = Math.toRadians(p2.getLon());

            bearing = (Math//from   w  w  w  .j av a 2 s. c  o  m
                    .toDegrees((Math.atan2(Math.sin(p2LonRad - p1LonRad) * Math.cos(p2LatRad),
                            Math.cos(p1LatRad) * Math.sin(p2LatRad)
                                    - Math.sin(p1LatRad) * Math.cos(p2LatRad) * Math.cos(p2LonRad - p1LonRad))))
                    + 360) % 360;
            break;
        case cartesian:
            //In case of cartesian space
            double dy = p2.y - p1.y;
            double dx = p2.x - p1.x;
            bearing = 90 - (180 / Math.PI) * Math.atan2(dy, dx);
            if (bearing < 0) {
                bearing += 360;
            }
            break;
        }
    }

    return bearing;
}

From source file:org.elasticsoftware.elasticactors.geoevents.Coordinate.java

public double distance(final double latitude, final double longitude, LengthUnit unit) {
    double a = 6378137, b = 6356752.3142;
    // ellipsiod//  w  ww.ja  v a  2 s  .c o m
    double L = (longitude - this.longitude) * degToRad;
    double U1 = Math.atan((1 - f) * Math.tan(this.latitude * degToRad));
    double U2 = Math.atan((1 - f) * Math.tan(latitude * degToRad));
    double sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
    double sinU2 = Math.sin(U2), cosU2 = Math.cos(U2);

    double cosSqAlpha, sinSigma, cos2SigmaM, cosSigma, sigma;

    double lambda = L, lambdaP, iterLimit = 20;
    do {
        double sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda);
        sinSigma = Math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda)
                + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
        if (sinSigma == 0)
            return 0; // co-incident points
        cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
        sigma = Math.atan2(sinSigma, cosSigma);
        double sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
        cosSqAlpha = 1 - sinAlpha * sinAlpha;
        cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha;
        if (cos2SigmaM == Double.NaN)
            cos2SigmaM = 0; // equatorial line: cosSqAlpha=0 (?6)
        double C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha));
        lambdaP = lambda;
        lambda = L + (1 - C) * f * sinAlpha
                * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
    } while (Math.abs(lambda - lambdaP) > EPSILON && --iterLimit > 0);

    if (iterLimit == 0)
        return Double.NaN;
    double uSquared = cosSqAlpha * (a * a - b * b) / (b * b);
    double A = 1 + uSquared / 16384 * (4096 + uSquared * (-768 + uSquared * (320 - 175 * uSquared)));
    double B = uSquared / 1024 * (256 + uSquared * (-128 + uSquared * (74 - 47 * uSquared)));
    double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)
            - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
    double s = b * A * (sigma - deltaSigma);

    return unit.convert(s, LengthUnit.METRES);
}

From source file:org.gearvrf.keyboard.util.Util.java

public static float getZRotationAngle(GVRSceneObject rotatingObject, GVRSceneObject targetObject) {
    float angle = (float) Math.toDegrees(Math.atan2(
            targetObject.getTransform().getPositionY() - rotatingObject.getTransform().getPositionY(),
            targetObject.getTransform().getPositionX() - rotatingObject.getTransform().getPositionX()));

    return angle;
}