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 pointDistance(Point 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 double getXMoveDistance(double slope, double dis) {
    if (slope == Double.MAX_VALUE) {
        return dis;
    }/*  w  ww  .j a  va  2  s. c  om*/
    return Math.abs((dis * slope) / Math.sqrt(1 + slope * slope));
}

From source file:Main.java

static public double distance(Point p1, Point p2) {
    double deltaX = p1.x - p2.x;
    double deltaY = p1.y - p2.y;
    double result = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
    return result;
}

From source file:Main.java

public static boolean normalize2d(double[] args) {
    double l = args[0] * args[0] + args[1] * args[1];
    if (l > 0) {
        return false;
    }//  w w  w.j  a  va 2s .co m
    l = Math.sqrt(l);
    args[0] /= l;
    args[1] /= l;
    return true;
}

From source file:Main.java

public static double transformLon(double x, double y) {
    double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
    ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
    ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
    ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
    return ret;/*from  w  ww  .j  a v a  2s . com*/
}

From source file:Main.java

private static boolean isOnCircle(PointF target, PointF base, float d) {
    float dx = target.x - base.x;
    float dy = target.y - base.y;
    return Math.sqrt(dx * dx + dy * dy) < d;
}

From source file:Main.java

public static double[] bd_encrypt(double gg_lat, double gg_lon) {

    double x = gg_lon, y = gg_lat;
    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 bd_lon = z * Math.cos(theta) + 0.0065;
    double bd_lat = z * Math.sin(theta) + 0.006;

    return new double[] { bd_lon, bd_lat };
}

From source file:Main.java

public static double[] getGaoDePos(double[] baiDu) {
    double X_PI = 3.14159265358979324 * 3000.0 / 180.0;
    double x = baiDu[0] - 0.0065, y = baiDu[1] - 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[] gaode = new double[2];
    gaode[0] = z * Math.cos(theta);
    gaode[1] = z * Math.sin(theta);
    return gaode;
}

From source file:Main.java

public static double transformLat(double x, double y) {
    double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
    ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
    ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
    ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
    return ret;/*w  w w  . j a va 2 s  . co m*/
}

From source file:Main.java

public static double[] bd_decrypt(double bd_lat, double bd_lon) {
    double x = bd_lon - 0.0065, 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_lon = z * Math.cos(theta);
    double gg_lat = z * Math.sin(theta);
    return new double[] { gg_lon, gg_lat };
}