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

private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength,
        int maxNumOfPixels) {
    double w = options.outWidth;
    double h = options.outHeight;

    int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels));
    int upperBound = (minSideLength == -1) ? 1280
            : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength));

    if (upperBound < lowerBound) {
        // return the larger one when there is no overlapping zone.
        return lowerBound;
    }//  w  w w . ja v a 2 s.com

    if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
        return 1;
    } else if (minSideLength == -1) {
        return lowerBound;
    } else {
        return upperBound;
    }
}

From source file:Main.java

public static double[] bd09togcj02(double bd_lon, double bd_lat) {
    double x = bd_lon - 0.0065;
    double y = bd_lat - 0.006;
    double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
    double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
    double gg_lng = z * Math.cos(theta);
    double gg_lat = z * Math.sin(theta);
    return new double[] { gg_lng, gg_lat };
}

From source file:Main.java

public static float distance(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return (float) Math.sqrt(x * x + y * y);
}

From source file:lsafunctions.LSA.java

public static double cosinSim(int v1, int v2, RealMatrix Vt) {
    double sim = 0.0;
    double sumNum = 0.0;
    double fdenom = 0.0;
    double sdenom = 0.0;

    for (int j = 0; j < Vt.getRowDimension(); j++) {
        sumNum += Vt.getEntry(j, v1) * Vt.getEntry(j, v2);
        fdenom += Math.pow(Vt.getEntry(j, v1), 2);
        sdenom += Math.pow(Vt.getEntry(j, v2), 2);
    }//from  ww  w .  ja v a 2  s . com
    sim = sumNum / (Math.sqrt(fdenom) * Math.sqrt(sdenom));

    return sim;
}

From source file:Main.java

private static int computeInitialSampleSize(Options options, int minSideLength, int maxNumOfPixels) {
    double w = options.outWidth;
    double h = options.outHeight;

    int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels));
    int upperBound = (minSideLength == -1) ? 128
            : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength));

    if (upperBound < lowerBound) {
        // return the larger one when there is no overlapping zone.
        return lowerBound;
    }//from w  w  w. j  av a  2s.com

    if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
        return 1;
    } else if (minSideLength == -1) {
        return lowerBound;
    } else {
        return upperBound;
    }
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static float distance(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    Math.sqrt(x * x + y * y);
    return (float) Math.sqrt(x * x + y * y);
}

From source file:Main.java

static public final float mag(float a, float b, float c) {
    return (float) Math.sqrt(a * a + b * b + c * c);
}

From source file:Main.java

/**
 * Get the distance between two points./*from w  w  w . j ava2  s . c o  m*/
 *
 * @param A Point A
 * @param B Point B
 * @return the distance between point A and point B.
 */
public static int getDistance(PointF A, PointF B) {
    return (int) Math.sqrt(Math.pow(A.x - B.x, 2) + Math.pow(A.y - B.y, 2));
}

From source file:Main.java

public static double fastDistanceMeters(double latRad1, double lngRad1, double latRad2, double lngRad2) {
    if ((Math.abs(latRad1 - latRad2) > RAD_PER_DEG) || (Math.abs(lngRad1 - lngRad2) > RAD_PER_DEG)) {
        return accurateDistanceMeters(latRad1, lngRad1, latRad2, lngRad2);
    }/*from www  . java 2  s  .  co m*/
    // Approximate sin(x) = x.
    double sineLat = (latRad1 - latRad2);

    // Approximate sin(x) = x.
    double sineLng = (lngRad1 - lngRad2);

    // Approximate cos(lat1) * cos(lat2) using
    // cos((lat1 + lat2)/2) ^ 2
    double cosTerms = Math.cos((latRad1 + latRad2) / 2.0);
    cosTerms = cosTerms * cosTerms;
    double trigTerm = sineLat * sineLat + cosTerms * sineLng * sineLng;
    trigTerm = Math.sqrt(trigTerm);

    // Approximate arcsin(x) = x
    return EARTH_RADIUS_METERS * trigTerm;
}

From source file:Main.java

public static float distance(int aX, int aY, int bX, int bY) {
    int xDiff = aX - bX;
    int yDiff = aY - bY;
    return (float) Math.sqrt(xDiff * xDiff + yDiff * yDiff);
}