List of usage examples for java.lang Math sqrt
@HotSpotIntrinsicCandidate public static double sqrt(double a)
From source file:Main.java
public static float distance(PointF p1, PointF p2) { float x = p1.x - p2.x; float y = p1.y - p2.y; return (float) Math.sqrt(x * x + y * y); }
From source file:Main.java
/** * Get the brightness of a given color/*from ww w. jav a 2 s. co m*/ * * @param color The color * @return The brightness value */ public static int getBrightness(int color) { int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); return (int) Math.sqrt(r * r * .241 + g * g * .691 + b * b * .068); }
From source file:Main.java
/** * Determine if the device is a 7 tablet * // ww w. j av a 2 s. co m * @param context * @return true if it is >= 6.5 and < 7.6 */ public static boolean is7InchTablet(Context context) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); float widthInInches = metrics.widthPixels / metrics.xdpi; float heightInInches = metrics.heightPixels / metrics.ydpi; double sizeInInches = Math.sqrt(Math.pow(widthInInches, 2) + Math.pow(heightInInches, 2)); return sizeInInches >= 6.5 && sizeInInches < 7.6; }
From source file:Main.java
public static double stdarr(int[] a, double avg) // std given the average { double res = 0.0; for (int i = 0; i < a.length; i++) res += (a[i] - avg) * (a[i] - avg); return (Math.sqrt(res / (a.length - 1))); }
From source file:Main.java
public static float norm2(float[] vec) { float sum = 0; for (float f : vec) { sum += Math.pow(f, 2);/*from w w w . ja v a 2 s . co m*/ } return (float) Math.sqrt(sum); }
From source file:Main.java
public static float distance(float x1, float y1, float x2, float y2) { float d1 = x1 - x2; float d2 = y1 - y2; return (float) Math.sqrt((float) Math.pow(d1, 2) + Math.pow(d2, 2)); }
From source file:Main.java
/** * Finds out if a number is a prime number or not. * //w w w. ja va 2s .com * @param number * The possible prime number * @return If it is a prime number or not */ public static boolean isPrime(int number) { if (number < 2) { return false; } if (number == 2) { return true; } if (number % 2 == 0) { return false; } int root = (int) Math.sqrt((double) number); for (int j = 2; j <= root; j++) { if (number % j == 0) { return false; } } return true; }
From source file:com.anhth12.lambda.common.math.VectorMath.java
public static double norm(float[] x) { double total = 0.0; for (float f : x) { double d = (double) f; total += d * d;/*from ww w .j a v a2s .co m*/ } return Math.sqrt(total); }
From source file:Main.java
/** * Get the distance between two points./* w w w . j a va 2 s .c o m*/ */ public static int getDistance(float x1, float y1, float x2, float y2) { return (int) Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); }
From source file:edu.csun.ecs.cs.multitouchj.ui.utility.PointUtility.java
public static float getDistance(Point pointA, Point pointB) { return (float) Math .sqrt(Math.pow((pointB.getX() - pointA.getX()), 2) + Math.pow((pointB.getY() - pointA.getY()), 2)); }