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:Main.java

static public final float atan(float value) {
    return (float) Math.atan(value);
}

From source file:Main.java

/**
 * Reconvert back to lat/lon.//from   w  w  w  .jav a  2  s.  c o m
 * 
 * @param x x value
 * @param y y value
 * @param z z value
 * 
 * @return point in lat,lon
 */
private static double[] cartesian2latlon(double x, double y, double z) {
    return new double[] { Math.atan(y / x), Math.acos(z / EARTH_RADIUS) };
}

From source file:Main.java

/**
 * Gets straighten matrix for the given bounds and degrees.
 *//*from  w w w  . j  a  v  a 2  s  .  c o m*/
public static void getStraightenMatrix(RectF bounds, float degrees, Matrix matrix) {
    matrix.reset();
    if ((degrees != 0) && !bounds.isEmpty()) {
        float w = bounds.width() / 2;
        float h = bounds.height() / 2;
        float adjustAngle;
        if ((degrees < 0 && w > h) || (degrees > 0 && w <= h)) {
            // The top left point is the boundary.
            adjustAngle = (float) Math.atan(h / -w) + MATH_PI + degrees * DEGREES_TO_RADIAN;
        } else {
            // The top right point is the boundary.
            adjustAngle = (float) Math.atan(h / w) - MATH_PI + degrees * DEGREES_TO_RADIAN;
        }
        float radius = (float) Math.hypot(w, h);
        float scaleX = (float) Math.abs(radius * Math.cos(adjustAngle)) / w;
        float scaleY = (float) Math.abs(radius * Math.sin(adjustAngle)) / h;
        float scale = Math.max(scaleX, scaleY);

        postRotateMatrix(degrees, new RectF(bounds), matrix);
        matrix.postScale(scale, scale);
    }
}

From source file:Main.java

static double distanceFromPointOnArc(double dA, double dB, double dAB) {
    // In spherical trinagle ABC
    // a is length of arc BC, that is dB
    // b is length of arc AC, that is dA
    // c is length of arc AB, that is dAB
    // We rename parameters so following formulas are more clear:
    double a = dB;
    double b = dA;
    double c = dAB;

    // First, we calculate angles alpha and beta in spherical triangle ABC
    // and based on them we decide how to calculate the distance:
    if (Math.sin(b) * Math.sin(c) == 0.0 || Math.sin(c) * Math.sin(a) == 0.0) {
        // It probably means that one of distance is n*pi, which gives around 20000km for n = 1,
        // unlikely for Denmark, so we should be fine.
        return -1.0;
    }//from  w  w  w. j  a va 2 s  .  c o m

    double alpha = Math.acos((Math.cos(a) - Math.cos(b) * Math.cos(c)) / (Math.sin(b) * Math.sin(c)));
    double beta = Math.acos((Math.cos(b) - Math.cos(c) * Math.cos(a)) / (Math.sin(c) * Math.sin(a)));

    // It is possible that both sinuses are too small so we can get nan when dividing with them
    if (Double.isNaN(alpha) || Double.isNaN(beta)) {
        return -1.0;
    }

    // If alpha or beta are zero or pi, it means that C is on the same circle as arc AB,
    // we just need to figure out if it is between AB:
    if (alpha == 0.0 || beta == 0.0) {
        return (dA + dB > dAB) ? Math.min(dA, dB) : 0.0;
    }

    // If alpha is obtuse and beta is acute angle, then
    // distance is equal to dA:
    if (alpha > Math.PI / 2 && beta < Math.PI / 2)
        return -1;

    // Analogously, if beta is obtuse and alpha is acute angle, then
    // distance is equal to dB:
    if (beta > Math.PI / 2 && alpha < Math.PI / 2)
        return -1;

    // Again, unlikely, since it would render at least pi/2*EARTH_RADIUS_IN_METERS, which is too much.
    if (Math.cos(a) == 0.0)
        return -1;

    double x = Math.atan(-1.0 / Math.tan(c) + (Math.cos(b) / (Math.cos(a) * Math.sin(c))));

    return x;
}

From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java

public static double atan(final double x) {
    return Math.atan(x);
}

From source file:org.apache.hadoop.hive.ql.udf.UDFAtan.java

public DoubleWritable evaluate(DoubleWritable x) {
    if (x == null) {
        return null;
    } else {/*  w  w  w . j  a v a  2 s . com*/
        result.set(Math.atan(x.get()));
        return result;
    }
}

From source file:org.renjin.primitives.MathTest.java

@Test
public void unaryCall() {
    assertThat(eval("atan(1)"), equalTo(c(Math.atan(1))));
}

From source file:dnimp.Statistics.java

private double studT(double t, int n) {
    t = Math.abs(t);// ww  w . j a  v a 2 s.com
    double th = Math.atan(t / Math.sqrt(n));
    double sth = Math.sin(th);
    double cth = Math.cos(th);

    if (n == 1)
        return 1 - th / (Math.PI / 2.0);

    if (n % 2 == 1) {
        return 1 - (th + sth * cth * statCom(cth * cth, 2, n - 3, -1)) / (Math.PI / 2.0);
    } else {
        return 1 - sth * statCom(cth * cth, 1, n - 3, -1);
    }
}

From source file:com.cloudmade.api.Utils.java

/**
 * Convert tile coordinates pair to latitude, longitude
 * //from w  ww.  j  a  v  a 2 s  . c  o  m
 * @param xtile
 * @param ytile
 * @param zoom
 * @return Latitude, longitude pair
 */
public static final double[] tilenums2latlon(int xtile, int ytile, int zoom) {
    double factor = 1 << zoom;
    double latitude = Math.atan(Math.sinh(Math.PI * (1 - 2 * ytile / factor)));
    double longitude = (xtile * 360.0 / factor) - 180.0;
    return new double[] { Math.toDegrees(latitude), longitude };
}

From source file:eu.betaas.taas.securitymanager.taastrustmanager.taastrustcalculator.ScalabilityCalculator.java

public float calculateTrustAspect(String thingServiceId) {
    // Check enough data is available
    if (tsData.length < 4) {
        logger.error("Not enough data is available -> Returning default value.");
        return 2.0f;
    }//ww  w.  j  a v a2s  .c  om

    // 1 - Scalability of memory in time
    // 1.1 - Calculate slope of the line generated with linear regression
    float slope = linearRegressionSlope(tsData);
    logger.debug("Memory usage slope: " + slope);

    // 1.2 - Calculate the angle corresponding to the slope
    double angle = Math.toDegrees(Math.atan(slope));
    logger.debug("Memory usage angle: " + angle);

    // 1.3 - Determine trust value for that angle
    float memoryTrust = 2.5f;
    if (angle <= 0.0) {
        memoryTrust = 4.8f;
    } else if (angle > 65.0) {
        memoryTrust = 0.05f;
    } else {
        memoryTrust = ((66.0f - (float) angle) * 4.5f) / 66.0f;
    }
    logger.debug("Memory Trust: " + memoryTrust);

    // 2 - Scalability of response time as requests grow

    return memoryTrust;
}