List of usage examples for java.lang Math PI
double PI
To view the source code for java.lang Math PI.
Click Source Link
From source file:Main.java
public static double getAngleByTwoPostion(float[] startPoints, float[] endPoint) { double result = 0; float xDistance = endPoint[0] - startPoints[0]; float yDistance = endPoint[1] - startPoints[1]; result = Math.atan2((double) yDistance, (double) xDistance) * 180 / Math.PI; result += 270;// w w w. ja v a 2 s . c o m return result; }
From source file:Main.java
public static void setRotateM(float[] rm, float a, float x, float y, float z) { rm[3] = 0;/*from www. j a va 2 s . com*/ rm[7] = 0; rm[11] = 0; rm[12] = 0; rm[13] = 0; rm[14] = 0; rm[15] = 1; a *= (float) (Math.PI / 180.0f); float s = (float) Math.sin(a); float c = (float) Math.cos(a); if (1.0f == x && 0.0f == y && 0.0f == z) { rm[5] = c; rm[10] = c; rm[6] = s; rm[9] = -s; rm[1] = 0; rm[2] = 0; rm[4] = 0; rm[8] = 0; rm[0] = 1; } else if (0.0f == x && 1.0f == y && 0.0f == z) { rm[0] = c; rm[10] = c; rm[8] = s; rm[2] = -s; rm[1] = 0; rm[4] = 0; rm[6] = 0; rm[9] = 0; rm[5] = 1; } else if (0.0f == x && 0.0f == y && 1.0f == z) { rm[0] = c; rm[5] = c; rm[1] = s; rm[4] = -s; rm[2] = 0; rm[6] = 0; rm[8] = 0; rm[9] = 0; rm[10] = 1; } else { float len = length(x, y, z); if (1.0f != len) { float recipLen = 1.0f / len; x *= recipLen; y *= recipLen; z *= recipLen; } float nc = 1.0f - c; float xy = x * y; float yz = y * z; float zx = z * x; float xs = x * s; float ys = y * s; float zs = z * s; rm[0] = x * x * nc + c; rm[4] = xy * nc - zs; rm[8] = zx * nc + ys; rm[1] = xy * nc + zs; rm[5] = y * y * nc + c; rm[9] = yz * nc - xs; rm[2] = zx * nc - ys; rm[6] = yz * nc + xs; rm[10] = z * z * nc + c; } }
From source file:Main.java
/************************************** * Math relevant/*from w ww .j a v a 2 s . c o m*/ *************************************/ public static double calculatePDFOfNormalDistribution(double mean, double std, double value) { double prob = Math.pow(Math.E, -Math.pow(value - mean, 2) / 2 / Math.pow(std, 2)) / (Math.sqrt(Math.PI * 2) * std); if (prob > 1) System.out.println(mean + " " + std + " " + value); return prob; }
From source file:Main.java
/** * conmputes hann window for given size/*from w ww.ja v a2 s.c om*/ * * @param n the length of the window * @return a Hann window as double[] */ public static double[] getHannWindow(int n) { double[] hann = new double[n]; for (int i = 0; i < n; i++) { hann[i] = 0.5 * (1 - Math.cos((2.0 * Math.PI * i) / (n - 1))); } return hann; }
From source file:fr.ritaly.dungeonmaster.audio.SoundSystem.java
public static void main(String[] args) throws Exception { // simpleTest(); // testClip(); SoundSystem.getInstance().init(new File("src\\main\\resources\\sound")); for (int i = 0; i < 72; i++) { SoundSystem.getInstance().play((i * 5.0f / 180.0f) * Math.PI, 1, AudioClip.GLOUPS); Thread.sleep(500);/*ww w .j a v a 2s .c o m*/ } for (int i = 0; i < 10; i++) { SoundSystem.getInstance().play(0, i, AudioClip.GLOUPS); Thread.sleep(250); } // SoundSystem.getInstance().setListener(new AudioListener() { // @Override // public Position getPosition() { // return new Position(0, 2, 0); // } // // @Override // public Direction getDirection() { // return Direction.NORTH; // } // // @Override // public void setDirection(Direction direction) { // } // }); // // for (int x = 0; x < 4; x++) { // for (int y = 0; y < 6; y++) { // if (((x == 0) || (x == 1)) // && ((y == 0) || (y == 5) || (y == 4))) { // continue; // } // // if (log.isDebugEnabled()) { // log.debug("(x,y) = (" + x + "," + y + ")"); // } // // SoundSystem.getInstance().play(new Position(x, y, 0), // AudioClip.GLOUPS); // // Thread.sleep(2000); // } // } // for (int i = 0; i < 10; i++) { // switch (RandomUtils.nextInt(3) + 1) { // case 1: // SoundSystem.getInstance().play(AudioClip.GLOUPS); // break; // case 2: // SoundSystem.getInstance().play(AudioClip.FIRE_BALL); // break; // case 3: // SoundSystem.getInstance().play(AudioClip.CHAMPION_DIED); // break; // default: // break; // } // // Thread.sleep(1000); // } while (true) { /* sleep for 1 second. */ try { Thread.sleep(1000); } catch (InterruptedException e) { // Ignore the exception. } SoundSystem.getInstance().dispose(); } }
From source file:Main.java
public static double tile2lat(int y, int aZoom) { final double MerkElipsK = 0.0000001; final long sradiusa = 6378137; final long sradiusb = 6356752; final double FExct = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa; final int TilesAtZoom = 1 << aZoom; double result = (y - TilesAtZoom / 2) / -(TilesAtZoom / (2 * Math.PI)); result = (2 * Math.atan(Math.exp(result)) - Math.PI / 2) * 180 / Math.PI; double Zu = result / (180 / Math.PI); double yy = ((y) - TilesAtZoom / 2); double Zum1 = Zu; Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct)) / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI))) * Math.pow(1 + FExct * Math.sin(Zum1), FExct))); while (Math.abs(Zum1 - Zu) >= MerkElipsK) { Zum1 = Zu;//from ww w. j a v a 2 s . c om Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct)) / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI))) * Math.pow(1 + FExct * Math.sin(Zum1), FExct))); } result = Zu * 180 / Math.PI; return result; }
From source file:Main.java
public static double distanceTo(double fromLat, double fromLng, double toLat, double toLng) { double fromLatRad = calculateRadian(fromLat); double fromLngRad = calculateRadian(fromLng); double toLatRad = calculateRadian(toLat); double toLngRad = calculateRadian(toLng); return EARTH_RADIUS * (Math.PI / 2 - Math.asin(Math.sin(fromLatRad) * Math.sin(toLatRad) + Math.cos(fromLngRad - toLngRad) * Math.cos(toLatRad) * Math.cos(fromLatRad))); }
From source file:Main.java
/** * Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 * Datum/*www . j av a2 s .co m*/ * * @return */ public static double[] MetersToLatLon(double mx, double my) { double lon = (mx / originShift) * 180.0; double lat = (my / originShift) * 180.0; lat = 180 / Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180.0)) - Math.PI / 2.0); return new double[] { lat, lon }; }
From source file:Main.java
public static double pixelYToLatitude(int pixelY, double zoomLevel, int tileSize) { int mapSize = getMapSize(zoomLevel, tileSize); if (pixelY < 0 || pixelY > mapSize) { throw new IllegalArgumentException( "invalid pixelY coordinate at zoom level " + zoomLevel + ": " + pixelY); }/*www . j a va2s . co m*/ double y = .5d - ((double) pixelY / mapSize); return 90d - 360d * Math.atan(Math.exp(-y * (2d * Math.PI))) / Math.PI; }
From source file:Main.java
/** * Rotate a set of coordinates by a given angle * @param c_x/*ww w . j ava2s . c o m*/ * @param c_y * @param thetab * @param x * @param y * @return */ public static double[] rotateCoord(double c_x, double c_y, double thetab, double x, double y) { double prc_x = x - c_x; double prc_y = y - c_y; double r = Math.sqrt(prc_x * prc_x + prc_y * prc_y); double theta = Math.atan2(prc_y, prc_x); theta = theta + thetab * Math.PI / 180.0; double pc_x = r * Math.cos(theta); double pc_y = r * Math.sin(theta); double p[] = new double[2]; p[0] = pc_x + c_x; p[1] = pc_y + c_y; return p; }