List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:Main.java
public static int getMapSize(double zoomLevel, int tileSize) { return (int) Math.pow(2d, getZoomLevelAsInt(zoomLevel)) * getTileSize(zoomLevel, tileSize); }
From source file:Util.java
/** * Extracts a decimal digit from a number * // w ww. j a v a 2 s . c o m * @param value * The number to extract from * @param place * The index of the digit to extract: 0 for units, 1 for * tens, 2 for hundreds, -1 for tenths, and so on * @return The designated digit */ public static int extractDigit(float value, int place) { float pow = (float) Math.pow(10, place); float powp = pow * (place < 0 ? -10 : 10); value %= powp; return (int) (value / pow); }
From source file:Main.java
public static double[] magnititute(double accx[], double accy[], double accz[]) { if (!((accx.length == accy.length) && (accy.length == accz.length))) { return null; }/* w w w. j a va2s . c o m*/ double result[] = new double[accx.length]; for (int i = 0; i < accx.length; i++) { result[i] = 0.0; double grav = SensorManager.GRAVITY_EARTH; result[i] += Math.pow(accx[i] / grav, 2.0); result[i] += Math.pow(accy[i] / grav, 2.0); result[i] += Math.pow(accz[i] / grav, 2.0); result[i] = Math.sqrt(result[i]); result[i] *= 310; } return result; }
From source file:Main.java
/** * Gets a float array of two lengths representing a rectangles width and height * The order of the corners in the input float array is: * 0------->1//from w ww . j av a2 s .com * ^ | * | | * | v * 3<-------2 * * @param corners the float array of corners (8 floats) * @return the float array of width and height (2 floats) */ public static float[] getRectSidesFromCorners(float[] corners) { return new float[] { (float) Math.sqrt(Math.pow(corners[0] - corners[2], 2) + Math.pow(corners[1] - corners[3], 2)), (float) Math.sqrt(Math.pow(corners[2] - corners[4], 2) + Math.pow(corners[3] - corners[5], 2)) }; }
From source file:Main.java
public static double calculateCosineSimilarity(List<Double> list1, List<Double> list2) { if (list1.size() != list2.size()) { System.err.println("Two lists must have the same dimensionality."); return 0; }/*from w w w . j av a2 s .c om*/ double dividend = 0, divisor1 = 0, divisor2 = 0; for (int i = 0; i < list1.size(); i++) { dividend += list1.get(i) * list2.get(i); divisor1 += Math.pow(list1.get(i), 2); divisor2 += Math.pow(list2.get(i), 2); } return dividend / (Math.sqrt(divisor1) * Math.sqrt(divisor2)); }
From source file:Main.java
public static int XYZtoRGB(float x, float y, float z) { x /= 100f;/*from w ww. j a v a 2 s . c o m*/ y /= 100f; z /= 100f; float r = x * 3.2406f + y * -1.5372f + z * -0.4986f; float g = x * -0.9689f + y * 1.8758f + z * 0.0415f; float b = x * 0.0557f + y * -0.2040f + z * 1.0570f; if (r > 0.0031308) { r = 1.055f * (float) Math.pow(r, 1 / 2.4f) - 0.055f; } else { r = 12.92f * r; } if (g > 0.0031308) { g = 1.055f * (float) Math.pow(g, 1 / 2.4f) - 0.055f; } else { g = 12.92f * g; } if (b > 0.0031308) { b = 1.055f * (float) Math.pow(b, 1 / 2.4f) - 0.055f; } else { b = 12.92f * b; } return 0xFF000000 | (((int) (r * 255.0f)) << 16) | (((int) (g * 255.0f)) << 8) | ((int) (b * 255.0f)); }
From source file:Main.java
public static double gps2km(final double lat_a, final double lng_a, final double lat_b, final double lng_b) { if (!isGpsValid(lng_a, lat_a) || !isGpsValid(lng_b, lat_b)) { return -1; }/*from www .j av a2s . c o m*/ final double radLat1 = (lat_a * Math.PI / 180.0); final double radLat2 = (lat_b * Math.PI / 180.0); final double a = radLat1 - radLat2; final double b = (lng_a - lng_b) * Math.PI / 180.0; final 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))); return s * EARTH_RADIUS; }
From source file:Main.java
public static boolean withPointRadius(PointF cur, PointF target, float radius) { double space_2 = Math.pow(Math.abs(cur.x - target.x), 2) + Math.pow(Math.abs(cur.y - target.y), 2); double space = Math.sqrt(space_2); if (radius > space) { return true; }/*from ww w .j a v a 2 s .co m*/ return false; }
From source file:Main.java
/** * Function to calculate the distance in meters from dbm rssi values. * http://rvmiller.com/2013/05/part-1-wifi-based-trilateration-on-android/ * * The function is based on Free Space Path Loss, and may not work with * indoor signal propagation.//from ww w .j a va2 s .c om * * @param levelInDb RSSI value. * @param freqInMHz Frequency of the sending device. * @return Distance in meters. */ public static double distanceFSPL(double levelInDb, double freqInMHz) { double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0; return Math.pow(10.0, exp); }
From source file:Main.java
/** * Calculates distance using Free-space path loss. Constant -27.55 is used for calculations, where frequency is in MHz and distance in meters. * FSPL(dB) = 20 log(d) + 20 log(f) - 27.55; d distance from the transmitter [m], f signal frequency [MHz] * * @param level measured RSSI [dBm]/* www. j a v a2 s .c om*/ * @param freq WiFi frequency [MHz] * @return distance from AP [m] */ public static double calculateDistance(double level, double freq) { double exp = (27.55 - (20 * Math.log10(freq)) + Math.abs(level)) / 20.0; return Math.pow(10.0, exp); }