List of usage examples for java.lang Math sqrt
@HotSpotIntrinsicCandidate public static double sqrt(double a)
From source file:Main.java
public static double getAcceleration(SensorEvent event) { final float x = event.values[0]; final float y = event.values[1]; final float z = event.values[2]; double sqrt = Math.sqrt(Math.abs(x * x) + Math.abs(y * y) + Math.abs(z * z)); return sqrt;/* w w w.j a v a 2s .co m*/ }
From source file:Main.java
public static double calScaleRatio(int originalWidth, int originalHeight, int targetWidth, int targetHeight) { if (originalWidth == 0 || originalHeight == 0) { return 1; } else {// w w w . j av a2s . c om double ratio = Math.sqrt((targetWidth * targetHeight * 1.0) / (originalWidth * originalHeight)); if (ratio > 1) { return 1; } else { return ratio; } } }
From source file:Main.java
public static double colorDistanceCore(double[] lab1, double[] lab2) { double[] lab = new double[] { lab2[0] - lab1[0], lab2[1] - lab1[1], lab2[2] - lab1[2] }; double C1 = Math.sqrt(lab1[1] * lab1[1] + lab1[2] * lab1[2]); double C2 = Math.sqrt(lab2[1] * lab2[1] + lab2[2] * lab2[2]); double Ci = C2 - C1; double Hi = Math.sqrt(Math.max(lab[1] * lab[1] + lab[2] * lab[2] - Ci * Ci, 0)); double kL = 1, kC = 1, kH = 1, K1 = .045, K2 = .015; double SL = 1, SC = 1 + K1 * C2, SH = 1 + K2 * C2; double dL = lab[0] / (kL * SL), dC = Ci / (kC * SC), dH = Hi / (kH * SH); return Math.sqrt(dL * dL + dC * dC + dH * dH); }
From source file:Main.java
public static double getStrength(String[] word) { double result = 0.0; for (int i = 0; i < word.length; i++) { result = result + (Double.parseDouble(word[i])) * (Double.parseDouble(word[i])); }//from w w w.j a v a 2 s. c om return Math.sqrt(result); }
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;/* www .j a va2 s.c o m*/ 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 calDistance(double latX, double lngX, double latY, double lngY) { double scale = 6400 * 1000 * (Math.PI / 180); double dX = scale * Math.abs((latX - latY)); double dY = scale * Math.abs((lngX - lngY)); return Math.sqrt(dX * dX + dY * dY); }
From source file:Main.java
public static long compute(long timeInNanosecond) { final long start = System.nanoTime(); long seed = start; while (System.nanoTime() - start < timeInNanosecond) { seed = (long) Math.sqrt(3.15); }/*from w ww . j av a2 s. c o m*/ return seed; // try { // TimeUnit.NANOSECONDS.sleep(timeInNanosecond); // } catch (InterruptedException e) { // e.printStackTrace(); // } // return 0; }
From source file:Main.java
public static boolean[] is_prime_up_to_with_sieve(int num) { boolean[] prime = new boolean[num + 1]; Arrays.fill(prime, true);/*from w w w .j a v a2 s . co m*/ prime[0] = false; prime[1] = false; int num_sqrt = (int) Math.ceil(Math.sqrt(num)); for (int i = 2; i <= num_sqrt; i++) { if (prime[i]) for (int j = i * i; j <= num; j += i) prime[j] = false; } return prime; }
From source file:Main.java
public static boolean isTablet(Activity activity) { DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2)); double physicalSize = diagonalPixels / (160 * dm.density); return physicalSize > 7; }
From source file:Main.java
public static float getCurrentScaleFromMatrix(Matrix matrix) { float[] values = new float[9]; matrix.getValues(values);//from ww w . jav a 2 s. c om float scalex = values[Matrix.MSCALE_X]; float skewy = values[Matrix.MSKEW_Y]; return (float) Math.sqrt(scalex * scalex + skewy * skewy); }