Example usage for java.lang Math atan

List of usage examples for java.lang Math atan

Introduction

In this page you can find the example usage for java.lang Math atan.

Prototype

public static double atan(double a) 

Source Link

Document

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.

Usage

From source file:au.org.ala.biocache.web.MapController.java

private double convertMetersToLat(double meters) {
    return 180.0 / Math.PI * (2 * Math.atan(Math.exp(meters / 20037508.342789244 * Math.PI)) - Math.PI / 2.0);
}

From source file:msi.gaml.operators.Maths.java

@operator(value = "atan", can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "Returns the value (in the interval [-90,90], in decimal degrees) of the arctan of the operand (which can be any real number).", masterDoc = true, examples = @example(value = "atan (1)", equals = "45.0"), see = {
        "acos", "asin", "tan" })
public static Double atan(final Double rv) {
    return Math.atan(rv) * toDeg;
}

From source file:msi.gaml.operators.Maths.java

@operator(value = "atan", can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "the arctan of the operand")
public static Double atan(final Integer rv) {
    return Math.atan(rv) * toDeg;
}

From source file:gbt.ubt.tool.Orthorectifier.java

public static double vincentyFormulae(double lat1, double long1, double lat2, double long2) {
    double latitude1 = deg2rad(lat1);
    double longitude1 = deg2rad(long1);
    double latitude2 = deg2rad(lat2);
    double longitude2 = deg2rad(long2);
    double a = 6378137.0;
    double f = 1.0 / 298.257223563;
    double b = (1.0 - f) * a;
    double u1 = Math.atan((1.0 - f) * Math.tan(latitude1));
    double u2 = Math.atan((1.0 - f) * Math.tan(latitude2));
    double L = longitude2 - longitude1;
    double lambda = L;
    double diff = 1.0;
    double tol = 10.0e-8;
    double cos2Alpha = 0.0;
    double sinOmega = 0.0;
    double cos2OmegaM = 0.0;
    double cosOmega = 0.0;
    double omega = 0.0;
    while (diff > tol) {
        sinOmega = Math.sqrt(Math.pow((Math.cos(u2) * Math.sin(lambda)), 2) + (Math
                .pow(((Math.cos(u1) * Math.sin(u2)) - (Math.sin(u1) * Math.cos(u2) * Math.cos(lambda))), 2)));
        cosOmega = (Math.sin(u1) * Math.sin(u2)) + (Math.cos(u1) * Math.cos(u2) * Math.cos(lambda));
        omega = Math.atan(sinOmega / cosOmega);
        double sinAlpha = (Math.cos(u1) * Math.cos(u2) * Math.sin(lambda)) / Math.sin(omega);
        cos2Alpha = 1 - (Math.pow(sinAlpha, 2));
        cos2OmegaM = cosOmega - ((2 * Math.sin(u1) * Math.sin(u2)) / cos2Alpha);
        double C = (f / 16.0) * cos2Alpha * (4 + (f * (4 - (3 * cos2Alpha))));
        double lambdaNew = L + ((1 - C) * f * sinAlpha * (omega
                + (C * sinOmega * (cos2OmegaM + (C * cosOmega * (-1 + (2 * Math.pow(cos2OmegaM, 2))))))));
        diff = Math.abs(lambdaNew - lambda);
        lambda = lambdaNew;/*from w w w.ja  v  a  2  s .c o  m*/
    }
    double uSquared = cos2Alpha * ((Math.pow(a, 2) - Math.pow(b, 2)) / Math.pow(b, 2));
    double A = 1 + ((uSquared / 16384.0)
            * (4096.0 + (uSquared * (-768.0 + (uSquared * (320.0 - (175.0 * uSquared)))))));
    double B = (uSquared / 1024.0) * (256.0 + (uSquared * (-128.0 + (uSquared * (74.0 - (47.0 * uSquared))))));
    double deltaOmega = B * sinOmega * (cos2OmegaM
            + (0.25 * B * ((cosOmega * (-1 + (2 * Math.pow(cos2OmegaM, 2)))) - ((1.0 / 6.0) * B * cos2OmegaM
                    * (-3.0 + (4.0 * Math.pow(sinOmega, 2))) * (-3.0 + (4.0 * Math.pow(cos2OmegaM, 2)))))));
    double s = b * A * (omega - deltaOmega);
    return s;
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphNode.java

/**
 * Draws an arrow head at the correct angle
 *
 * @param g     The Java2D Graphics/*from www  .  jav  a 2  s .  com*/
 * @param tailX position X on target node
 * @param tailY position Y on target node
 * @param headX position X on source node
 * @param headY position Y on source node
 */
private static void drawArrow(final Graphics2D g, final int tailX, final int tailY, final int headX,
        final int headY) {

    final double t1 = Math.abs(headY - tailY);
    final double t2 = Math.abs(headX - tailX);
    double theta = Math.atan(t1 / t2);
    if (headX >= tailX) {
        if (headY > tailY)
            theta = Math.PI + theta;
        else
            theta = -(Math.PI + theta);
    } else if (headX < tailX && headY > tailY)
        theta = 2 * Math.PI - theta;
    final double cosTheta = FastMath.cos(theta);
    final double sinTheta = FastMath.sin(theta);

    final Point p2 = new Point(-8, -3);
    final Point p3 = new Point(-8, +3);

    int x = (int) Math.round((cosTheta * p2.x) - (sinTheta * p2.y));
    p2.y = (int) Math.round((sinTheta * p2.x) + (cosTheta * p2.y));
    p2.x = x;
    x = (int) Math.round((cosTheta * p3.x) - (sinTheta * p3.y));
    p3.y = (int) Math.round((sinTheta * p3.x) + (cosTheta * p3.y));
    p3.x = x;

    p2.translate(tailX, tailY);
    p3.translate(tailX, tailY);

    Stroke oldStroke = g.getStroke();
    g.setStroke(new BasicStroke(2));
    g.drawLine(tailX, tailY, headX, headY);
    g.drawLine(tailX, tailY, p2.x, p2.y);
    g.drawLine(p3.x, p3.y, tailX, tailY);
    g.setStroke(oldStroke);
}

From source file:com.morninz.ninepinview.widget.NinePINView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // draw circles around center points and connection line
    int drawnCount = mDrawnPoints.size();
    for (int j = 0; j < drawnCount; j++) {
        Point p1 = mDrawnPoints.get(j);
        canvas.drawCircle(p1.x, p1.y, mCircleRadius, mCirclePaint);
        if (j + 1 < drawnCount) {
            Point p2 = mDrawnPoints.get(j + 1);
            canvas.drawCircle(p2.x, p2.y, mCircleRadius, mCirclePaint);
            canvas.drawLine(p1.x, p1.y, p2.x, p2.y, mLinePaint);
            if (mWillDrawWrongTriangle) {
                // compute the wrong triangle's direction of this point.
                float angle = 0.f;
                if (p2.y == p1.y) {// x-axis
                    angle = p2.x > p1.x ? 0.f : 180.f;
                } else if (p2.x == p1.x) { // y-axis
                    angle = p2.y > p1.y ? 90.f : -90.f;
                } else {// in quadrants
                    double tanA = ((double) p2.y - (double) p1.y) / ((double) p2.x - (double) p1.x);
                    // in 1 or 4 quadrant
                    angle = (float) (Math.atan(tanA) * 180 / Math.PI);
                    // in 2 or 3 quadrant
                    if (p2.x < p1.x) {
                        angle += 180.f;/*  www.  j  av a  2 s . c  om*/
                    }
                }
                Log.d(TAG, "angle " + angle);
                canvas.save();
                canvas.rotate(angle, p1.x, p1.y);
                canvas.drawPath(mWrongPaths[p1.index], mWrongPaint);
                canvas.restore();
            }
        }
    }

    // draw extra connection line
    if (mLastDrawnPoint != null) {
        canvas.drawLine(mLastDrawnPoint.x, mLastDrawnPoint.y, mCurrX, mCurrY, mLinePaint);
    }

    // draw 9 center points
    for (int i = 0; i < POINT_COUNT; i++) {
        Point p = mCenterPoints[i];
        canvas.drawCircle(p.x, p.y, mPointSize, mPointPaint);
    }
}

