Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine of an angle.

Usage

From source file:Main.java

public static float[] getRotationFromGyro(float[] values, float timestamp, float nowTimeStamp,
        float[] currentRotMatrix, boolean swapX, boolean swapY, boolean swapZ) {
    float[] deltaRotationVector = new float[4];
    if (timestamp != 0) {
        final float dT = (nowTimeStamp - timestamp) * NS2S;
        float axisX = swapX ? -values[0] : values[0];
        float axisY = swapY ? -values[1] : values[1];
        float axisZ = swapZ ? -values[2] : values[2];

        float omegaMagnitude = (float) Math.sqrt(axisX * axisX + axisY * axisY + axisZ * axisZ);
        if (omegaMagnitude > 0.1f) {
            axisX /= omegaMagnitude;/* w w  w .j  ava 2 s  . c o m*/
            axisY /= omegaMagnitude;
            axisZ /= omegaMagnitude;
        }

        float thetaOverTwo = omegaMagnitude * dT / 2.0f;
        float sinThetaOverTwo = (float) Math.sin(thetaOverTwo);
        float cosThetaOverTwo = (float) Math.cos(thetaOverTwo);
        deltaRotationVector[0] = sinThetaOverTwo * axisX;
        deltaRotationVector[1] = sinThetaOverTwo * axisY;
        deltaRotationVector[2] = sinThetaOverTwo * axisZ;
        deltaRotationVector[3] = cosThetaOverTwo;
    }
    float[] deltaRotationMatrix = new float[16];
    SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector);
    return naivMatrixMultiply(currentRotMatrix, deltaRotationMatrix);
}

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 . ja  v  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

public static void transform(double wgLat, double wgLon, double[] latlng) {
    if (outOfChina(wgLat, wgLon)) {
        latlng[0] = wgLat;/*w  ww . j  a  va2s  .  c o m*/
        latlng[1] = wgLon;
        return;
    }
    double dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
    double dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
    double radLat = wgLat / 180.0 * pi;
    double magic = Math.sin(radLat);
    magic = 1 - ee * magic * magic;
    double sqrtMagic = Math.sqrt(magic);
    dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
    dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
    latlng[0] = wgLat + dLat;
    latlng[1] = wgLon + dLon;
}

From source file:Main.java

/**
 * Converts to Cartesian points//from w  w w.  j av a 2s  .  c  o  m
 * 
 * @param lat latitude
 * @param lon longitude
 * 
 * @return point in x,y,z
 */
private static double[] latlon2cartesian(double lat, double lon) {
    return new double[] { Math.cos(lon) * Math.cos(lat) * EARTH_RADIUS,
            Math.sin(lon) * Math.cos(lat) * EARTH_RADIUS, Math.sin(lat) * EARTH_RADIUS };
}

From source file:Main.java

static double arcInRadians(Location A, Location B) {
    double latitudeArc = (A.getLatitude() - B.getLatitude()) * DEG_TO_RAD;
    double longitudeArc = (A.getLongitude() - B.getLongitude()) * DEG_TO_RAD;
    double latitudeH = Math.sin(latitudeArc * 0.5);
    latitudeH *= latitudeH;// w w w . j  a  v  a 2s.  c om
    double lontitudeH = Math.sin(longitudeArc * 0.5);
    lontitudeH *= lontitudeH;
    double tmp = Math.cos(A.getLatitude() * DEG_TO_RAD) * Math.cos(B.getLatitude() * DEG_TO_RAD);
    return 2.0 * Math.asin(Math.sqrt(latitudeH + tmp * lontitudeH));
}

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/*ww  w .ja  v  a2  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: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.//from w ww  .  j  a  v  a  2 s . c  om
 */
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

/**
 * Special crop of bitmap rotated by not stright angle, in this case the original crop bitmap contains parts
 * beyond the required crop area, this method crops the already cropped and rotated bitmap to the final
 * rectangle.<br>/*from w w w  .j a va  2s . c o m*/
 * Note: rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping.
 */
private static Bitmap cropForRotatedImage(Bitmap bitmap, float[] points, Rect rect, int degreesRotated,
        boolean fixAspectRatio, int aspectRatioX, int aspectRatioY) {
    if (degreesRotated % 90 != 0) {

        int adjLeft = 0, adjTop = 0, width = 0, height = 0;
        double rads = Math.toRadians(degreesRotated);
        int compareTo = degreesRotated < 90 || (degreesRotated > 180 && degreesRotated < 270) ? rect.left
                : rect.right;
        for (int i = 0; i < points.length; i += 2) {
            if (points[i] >= compareTo - 1 && points[i] <= compareTo + 1) {
                adjLeft = (int) Math.abs(Math.sin(rads) * (rect.bottom - points[i + 1]));
                adjTop = (int) Math.abs(Math.cos(rads) * (points[i + 1] - rect.top));
                width = (int) Math.abs((points[i + 1] - rect.top) / Math.sin(rads));
                height = (int) Math.abs((rect.bottom - points[i + 1]) / Math.cos(rads));
                break;
            }
        }

        rect.set(adjLeft, adjTop, adjLeft + width, adjTop + height);
        if (fixAspectRatio) {
            fixRectForAspectRatio(rect, aspectRatioX, aspectRatioY);
        }

        Bitmap bitmapTmp = bitmap;
        bitmap = Bitmap.createBitmap(bitmap, rect.left, rect.top, rect.width(), rect.height());
        if (bitmapTmp != bitmap) {
            bitmapTmp.recycle();
        }
    }
    return bitmap;
}

From source file:Main.java

/**
 * Computes the bearing in degrees between two points on Earth.
 * /*from ww  w. j  av a 2  s.  co m*/
 * @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 degrees. A value of 0 means due
 *         north.
 */
public static double bearing(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 radToBearing(Math.atan2(y, x));
}

From source file:Main.java

public static double accurateDistanceMeters(double lat1, double lng1, double lat2, double lng2) {
    double dlat = Math.sin(0.5 * (lat2 - lat1));
    double dlng = Math.sin(0.5 * (lng2 - lng1));
    double x = dlat * dlat + dlng * dlng * Math.cos(lat1) * Math.cos(lat2);
    return (2 * Math.atan2(Math.sqrt(x), Math.sqrt(Math.max(0.0, 1.0 - x)))) * EARTH_RADIUS_METERS;
}