Example usage for java.lang Math sqrt

List of usage examples for java.lang Math sqrt

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double sqrt(double a) 

Source Link

Document

Returns the correctly rounded positive square root of a double value.

Usage

From source file:Maths.java

/** sqrt(a^2 + b^2) without under/overflow. **/

public static double hypot(double a, double b) {
    double r;/*from  w  w  w . j  a  v  a2s . co  m*/
    if (Math.abs(a) > Math.abs(b)) {
        r = b / a;
        r = Math.abs(a) * Math.sqrt(1 + r * r);
    } else if (b != 0) {
        r = a / b;
        r = Math.abs(b) * Math.sqrt(1 + r * r);
    } else {
        r = 0.0;
    }
    return r;
}

From source file:Main.java

public static double GX(int x, int y, Bitmap bitmap) {
    double res = (-1) * getPixel(x - 1, y - 1, bitmap) + 1 * getPixel(x + 1, y - 1, bitmap)
            + (-Math.sqrt(2)) * getPixel(x - 1, y, bitmap) + Math.sqrt(2) * getPixel(x + 1, y, bitmap)
            + (-1) * getPixel(x - 1, y + 1, bitmap) + 1 * getPixel(x + 1, y + 1, bitmap);
    return res;//from  www .j  a va 2 s.  com
}

From source file:Main.java

/**
 * @param x1//  w  w w .  j av  a 2  s.c  o m
 * @param y1
 * @param x2
 * @param y2
 * @return
 */
public final static double calDistance(double x1, double y1, double x2, double y2) {
    double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    return distance;
}

From source file:Main.java

public static double getDistance(Point p1, Point p2) {
    double x = p1.getX() - p2.getX();
    double y = p1.getY() - p2.getY();
    return Math.sqrt(x * x + y * y);
}

From source file:Main.java

public static double getPhysicalSize(Activity context) {
    DisplayMetrics dm = getScreenSize(context);
    double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2));
    return diagonalPixels / (160 * dm.density);
}

From source file:Main.java

/**
 * Returns the square root of the sum of squares of its arguments, see {@link Math#hypot(double, double)}
 *///from w w w.j  av  a 2 s.  c o m
public static float hypo(int a, int b) {
    return (float) Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
}

From source file:Main.java

private static Double calculateMagnitude(Map<Object, Integer> map1) {
    Double sum = 0.0;/*from w  w w  .  j  a  v  a 2s . c o m*/
    for (Integer value : map1.values()) {
        sum += Math.pow(value, 2);
    }

    return Math.sqrt(sum);
}

From source file:Main.java

public static double getPPI(int w_pixels, int h_pixels, float diagonal_size) {
    if (w_pixels <= 0 || h_pixels <= 0 || diagonal_size <= 0) {
        return -1.0;
    }/*from  ww w . j a  va2s  . c  o  m*/
    return Math.sqrt(w_pixels * w_pixels + h_pixels * h_pixels) / diagonal_size;
}

From source file:Main.java

public static void normalize(float[] vector) {
    double sum = 0.0;
    for (float x : vector) {
        sum += x * x;/*from www . j av a2 s .c  o m*/
    }
    if (sum == 0) {
        return;
    }
    sum = Math.sqrt(sum);
    for (int i = 0; i < vector.length; i++) {
        vector[i] /= sum;
    }
}

From source file:Main.java

private static void calculateInSampleSize(long requestPixels, BitmapFactory.Options options) {
    long picSize = options.outHeight * options.outWidth;
    int inSampleSize = (int) Math.sqrt(picSize / requestPixels);
    if (inSampleSize <= 1) {
        inSampleSize = 1;/*  w w  w  .j a v a 2s  .c  om*/
    }
    options.inSampleSize = inSampleSize;
}