From source file:org.kalypsodeegree_impl.graphics.displayelements.RasterDisplayElement_Impl.java

private double calculateSlope(final int i, final int j, final double[][] values, final double xres,
        final double yres, final double z) {
    final double scale = 1.0;
    final double az = 315.0;
    final double alt = 75.0;

    if (i == 0 || i > values.length - 2)
        return Double.NaN;

    if (j == 0 || j > values[0].length - 2)
        return Double.NaN;

    // First Slope ...
    final double x = z * //
            (values[i - 1][j - 1] + values[i - 1][j] + values[i - 1][j] + values[i - 1][j + 1]
                    - values[i + 1][j - 1] - values[i + 1][j] - values[i + 1][j] - values[i + 1][j + 1]) //
            / (8.0 * xres * scale);//  w w w .  j  ava2 s .  co  m

    final double y = z * //
            (values[i - 1][j + 1] + values[i][j + 1] + values[i][j + 1] + values[i + 1][j + 1]
                    - values[i - 1][j - 1] - values[i][j - 1] - values[i][j - 1] - values[i + 1][j - 1]) //
            / (8.0 * yres * scale);

    final double slope = 90.0 - Math.toDegrees(Math.atan(Math.sqrt(x * x + y * y)));

    // ... then aspect...
    final double aspect = Math.atan2(x, y);

    // ... then the shade value
    final double cang = Math.sin(Math.toRadians(alt)) * Math.sin(Math.toRadians(slope)) + //
            Math.cos(Math.toRadians(alt)) * Math.cos(Math.toRadians(slope)) //
                    * Math.cos(Math.toRadians(az - 90.0) - aspect);

    if (cang <= 0.0)
        return 1.0;

    return cang;
}

