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

/**
 * From http://stackoverflow.com/a/19498994/423980
 * @return  distance between 2 points, stored as 2 pair location;
 *///from   w w  w. j  a  v a 2s  . co  m
public static double distanceFrom(double lat1, double lng1, double lat2, double lng2) {
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = EARTH_RADIOUS * c;
    return Double.valueOf(dist * METER_CONVERSION).floatValue();
}

From source file:Main.java

public static float getDistanceBetween2Points(PointF p0, PointF p1) {
    float distance = (float) Math.sqrt(Math.pow(p0.y - p1.y, 2) + Math.pow(p0.x - p1.x, 2));
    return distance;
}

From source file:Main.java

public static double getDistance(double x1, double y1, double x2, double y2) {
    double x = x1 - x2;
    double y = y1 - y2;
    return Math.sqrt(x * x + y * y);
}

From source file:Main.java

public static double getDistance(float x1, float y1, float x2, float y2) {
    float xd = x1 - x2;
    float yd = y1 - y2;

    return Math.sqrt(xd * xd + yd * yd);
}

From source file:Main.java

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

From source file:Main.java

public static float distance(float x, float y, float sx, float sy) {
    float dx = x - sx;
    float dy = y - sy;
    return (float) Math.sqrt(dx * dx + dy * dy);
}

From source file:Main.java

public static void barrelDistortion(double paramA, double paramB, double paramC, PointF src) {

    double paramD = 1.0 - paramA - paramB - paramC; // describes the linear scaling of the image

    float d = 1.0f;

    // center of dst image
    double centerX = 0f;
    double centerY = 0f;

    if (src.x == centerX && src.y == centerY) {
        return;/*from www  . java 2 s.com*/
    }

    // cartesian coordinates of the destination point (relative to the centre of the image)
    double deltaX = (src.x - centerX) / d;
    double deltaY = (src.y - centerY) / d;

    // distance or radius of dst image
    double dstR = Math.sqrt(deltaX * deltaX + deltaY * deltaY);

    // distance or radius of src image (with formula)
    double srcR = (paramA * dstR * dstR * dstR + paramB * dstR * dstR + paramC * dstR + paramD) * dstR;

    // comparing old and new distance to get factor
    double factor = Math.abs(dstR / srcR);

    // coordinates in source image
    float xResult = (float) (centerX + (deltaX * factor * d));
    float yResult = (float) (centerY + (deltaY * factor * d));

    src.set(xResult, yResult);
}

From source file:Main.java

public static double[] gcj02tobd09(double lng, double lat) {
    double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_pi);
    double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_pi);
    double bd_lng = z * Math.cos(theta) + 0.0065;
    double bd_lat = z * Math.sin(theta) + 0.006;
    return new double[] { bd_lng, bd_lat };
}

From source file:Main.java

/**
 * Returns the euclidean distance between two LAB colors.
 *//*w  w  w. j a va 2  s.c om*/
public static double distanceEuclidean(double[] labX, double[] labY) {
    return Math.sqrt(
            Math.pow(labX[0] - labY[0], 2) + Math.pow(labX[1] - labY[1], 2) + Math.pow(labX[2] - labY[2], 2));
}

From source file:Main.java

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