Example usage for java.lang Math asin

List of usage examples for java.lang Math asin

Introduction

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

Prototype

public static double asin(double a) 

Source Link

Document

Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.

Usage

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;/*  w  w  w  .  j  ava 2  s  .  co  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;//from  w w w  .  ja  v a  2s . c o m
    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;//from  w w  w.jav  a 2 s  .  co  m
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {

    double Lat1 = rad(latitude1);
    double Lat2 = rad(latitude2);
    double a = Lat1 - Lat2;
    double b = rad(longitude1) - rad(longitude2);
    double s = 2 * Math.asin(Math.sqrt(
            Math.pow(Math.sin(a / 2), 2) + Math.cos(Lat1) * Math.cos(Lat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;/*from  w w  w .  j a va 2s.  c o m*/
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static double[] Rec2Sph(double x, double y, double z) {
    double[] sph = new double[3];
    sph[0] = Math.sqrt(x * x + y * y + z * z);
    sph[1] = x == 0 ? 0 : Math.atan(Math.abs(y / x));
    if (x < 0)
        sph[1] = Math.PI - sph[1];
    if (y < 0)
        sph[1] *= -1;//from   w w w .  ja v  a 2s.  c  o m
    sph[2] = Math.asin(z / sph[0]);
    return sph;
}

From source file:Main.java

public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
    double radLat1 = (lat_a * Math.PI / 180.0);
    double radLat2 = (lat_b * Math.PI / 180.0);
    double a = radLat1 - radLat2;
    double b = (lng_a - lng_b) * Math.PI / 180.0;
    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;//from   w  w  w  .j a  va2s.c  om
    s = Math.round(s * 10000) / 10000;
    return s;
}

From source file:Main.java

public static double distanceTo(double fromLat, double fromLng, double toLat, double toLng) {

    double fromLatRad = calculateRadian(fromLat);
    double fromLngRad = calculateRadian(fromLng);
    double toLatRad = calculateRadian(toLat);
    double toLngRad = calculateRadian(toLng);

    return EARTH_RADIUS * (Math.PI / 2 - Math.asin(Math.sin(fromLatRad) * Math.sin(toLatRad)
            + Math.cos(fromLngRad - toLngRad) * Math.cos(toLatRad) * Math.cos(fromLatRad)));
}

From source file:Main.java

public static double haversine(double lat1, double lon1, double lat2, double lon2) {
    final double R = 6372.8; // In kilometers

    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    lat1 = Math.toRadians(lat1);// w ww .j  ava 2  s .c  o  m
    lat2 = Math.toRadians(lat2);

    double a = Math.pow(Math.sin(dLat / 2), 2)
            + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
}

From source file:Main.java

public static double gps2km(final double lat_a, final double lng_a, final double lat_b, final double lng_b) {
    if (!isGpsValid(lng_a, lat_a) || !isGpsValid(lng_b, lat_b)) {
        return -1;
    }//  www .j  a va2  s .c o  m
    final double radLat1 = (lat_a * Math.PI / 180.0);
    final double radLat2 = (lat_b * Math.PI / 180.0);
    final double a = radLat1 - radLat2;
    final double b = (lng_a - lng_b) * Math.PI / 180.0;
    final 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)));
    return s * EARTH_RADIUS;
}

From source file:Main.java

public static double tile2lat(int y, int aZoom) {

    final double MerkElipsK = 0.0000001;
    final long sradiusa = 6378137;
    final long sradiusb = 6356752;
    final double FExct = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa;
    final int TilesAtZoom = 1 << aZoom;
    double result = (y - TilesAtZoom / 2) / -(TilesAtZoom / (2 * Math.PI));
    result = (2 * Math.atan(Math.exp(result)) - Math.PI / 2) * 180 / Math.PI;
    double Zu = result / (180 / Math.PI);
    double yy = ((y) - TilesAtZoom / 2);

    double Zum1 = Zu;
    Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct))
            / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI)))
                    * Math.pow(1 + FExct * Math.sin(Zum1), FExct)));
    while (Math.abs(Zum1 - Zu) >= MerkElipsK) {
        Zum1 = Zu;/*from  w w w. j  av a2 s .  c  o  m*/
        Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct))
                / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI)))
                        * Math.pow(1 + FExct * Math.sin(Zum1), FExct)));
    }

    result = Zu * 180 / Math.PI;

    return result;

}