From source file:sphericalGeo.SphericalDiffusionModel.java

public static void main(String[] args) {
    for (int k = 1; k < NN + 1; ++k) {
        phi[k - 1] = Math.pow(2.0, -k);
        ap[k - 1] = Math.atan(phi[k - 1]);
    }/*from   w  w  w.  j  av a2  s  .c o  m*/

    // speed test
    final int N = args.length > 0 ? Integer.parseInt(args[0]) : 10000000;
    final int seed = args.length > 1 ? Integer.parseInt(args[1]) : 123;
    Randomizer.setSeed(seed);
    if (args.length > 2) {
        usemyacos = (Integer.parseInt(args[2]) != 0);
    }
    if (args.length > 3) {
        usemyat = (Integer.parseInt(args[3]) != 0);
    }
    boolean pre = true;
    if (args.length > 4) {
        pre = (Integer.parseInt(args[4]) != 0);
    }

    long start;
    double a0 = 0, a1 = 1;
    double x0 = 0, x1 = 1;
    if (pre) {
        double[][] point = new double[N][2];
        for (int i = 0; i < N; i++) {
            point[i][0] = Randomizer.nextDouble() * 180 - 90;
            point[i][1] = Randomizer.nextDouble() * 360 - 180;
        }

        System.err.println("Starting...");

        start = System.currentTimeMillis();

        for (int i = 0; i < N; i++) {
            double[] cart = SphericalDiffusionModel.spherical2Cartesian(point[i][0], point[i][1]);
            double[] sper = SphericalDiffusionModel.cartesian2Sperical(cart, usemyacos);
            x0 += sper[0];
            x1 += sper[1];
            a0 += point[i][0];
            a1 += point[i][1];
        }
    } else {
        double[] point = new double[2];
        System.err.println("Starting...");

        start = System.currentTimeMillis();

        for (int i = 0; i < N; i++) {
            point[0] = Randomizer.nextDouble() * 180 - 90;
            point[1] = Randomizer.nextDouble() * 360 - 180;
            double[] cart = SphericalDiffusionModel.spherical2Cartesian(point[0], point[1]);
            double[] sper = SphericalDiffusionModel.cartesian2Sperical(cart, usemyacos);
            x0 += sper[0];
            x1 += sper[1];
            a0 += point[0];
            a1 += point[1];
        }
    }

    long end = System.currentTimeMillis();
    System.err.println("N : " + N + " seed: " + seed + (usemyacos ? " jhacos" : " fastmath")
            + (usemyat ? " jhatan2" : " atanapprox"));
    System.err.println("Expeted sum: " + a0 + " " + a1);
    System.err.println("Calculated : " + x0 + " " + x1);
    System.err.println(
            "Diff : " + Math.abs(a0 - x0) / Math.max(a0, x0) + " " + Math.abs(a1 - x1) / Math.max(a1, x1));

    System.err.println("Runtime: " + ((end - start) / 1000.0) + " seconds");
}

