Example usage for java.lang Math toRadians

List of usage examples for java.lang Math toRadians

Introduction

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

Prototype

public static double toRadians(double angdeg) 

Source Link

Document

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Usage

From source file:Main.java

public static float cos(double degree) {
    return (float) Math.cos(Math.toRadians(degree));
}

From source file:Main.java

public static float sin(double degree) {
    return (float) Math.sin(Math.toRadians(degree));
}

From source file:Main.java

public static int getStopY(float angle, int distance) {
    return Double.valueOf(Math.rint(-1 * distance * Math.sin(Math.toRadians(angle)))).intValue();
}

From source file:Main.java

private static double lonToX(double lon) {
    return R_MAJOR * Math.toRadians(lon);
}

From source file:Main.java

public static float getRadiusCosineCoefficient(final float valuePositionInDegrees) {
    final double valuePositionInRadians = Math.toRadians((double) valuePositionInDegrees);
    return (float) Math.cos(valuePositionInRadians);
}

From source file:Main.java

public static double getBearing(double lat1, double lng1, double lat2, double lng2) {
    double dLat = Math.toRadians(lat2 - lat1);

    double dLng = Math.toRadians(lng2 - lng1);

    lat1 = Math.toRadians(lat1);/*w w  w  .  jav a 2  s  . co  m*/
    lat2 = Math.toRadians(lat2);

    lng1 = Math.toRadians(lng1);
    lng2 = Math.toRadians(lng2);

    double y = Math.sin(dLng) * Math.cos(lat2);
    double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLng);
    double brng = Math.toDegrees(Math.atan2(y, x));

    return brng;
}

From source file:Main.java

public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
    double earthRadius = 3958.75;
    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 = earthRadius * c;

    int meterConversion = 1609;

    return dist * meterConversion;
}

From source file:Main.java

public static double distance(double lat1, double lng1, double lat2, double lng2) {
    double earthRadius = 6371000; //meters
    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 distance = (double) (earthRadius * c);

    return distance;
}

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);//  ww  w.j  ava2  s. c om
    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 distFrom(double lat1, double lng1, double lat2, double lng2) {
    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double sindLat = Math.sin(dLat / 2);
    double sindLng = Math.sin(dLng / 2);
    double a = Math.pow(sindLat, 2)
            + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    if (dist >= 1000) {
        int distInInt = (int) dist;
        dist = (int) distInInt;
    } else if (dist >= 100) {
        dist = (((int) (dist * 10)) / 10.0);
    } else {/*  ww w  .  jav  a  2  s .  c  o  m*/
        dist = (((int) (dist * 100)) / 100.0);
    }
    return dist;
}