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:frk.gpssimulator.support.NavUtils.java

/**
 * Returns coordinates of position which is given distance and bearing from given point.
 * @param pt1//from   www  .j  a v a  2s. c  o m
 * @param dist
 * @param brg
 * @return
 */
public static Point getPosition(Point pt1, double d, double brg) {
    if (Double.doubleToRawLongBits(d) == 0) {
        return pt1;
    }

    double lat1 = Math.toRadians(pt1.getLatitude());
    double lon1 = Math.toRadians(pt1.getLongitude());
    double brgAsRadians = Math.toRadians(brg);

    double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / EARTH_RADIUS_IN_METERS)
            + Math.cos(lat1) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(brgAsRadians));
    double x = Math.sin(brgAsRadians) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(lat1);
    double y = Math.cos(d / EARTH_RADIUS_IN_METERS) - Math.sin(lat1) * Math.sin(lat2);
    double lon2 = lon1 + Math.atan2(x, y);

    return new Point(Math.toDegrees(lat2), Math.toDegrees(lon2), null);

}

From source file:uk.org.todome.Util.java

public static double getDistanceBetween(GeoPoint point1, GeoPoint point2) {
    // Implemented from code at
    // http://www.movable-type.co.uk/scripts/latlong.html
    int R = 6371; // radius of Earth in km

    double lat2 = Math.toRadians(point2.getLatitudeE6() * 1e-6);
    double lat1 = Math.toRadians(point1.getLatitudeE6() * 1e-6);

    double dLat = lat2 - lat1;
    double dLon = Math.toRadians((point2.getLongitudeE6() - point1.getLongitudeE6()) * 1e-6);

    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = R * c;

    return d;/*from  ww w  . j a va2 s .  c o  m*/
}

From source file:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java

public static Dataset generateAzimuthalArray(double[] beamCentre, int[] shape, double min) {
    //Number of circles
    int n = (int) Math.floor((min + 180) / 360);
    double minInBase = (min - (360 * n));

    Dataset out = DatasetFactory.zeros(shape, Dataset.FLOAT64);
    PositionIterator iter = out.getPositionIterator();

    int[] pos = iter.getPos();

    //+0.5 for centre of pixel
    while (iter.hasNext()) {
        double val = Math.toDegrees(Math.atan2(pos[0] + 0.5 - beamCentre[1], pos[1] + 0.5 - beamCentre[0]));
        if (val < minInBase)
            val = val + 360;
        out.set(val + 360 * n, pos);
    }/*from  w  ww .  j  ava 2s .  c  o  m*/

    return out;

}

From source file:com.mapr.synth.drive.GeoPoint.java

public ObjectNode asJson(ObjectNode node) {
    node.set("latitude", nodeFactory.numberNode(180 / Math.PI * Math.asin(r.getZ())));
    node.set("longitude", nodeFactory.numberNode(180 / Math.PI * Math.atan2(r.getY(), r.getX())));
    return node;/*from   w  w w.  j a  v a 2  s.  c o  m*/
}

From source file:demo.support.NavUtils.java

/**
 * Returns coordinates of position which is given distance and bearing from given point.
 * @param pt1/*from w  ww  .  j  a va  2  s  .  com*/
 * @param dist
 * @param brg
 * @return
 */
public static Point getPosition(Point pt1, double d, double brg) {
    if (Double.doubleToRawLongBits(d) == 0) {
        return pt1;
    }

    double lat1 = Math.toRadians(pt1.getLatitude());
    double lon1 = Math.toRadians(pt1.getLongitude());
    double brgAsRadians = Math.toRadians(brg);

    double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / EARTH_RADIUS_IN_METERS)
            + Math.cos(lat1) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(brgAsRadians));
    double x = Math.sin(brgAsRadians) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(lat1);
    double y = Math.cos(d / EARTH_RADIUS_IN_METERS) - Math.sin(lat1) * Math.sin(lat2);
    double lon2 = lon1 + Math.atan2(x, y);

    return new Point(Math.toDegrees(lat2), Math.toDegrees(lon2));

}

From source file:org.esa.beam.util.math.FastMathTest.java

@Test
public void testMathATan2() {
    for (double i = 0; i < numItr; ++i) {
        double val = Math.atan2(i, i);
    }//from ww w . ja v  a  2s. c  o m
}

From source file:me.timothy.ddd.DDDUtils.java

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

From source file:org.optaplanner.examples.tsp.domain.location.Location.java

/**
 * The angle relative to the direction EAST.
 * @param location never null//from  www .j  a v a  2s  .c om
 * @return in Cartesian coordinates
 */
public double getAngle(Location location) {
    // Euclidean distance (Pythagorean theorem) - not correct when the surface is a sphere
    double latitudeDifference = location.latitude - latitude;
    double longitudeDifference = location.longitude - longitude;
    return Math.atan2(latitudeDifference, longitudeDifference);
}

From source file:com.l2jfree.gameserver.util.Util.java

/** Return degree value of object 2 to the horizontal line with object 1 being the origin */
public final static double calculateAngleFrom(int obj1X, int obj1Y, int obj2X, int obj2Y) {
    double angleTarget = Math.toDegrees(Math.atan2(obj2Y - obj1Y, obj2X - obj1X));

    return getValidDegree(angleTarget);
}

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

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