From source file:edu.tum.cs.vis.model.util.algorithm.ACCUM.java

/**
 * Calculate hue and saturation for curvature properties.
 * //from  ww  w .  j av a  2  s.  com
 * @param curvatures
 *            maps curvatures to vertices
 * @param smoothSigma
 *            Sigma value for smoothing the curvature. Set to 0 to disable smoothing.
 * @param m
 *            model needed to calculate hue saturation scale
 */
private static void setCurvatureHueSaturation(HashMap<Vertex, Curvature> curvatures, Model m,
        float smoothSigma) {
    if (smoothSigma > 0.0f) {
        float scaledSigma = smoothSigma * m.feature_size();
        diffuse_curv(m, curvatures, scaledSigma);
    }

    float cscale = 120.0f * typical_scale(curvatures, m);
    cscale = cscale * cscale;
    int nv = m.getVertices().size();
    for (int i = 0; i < nv; i++) {
        Curvature c = curvatures.get(m.getVertices().get(i));
        float H = 0.5f * (c.getCurvatureMax() + c.getCurvatureMin()); // mean curvature
        float K = c.getCurvatureMax() * c.getCurvatureMin(); // gaussian curvature
        float h = (float) (4.0f / 3.0f * Math.abs(Math.atan2(H * H - K, H * H * Math.signum(H))));
        float s = (float) ((2 / Math.PI) * Math.atan((2.0f * H * H - K) * cscale));
        c.setHue(h);
        c.setSaturation(s);
    }
}

From source file:app.akexorcist.gdaplibrary.GoogleDirection.java

private LatLng getNewPosition(LatLng begin, LatLng end) {
    double lat = Math.abs(begin.latitude - end.latitude);
    double lng = Math.abs(begin.longitude - end.longitude);

    double dis = Math.sqrt(Math.pow(lat, 2) + Math.pow(lng, 2));
    if (dis >= animateDistance) {
        double angle = -1;

        if (begin.latitude <= end.latitude && begin.longitude <= end.longitude)
            angle = Math.toDegrees(Math.atan(lng / lat));
        else if (begin.latitude > end.latitude && begin.longitude <= end.longitude)
            angle = (90 - Math.toDegrees(Math.atan(lng / lat))) + 90;
        else if (begin.latitude > end.latitude && begin.longitude > end.longitude)
            angle = Math.toDegrees(Math.atan(lng / lat)) + 180;
        else if (begin.latitude <= end.latitude && begin.longitude > end.longitude)
            angle = (90 - Math.toDegrees(Math.atan(lng / lat))) + 270;

        double x = Math.cos(Math.toRadians(angle)) * animateDistance;
        double y = Math.sin(Math.toRadians(angle)) * animateDistance;
        totalAnimateDistance += animateDistance;
        double finalLat = begin.latitude + x;
        double finalLng = begin.longitude + y;

        return new LatLng(finalLat, finalLng);
    } else {//from  w  w  w  .ja  v  a  2 s.c o  m
        return end;
    }
}