Example usage for java.lang Math PI

List of usage examples for java.lang Math PI

Introduction

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

Prototype

double PI

To view the source code for java.lang Math PI.

Click Source Link

Document

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Usage

From source file:Main.java

public static float getCurrentAzimuthDegrees() {
    return getCurrentAzimuth() * (float) (180 / Math.PI);
}

From source file:Main.java

/**
 * Convert degrees to radians./*from   ww w.  j a v a2 s.  c o  m*/
 */
public static float d2r(float d) {
    float r = 0.0f;
    r = (float) (d * (Math.PI / 180.0f));
    return r;
}

From source file:Main.java

public static float getAngleToCoordinates(double _direction, float _startX, float _startY, char _type) {
    if (_type == 'x') {
        return _startX + (float) Math.cos((_direction * Math.PI) / 180);
    } else {/* w  ww .java 2 s.co  m*/
        return _startY + (float) Math.sin((_direction * Math.PI) / 180);
    }
}

From source file:Main.java

/**
 * Normalizes an angle in radians to -Math.PI < angle <= Math.PI
 *//*from   w w w  .j a  va2  s .c o  m*/
public static double getPrincipleArgument(double angle) {
    double arg = angle;
    while (arg <= -Math.PI)
        arg += 2 * Math.PI;
    while (arg > Math.PI)
        arg -= 2 * Math.PI;
    return arg;
}

From source file:Main.java

public static int[] getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) {
    final int[] out = new int[2];

    final double E2 = (double) aLat * Math.PI / 180;
    final long sradiusa = 6378137;
    final long sradiusb = 6356752;
    final double J2 = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa;
    final double M2 = (double) Math.log((1 + Math.sin(E2)) / (1 - Math.sin(E2))) / 2
            - J2 * Math.log((1 + J2 * Math.sin(E2)) / (1 - J2 * Math.sin(E2))) / 2;
    final double B2 = (double) (1 << zoom);
    out[0] = (int) Math.floor(B2 / 2 - M2 * B2 / 2 / Math.PI);

    out[1] = (int) Math.floor((aLon + 180) / 360 * (1 << zoom));

    return out;/*from   ww  w . j ava  2s  . c  om*/
}

From source file:Main.java

public static double getLat(int inY, int zoom) {
    double y = Math.floor(inY * 256);
    double efactor = Math.exp((0.5 - y / 256 / Math.pow(2, zoom)) * 4 * Math.PI);
    double latitude = Math.asin((efactor - 1) / (efactor + 1)) * 180 / Math.PI;
    if (latitude < -90.0) {
        latitude = -90.0;// w ww.ja  v  a2s . c  o  m
    } else if (latitude > 90.0) {
        latitude = 90.0;
    }
    return latitude;
}

From source file:Main.java

public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
    double radLat1 = (lat_a * Math.PI / 180.0);
    double radLat2 = (lat_b * Math.PI / 180.0);
    double a = radLat1 - radLat2;
    double b = (lng_a - lng_b) * Math.PI / 180.0;
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;//from   ww  w. java 2 s  . co m
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static double goertzel(double[] data, double freq, double sr) {
    double s_prev = 0;
    double s_prev2 = 0;
    double coeff = 2 * Math.cos((2 * Math.PI * freq) / sr);
    double s;/*from w  ww.j ava 2  s.com*/
    for (int i = 0; i < data.length; i++) {
        double sample = data[i];
        s = sample + coeff * s_prev - s_prev2;
        s_prev2 = s_prev;
        s_prev = s;
    }
    double power = s_prev2 * s_prev2 + s_prev * s_prev - coeff * s_prev2 * s_prev;

    return power;
}

From source file:Main.java

/**
 * Get a Hann window.//from   ww  w .j  a va 2 s  . c om
 */
private static double[] hann(int windowWidth) {
    double[] envelopeArray = new double[windowWidth];
    for (int i = 0; i < windowWidth; i++) {
        envelopeArray[i] = 0.5 * (1 - Math.cos(2 * Math.PI * i / windowWidth));
    }
    return envelopeArray;
}

From source file:Main.java

private static void setPerspectiveM(float[] m, int offset, double fovy, double aspect, double zNear,
        double zFar) {
    Matrix.setIdentityM(m, offset);//w  w  w.ja v a2 s  .  c  om
    double ymax = zNear * Math.tan(fovy * Math.PI / 360.0);
    double ymin = -ymax;
    double xmin = ymin * aspect;
    double xmax = ymax * aspect;
    Matrix.frustumM(m, offset, (float) xmin, (float) xmax, (float) ymin, (float) ymax, (float) zNear,
            (float) zFar);
}