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:webservice.GPSDistance.java

public static double distFrom(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));
    float dist = (float) (earthRadius * c);

    return dist;//w  ww . ja  va2s.  c  o m
}

From source file:Data.Utilities.java

public static Double haversine(double lat1, double lon1, double lat2, double lon2) {
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    lat1 = Math.toRadians(lat1);/*from   w w w . j av  a  2 s.  c  o  m*/
    lat2 = Math.toRadians(lat2);

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

From source file:Main.java

static public long getHeadWindComponent(double windSpeed, double windDir, double d) {
    return Math.round(windSpeed * Math.cos(Math.toRadians(windDir - d)));
}

From source file:Main.java

static public long getCrossWindComponent(double windSpeed, double windDir, double d) {
    return Math.round(windSpeed * Math.sin(Math.toRadians(windDir - d)));
}

From source file:Main.java

public static Bitmap rotateAndFrame(Bitmap bitmap) {
    final boolean positive = sRandom.nextFloat() >= 0.5f;
    final float angle = (ROTATION_ANGLE_MIN + sRandom.nextFloat() * ROTATION_ANGLE_EXTRA)
            * (positive ? 1.0f : -1.0f);
    final double radAngle = Math.toRadians(angle);

    final int bitmapWidth = bitmap.getWidth();
    final int bitmapHeight = bitmap.getHeight();

    final double cosAngle = Math.abs(Math.cos(radAngle));
    final double sinAngle = Math.abs(Math.sin(radAngle));

    final int strokedWidth = (int) (bitmapWidth + 2 * PHOTO_BORDER_WIDTH);
    final int strokedHeight = (int) (bitmapHeight + 2 * PHOTO_BORDER_WIDTH);

    final int width = (int) (strokedHeight * sinAngle + strokedWidth * cosAngle);
    final int height = (int) (strokedWidth * sinAngle + strokedHeight * cosAngle);

    final float x = (width - bitmapWidth) / 2.0f;
    final float y = (height - bitmapHeight) / 2.0f;

    final Bitmap decored = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(decored);

    canvas.rotate(angle, width / 2.0f, height / 2.0f);
    canvas.drawBitmap(bitmap, x, y, sPaint);
    canvas.drawRect(x, y, x + bitmapWidth, y + bitmapHeight, sStrokePaint);

    return decored;
}

From source file:Main.java

/**
 * Calculate the difference between true solar time and mean. The "equation
 * of time" is a term accounting for changes in the time of solar noon for
 * a given location over the course of a year. Earth's elliptical orbit and
 * Kepler's law of equal areas in equal times are the culprits behind this
 * phenomenon. See the//from  ww  w .j  a v  a 2 s  .com
 * <A HREF="http://www.analemma.com/Pages/framesPage.html">Analemma page</A>.
 * Below is a plot of the equation of time versus the day of the year.
 *
 * <P align="center"><img src="doc-files/EquationOfTime.png"></P>
 *
 * @param  t number of Julian centuries since J2000.
 * @return Equation of time in minutes of time.
 */
private static double equationOfTime(final double t) {
    double eps = Math.toRadians(obliquityCorrected(t));
    double l0 = Math.toRadians(sunGeometricMeanLongitude(t));
    double m = Math.toRadians(sunGeometricMeanAnomaly(t));
    double e = eccentricityEarthOrbit(t);
    double y = Math.tan(eps / 2);
    y *= y;

    double sin2l0 = Math.sin(2 * l0);
    double cos2l0 = Math.cos(2 * l0);
    double sin4l0 = Math.sin(4 * l0);
    double sin1m = Math.sin(m);
    double sin2m = Math.sin(2 * m);

    double etime = y * sin2l0 - 2 * e * sin1m + 4 * e * y * sin1m * cos2l0 - 0.5 * y * y * sin4l0
            - 1.25 * e * e * sin2m;

    return Math.toDegrees(etime) * 4.0;
}

From source file:RingShell.java

static int[] createCircle(int radius, int centerX, int centerY) {
    int[] points = new int[360 * 2];
    for (int i = 0; i < 360; i++) {
        points[i * 2] = centerX + (int) (radius * Math.cos(Math.toRadians(i)));
        points[i * 2 + 1] = centerY + (int) (radius * Math.sin(Math.toRadians(i)));
    }/*from  w w w .ja  v  a2s. c o  m*/
    return points;
}

From source file:Main.java

/**
 * Returns the correction factor for the solar irradiance due to the elliptical
 * orbit of the Sun.//from w ww  . j ava 2 s .  c o  m
 *
 * @param day the day (of year) of interest.
 *
 * @return the correction factor.
 */
public static double getSolarIrradianceCorrectionFactor(int day) {
    final double d = 1.0 - 0.01673 * Math.cos(Math.toRadians(0.9856 * (day - 4)));

    return 1.0 / (d * d);
}

From source file:Main.java

/**
 * Computes the bearing in radians between two points on Earth.
 *
 * @param lat1 Latitude of the first point
 * @param lon1 Longitude of the first point
 * @param lat2 Latitude of the second point
 * @param lon2 Longitude of the second point
 * @return Bearing between the two points in radians. A value of 0 means due
 *         north./*  w  w  w  . j a v  a  2s. c  o  m*/
 */
public static double bearingRad(double lat1, double lon1, double lat2, double lon2) {
    double lat1Rad = Math.toRadians(lat1);
    double lat2Rad = Math.toRadians(lat2);
    double deltaLonRad = Math.toRadians(lon2 - lon1);

    double y = Math.sin(deltaLonRad) * Math.cos(lat2Rad);
    double x = Math.cos(lat1Rad) * Math.sin(lat2Rad)
            - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad);
    return Math.atan2(y, x);
}

From source file:Main.java

/**
 * Waypoint projection using haversine formula
 * http://en.wikipedia.org/wiki/Haversine_formula See discussion here for
 * further information: http://www.movable-type.co.uk/scripts/latlong.html
 *//*  w  w  w  . ja v  a2  s .co m*/
public static double[] project(double distance, double bearing, double startLat, double startLon) {

    double distanceRad = distance / EARTH_RADIUS_KM;
    double bearingRad = Math.toRadians(bearing);
    double startLatRad = Math.toRadians(startLat);
    double startLonRad = Math.toRadians(startLon);

    double endLat = Math.asin(Math.sin(startLatRad) * Math.cos(distanceRad)
            + Math.cos(startLatRad) * Math.sin(distanceRad) * Math.cos(bearingRad));

    double endLon = startLonRad
            + Math.atan2(Math.sin(bearingRad) * Math.sin(distanceRad) * Math.cos(startLatRad),
                    Math.cos(distanceRad) - Math.sin(startLatRad) * Math.sin(endLat));

    // Adjust projections crossing the 180th meridian:
    double endLonDeg = Math.toDegrees(endLon);

    if (endLonDeg > 180 || endLonDeg < -180) {
        endLonDeg = endLonDeg % 360; // Just in case we circle the earth
                                     // more than once.
        if (endLonDeg > 180) {
            endLonDeg = endLonDeg - 360;
        } else if (endLonDeg < -180) {
            endLonDeg = endLonDeg + 360;
        }
    }

    double[] endCoords = new double[] { Math.toDegrees(endLat), endLonDeg };

    return endCoords;

}