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.jiahuan.svgmapview.core.helper.map.SVGParser.java

private static float angle(float x1, float y1, float x2, float y2) {

    return (float) Math.toDegrees(Math.atan2(x1, y1) - Math.atan2(x2, y2)) % 360;
}

From source file:fr.fg.server.core.TerritoryManager.java

private static Polygon createPolygon(float[][] coords, int offset, int reduction) {
    int[] xpts = new int[coords.length], ypts = new int[coords.length];

    for (int j = 0; j < coords.length; j++) {
        // Calcule l'angle form par le segment suivant le point
        float dx1 = coords[(j + 1) % coords.length][0] - coords[j][0];
        float dy1 = coords[(j + 1) % coords.length][1] - coords[j][1];
        double angle1 = Math.atan2(dy1, dx1);

        // Calcule l'angle form par le segment prcdent le point
        float dx2 = coords[(j - 1 + coords.length) % coords.length][0] - coords[j][0];
        float dy2 = coords[(j - 1 + coords.length) % coords.length][1] - coords[j][1];
        double angle2 = Math.atan2(dy2, dx2);

        // Dtermine l'angle entre les deux segments, en supposant que le
        // polygone est convexe (angles < pi)
        double angle = (-angle1 - angle2) / 2;
        if (Math.abs(angle1 - angle2) > Math.PI)
            angle += Math.PI;// ww w  .ja v a 2  s. c o  m

        // Dcale le point vers l'intrieur du polygone selon l'angle form
        // par les deux segments
        xpts[j] = (int) (Math.round(coords[j][0]) + Math.cos(angle) * reduction + offset);
        ypts[j] = (int) (Math.round(-coords[j][1]) + Math.sin(angle) * reduction + offset);
    }

    return new Polygon(xpts, ypts, coords.length);
}

From source file:org.esa.beam.framework.datamodel.TiePointGrid.java

public final float getPixelFloat(final InterpInput in) {
    if (discontinuity != DISCONT_NONE) {
        if (isDiscontNotInit()) {
            initDiscont();// w  w w .j ava2 s. co  m
        }
        final float v = (float) (MathUtils.RTOD
                * Math.atan2(sinGrid.getPixelFloat(in), cosGrid.getPixelFloat(in)));
        return (v < 0.0 && discontinuity == DISCONT_AT_360) ? 360.0F + v : v; // = 180 + (180 - abs(v))
    }
    return interpolate(in.wi, in.wj, in.i0, in.j0);
}

From source file:biz.bokhorst.bpt.BPTService.java

