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:Main.java

public static double norm(Vector<Double> l1, Vector<Double> l2) {
    assert (l1.size() == l2.size());

    double ans = 0.;
    for (int i = 0; i < l1.size(); ++i)
        ans += (l1.elementAt(i) - l2.elementAt(i)) * (l1.elementAt(i) - l2.elementAt(i));
    ans = Math.sqrt(ans);

    return ans;/*from  ww w.  j a v  a2 s .  c o  m*/
}

From source file:Main.java

public static double pointDistance(PointF a, Point b) {
    return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap source, int targetSize) {
    int sourceW = source.getWidth();
    int sourceH = source.getHeight();

    float scaleFactor = (float) Math.sqrt(source.getByteCount() / targetSize);

    int dstWidth = (int) (sourceW / scaleFactor);
    int dstHeight = (int) (sourceH / scaleFactor);

    Bitmap scaledBitmap = createScaledBitmap(source, dstWidth, dstHeight, true);
    return scaledBitmap;
}

From source file:Main.java

public static int[] getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) {
    final int[] out = new int[2];

    final double E2 = (double) aLat * Math.PI / 180;
    final long sradiusa = 6378137;
    final long sradiusb = 6356752;
    final double J2 = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa;
    final double M2 = (double) Math.log((1 + Math.sin(E2)) / (1 - Math.sin(E2))) / 2
            - J2 * Math.log((1 + J2 * Math.sin(E2)) / (1 - J2 * Math.sin(E2))) / 2;
    final double B2 = (double) (1 << zoom);
    out[0] = (int) Math.floor(B2 / 2 - M2 * B2 / 2 / Math.PI);

    out[1] = (int) Math.floor((aLon + 180) / 360 * (1 << zoom));

    return out;//from  w  w w .j  a  v a  2s. c  om
}

From source file:Main.java

private static final double colorDistance(int color1, int color2) {
    int redDistance = Color.red(color1) - Color.red(color2);
    int greenDistance = Color.green(color1) - Color.green(color2);
    int blueDistance = Color.blue(color1) - Color.blue(color2);
    double distance = Math
            .sqrt(redDistance * redDistance + greenDistance * greenDistance + blueDistance * blueDistance);
    return distance / 256.;
}

From source file:Main.java

public static boolean isColourLight(int colour) {
    if (colour == 0) {
        return false;
    }/*from w  w w  . ja v a  2s.  co  m*/

    int red = Color.red(colour);
    int blue = Color.blue(colour);
    int green = Color.green(colour);

    return (int) Math.sqrt(red * red * .241 + green * green * .691 + blue * blue * .068) > 130;
}

From source file:Main.java

public static double getDistance(double lat1, double lng1, double lat2, double lng2) {
    double radLat1 = rad(lat1);
    double radLat2 = rad(lat2);
    double a = radLat1 - radLat2;
    double b = rad(lng1) - rad(lng2);
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin((double) a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;/*from w w  w .j  av a  2  s. c o m*/
    return s;
}

From source file:Main.java

public static double GetDistance(double lat1, double lng1, double lat2, double lng2) {
    double radLat1 = rad(lat1);
    double radLat2 = rad(lat2);
    double a = radLat1 - radLat2;
    double b = rad(lng1) - rad(lng2);

    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)));
    s = s * EARTH_RADIUS;/*w  w w . j  a v a  2s.  c om*/
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static double DistanceOfTwoPoints(double lat1, double lng1, double lat2, double lng2) {
    double radLat1 = rad(lat1);
    double radLat2 = rad(lat2);
    double a = radLat1 - radLat2;
    double b = rad(lng1) - rad(lng2);
    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)));
    s = s * EARTH_RADIUS;/* w  w  w. j  a v a2s .  c  o m*/
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

/**************************************
 * Math relevant/*from   w w  w  . j  a  va 2 s  .co 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;
}