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

/**
 * Same as toX, but converts to Y component, assuming positive Y is down.
 * //from  w  ww .j  a  v  a  2 s .  co m
 * @param angle
 * @return
 */
public static double toY(int angle) {
    return Math.sin(Math.toRadians(angle - 90));
}

From source file:Main.java

public static Double getDistance(double lat1, double lat2, double lon1, double lon2, double el1, double el2) {

    final int R = 6371; // Radius of the earth

    Double latDistance = Math.toRadians(lat2 - lat1);
    Double lonDistance = Math.toRadians(lon2 - lon1);
    Double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
    Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double distance = R * c; // convert to meters

    double height = el1 - el2;

    distance = Math.pow(distance, 2) + Math.pow(height, 2);

    return Math.sqrt(distance);
}

From source file:Main.java

public static double distanceFrom(double lat1, double lng1, double lat2, double lng2) {
    // Implementation of the Haversine distance formula
    lat1 = Math.toRadians(lat1);
    lng1 = Math.toRadians(lng1);/*from   w w w .  ja  v a2 s  .com*/
    lat2 = Math.toRadians(lat2);
    lng2 = Math.toRadians(lng2);

    double dlon = lng2 - lng1;
    double dlat = lat2 - lat1;

    double a = Math.pow((Math.sin(dlat / 2)), 2)
            + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return 3958.75 * c; // 3958: Earth radius in miles
}

From source file:Main.java

/**
 * Calculates the distance between two locations in KM
 *//* w w w  .  ja  va 2 s.c om*/
public static double checkDistance(double lat1, double lng1, double lat2, double lng2) {
    double earthRadius = 6371;

    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 * 1000;

    return dist; // in meter
}

From source file:Main.java

/**
 * Calculate the azimuth to the target location from local.
 *//* ww w  .  ja  v  a  2s  .c  o m*/
private static int getPosDirection(final double startlat, final double startlong, final double endlat,
        final double endlon) {
    double slat = Math.toRadians(startlat);
    double elat = Math.toRadians(endlat);
    double slng = Math.toRadians(startlong);
    double elng = Math.toRadians(endlon);
    double Y = Math.sin(elng - slng) * Math.cos(elat);
    double X = Math.cos(slat) * Math.sin(elat) - Math.sin(slat) * Math.cos(elat) * Math.cos(elng - slng);
    double deg = Math.toDegrees(Math.atan2(Y, X));
    double angle = (deg + 360) % 360;
    return (int) (Math.abs(angle) + (1 / 7200));
}

From source file:Main.java

public static float getAngleDifference(float ang1, float ang2) {
    float a = (float) Math.toDegrees(ang1) - (float) Math.toDegrees(ang2);
    a += (a > 180) ? -360 : (a < -180) ? 360 : 0;
    return (float) Math.toRadians(a);
}

From source file:Main.java

public static PointF rotatePoint(PointF point, PointF centerPoint, float rotate) {
    float x = point.x;
    float y = point.y;
    float sinA = (float) Math.sin(Math.toRadians(rotate));
    float cosA = (float) Math.cos(Math.toRadians(rotate));
    float newX = centerPoint.x + (x - centerPoint.x) * cosA - (y - centerPoint.y) * sinA;
    float newY = centerPoint.y + (y - centerPoint.y) * cosA + (x - centerPoint.x) * sinA;
    return new PointF(newX, newY);
}

From source file:Main.java

private static double getRadiansByHHMMSS(double hours, double minutes, double seconds) {
    double degreeHours = hours * 15.0;
    double degreesMin = (minutes / 60.0) * 15.0;
    double degreesSec = (seconds / 3600.0) * 15.0;
    double degrees = degreeHours + degreesMin + degreesSec;
    return Math.toRadians(degrees);
}

From source file:Main.java

/**
 * Calculate the apparent longitude of the sun.
 *
 * @param  t number of Julian centuries since J2000.
 * @return Sun's apparent longitude in degrees.
 */// www  .  j a  va2  s. c om
private static double sunApparentLongitude(final double t) {
    final double omega = Math.toRadians(125.04 - 1934.136 * t);
    return sunTrueLongitude(t) - 0.00569 - 0.00478 * Math.sin(omega);
}

From source file:Main.java

/**
 * Calculate the equation of center for the sun. This value is a correction
 * to add to the geometric mean longitude in order to get the "true" longitude
 * of the sun./*  w  w  w .j ava2s . com*/
 *
 * @param  t number of Julian centuries since J2000.
 * @return Equation of center in degrees.
 */
private static double sunEquationOfCenter(final double t) {
    final double m = Math.toRadians(sunGeometricMeanAnomaly(t));
    return Math.sin(1 * m) * (1.914602 - t * (0.004817 + 0.000014 * t))
            + Math.sin(2 * m) * (0.019993 - t * (0.000101)) + Math.sin(3 * m) * (0.000289);
}