public double distanceM(double userLat, double userLng, double venueLat, double venueLng) {
    double latDistance = Math.toRadians(userLat - venueLat);
    double lngDistance = Math.toRadians(userLng - venueLng);
    double a = (Math.sin(latDistance / 2) * Math.sin(latDistance / 2)) + (Math.cos(Math.toRadians(userLat)))
            * (Math.cos(Math.toRadians(venueLat))) * (Math.sin(lngDistance / 2)) * (Math.sin(lngDistance / 2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return 6371 * 1000 * c;
}

From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java

static private double _bearing(double lat1, double long1, double lat2, double long2) {
    double degToRad = Math.PI / 180.0;
    double phi1 = lat1 * degToRad;
    double phi2 = lat2 * degToRad;
    double lam1 = long1 * degToRad;
    double lam2 = long2 * degToRad;

    return Math.atan2(Math.sin(lam2 - lam1) * Math.cos(phi2),
            Math.cos(phi1) * Math.sin(phi2) - Math.sin(phi1) * Math.cos(phi2) * Math.cos(lam2 - lam1)) * 180
            / Math.PI;//from  w  ww.j  av a 2s . c  om
}

From source file:graph.eventhandlers.MyEditingGraphMousePlugin.java

private void transformArrowShape(Point2D down, Point2D out) {
    float x1 = (float) down.getX();
    float y1 = (float) down.getY();
    float x2 = (float) out.getX();
    float y2 = (float) out.getY();

    AffineTransform xform = AffineTransform.getTranslateInstance(x2, y2);

    float dx = x2 - x1;
    float dy = y2 - y1;
    float thetaRadians = (float) Math.atan2(dy, dx);
    xform.rotate(thetaRadians);/* w ww. j  av  a2s . com*/
    arrowShape = xform.createTransformedShape(rawArrowShape);
}

From source file:lu.fisch.unimozer.Diagram.java

private void drawExtends(Graphics2D g, Point pFrom, Point pTo) {
    int ARROW_SIZE = 16;
    double ARROW_ANGLE = Math.PI / 6;

    //g.setColor(Color.BLACK);
    double angle = Math.atan2(-(pFrom.y - pTo.y), pFrom.x - pTo.x);

    Point pArrow = new Point(pTo.x + (int) ((ARROW_SIZE - 2) * Math.cos(angle)),
            pTo.y - (int) ((ARROW_SIZE - 2) * Math.sin(angle)));

    // draw the arrow head
    int[] xPoints = { pTo.x, pTo.x + (int) ((ARROW_SIZE) * Math.cos(angle + ARROW_ANGLE)),
            pTo.x + (int) (ARROW_SIZE * Math.cos(angle - ARROW_ANGLE)) };
    int[] yPoints = { pTo.y, pTo.y - (int) ((ARROW_SIZE) * Math.sin(angle + ARROW_ANGLE)),
            pTo.y - (int) (ARROW_SIZE * Math.sin(angle - ARROW_ANGLE)) };

    g.drawPolygon(xPoints, yPoints, 3);//from  w w  w  .jav a  2  s.c  om
    g.drawLine(pFrom.x, pFrom.y, pArrow.x, pArrow.y);
}

From source file:org.hoteia.qalingo.core.domain.Store.java

public Double getDistanceFromInKm(String fromLatitude, String fromLongitude) {
    double earthRadius = Constants.EARTH_RADIUS;
    double dLat = Math.toRadians(new Double(getLatitude()) - new Double(fromLatitude));
    double dLng = Math.toRadians(new Double(getLongitude()) - new Double(fromLongitude));
    double sindLat = Math.sin(dLat / 2);
    double sindLng = Math.sin(dLng / 2);
    double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(new Double(fromLatitude)))
            * Math.cos(Math.toRadians(new Double(getLatitude())));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;
    return dist;/*  w ww. j  ava  2  s  .c  o  m*/
}

From source file:MouseNavigateTest.java

public static EulerAngles Eul_FromMatrix(float[][] M, int order) {
    EulerAngles ea = new EulerAngles();

    EulGetOrdInfo info = EulGetOrd(order);

    int i = info.i;
    int j = info.j;
    int k = info.k;
    int h = info.h;
    int n = info.n;
    int s = info.s;
    int f = info.f;

    if (s == EulRepYes) {
        double sy = Math.sqrt(M[i][j] * M[i][j] + M[i][k] * M[i][k]);
        if (sy > 16 * FLT_EPSILON) {
            ea.x = (float) Math.atan2(M[i][j], M[i][k]);
            ea.y = (float) Math.atan2(sy, M[i][i]);
            ea.z = (float) Math.atan2(M[j][i], -M[k][i]);
        } else {/*from  www .  jav  a2s .co  m*/
            ea.x = (float) Math.atan2(-M[j][k], M[j][j]);
            ea.y = (float) Math.atan2(sy, M[i][i]);
            ea.z = 0;
        }
    } else {
        double cy = Math.sqrt(M[i][i] * M[i][i] + M[j][i] * M[j][i]);
        if (cy > 16 * FLT_EPSILON) {
            ea.x = (float) Math.atan2(M[k][j], M[k][k]);
            ea.y = (float) Math.atan2(-M[k][i], cy);
            ea.z = (float) Math.atan2(M[j][i], M[i][i]);
        } else {
            ea.x = (float) Math.atan2(-M[j][k], M[j][j]);
            ea.y = (float) Math.atan2(-M[k][i], cy);
            ea.z = 0;
        }
    }
    if (n == EulParOdd) {
        ea.x = -ea.x;
        ea.y = -ea.y;
        ea.z = -ea.z;
    }
    if (f == EulFrmR) {
        float t = ea.x;
        ea.x = ea.z;
        ea.z = t;
    }
    ea.w = order;
    return (ea);
}

From source file:pl.dp.bz.poid.fouriertest.FourierProc.java

public double[][] getFourierImageArgument() {
    double[][] tab = new double[fourierImage.length][fourierImage[0].length];
    for (int x = 0; x < fourierImage.length; x++) {

        for (int y = 0; y < fourierImage[x].length; y++) {
            tab[x][y] = Math.atan2(fourierImage[x][y].getImaginary(), fourierImage[x][y].getReal());
        }//from w  ww .  j a v  a 2  s  .  c o m
    }

    return tab;
}