Example usage for java.lang Math acos

List of usage examples for java.lang Math acos

Introduction

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

Prototype

public static double acos(double a) 

Source Link

Document

Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.

Usage

From source file:Main.java

/**
 * http://snippets.dzone.com/posts/show/10687
 * @param lat1/* www  .  j av  a  2 s.  c  om*/
 * @param lon1
 * @param lat2
 * @param lon2
 * @param unit   "M":miles, "K":kilometers, "N":Nautical Miles
 * @return
 */
public static double distance(double lat1, double lon1, double lat2, double lon2, String unit) {
    double theta = lon1 - lon2;
    double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
            + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
    dist = Math.acos(dist);
    dist = rad2deg(dist);
    dist = dist * 60 * 1.1515;
    if (unit == "K") {
        dist = dist * 1.609344;
    } else if (unit == "N") {
        dist = dist * 0.8684;
    }
    return (dist);
}

From source file:Main.java

public static double distance(double lat1, double lon1, double lat2, double lon2) {
    if (lat1 == lat2 && lon1 == lon2) {
        return 0;
    }/*from  w w w .j av  a  2 s .  co  m*/
    // haversine great circle distance approximation, returns meters
    double theta = lon1 - lon2;
    double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
            + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
    if (dist > 1) {
        return 0;
    }
    dist = Math.acos(dist);
    dist = rad2deg(dist);
    dist = dist * 60; // 60 nautical miles per degree of separation
    dist = dist * 1852; // 1852 meters per nautical mile
    return dist / 1000;
}

From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java

public static double acos(final double x) {
    return Math.acos(x);
}

From source file:Main.java

/**
 * Metoda care calculeaza viteza cu care se deplaseaza intre 2 coordonate
 * date(Lat+long) intr-un interval de timp [time_1,time_2]. Calculam
 * distanta dintre cele doua coordonate folosind formula " Great-circle
 * distance" viteza = distanta transformata in m/diferenta dintre cei 2
 * timpi primiti ca parametru// w w w  .j a  v  a2 s. co  m
 */
public static double computeSpeed(double lat_1, double long_1, long time_1, double lat_2, double long_2,
        long time_2) {
    double speed; // speed->m/s
    double distanceKm;
    double distanceM;
    long time;
    double r = 6378.137;

    double e = (double) Math.acos(
            Math.sin(lat_1) * Math.sin(lat_2) + Math.cos(lat_1) * Math.cos(lat_2) * Math.cos(long_2 - long_1));
    e = e / 180 * (double) Math.PI;
    distanceKm = e * r;
    distanceM = distanceKm * 1000;
    time = (time_2 - time_1) / 1000;
    speed = distanceM / time;

    return speed;
}

From source file:Main.java

public static float acos(float value) {
    return (float) Math.acos(value);
}

From source file:Main.java

/**
 * Computes the distance in meters 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 Distance between the two points in meters.
 *//*from  w ww  .  j  a v  a  2 s.  c o m*/
public static double distance(double lat1, double lon1, double lat2, double lon2) {
    double lat1Rad = Math.toRadians(lat1);
    double lat2Rad = Math.toRadians(lat2);
    double deltaLonRad = Math.toRadians(lon2 - lon1);

    return Math.acos(Math.sin(lat1Rad) * Math.sin(lat2Rad)
            + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad)) * EARTH_RADIUS_KM * 1000;
}

From source file:Main.java

/**
 * Computes the distance in kilometers 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 Distance between the two points in kilometers.
 *///  w ww . j  a v a 2 s .c  om
public static double distanceKm(double lat1, double lon1, double lat2, double lon2) {
    double lat1Rad = Math.toRadians(lat1);
    double lat2Rad = Math.toRadians(lat2);
    double deltaLonRad = Math.toRadians(lon2 - lon1);

    return Math.acos(Math.sin(lat1Rad) * Math.sin(lat2Rad)
            + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad)) * EARTH_RADIUS_KM;
}

From source file:Main.java

public static BigDecimal acos(BigDecimal val) {
    return BigDecimal.valueOf(Math.acos(val.doubleValue()));
}

From source file:Main.java

static double distanceFromPointOnArc(double dA, double dB, double dAB) {
    // In spherical trinagle ABC
    // a is length of arc BC, that is dB
    // b is length of arc AC, that is dA
    // c is length of arc AB, that is dAB
    // We rename parameters so following formulas are more clear:
    double a = dB;
    double b = dA;
    double c = dAB;

    // First, we calculate angles alpha and beta in spherical triangle ABC
    // and based on them we decide how to calculate the distance:
    if (Math.sin(b) * Math.sin(c) == 0.0 || Math.sin(c) * Math.sin(a) == 0.0) {
        // It probably means that one of distance is n*pi, which gives around 20000km for n = 1,
        // unlikely for Denmark, so we should be fine.
        return -1.0;
    }//from w  ww  .j  a  v a 2s .  c  o m

    double alpha = Math.acos((Math.cos(a) - Math.cos(b) * Math.cos(c)) / (Math.sin(b) * Math.sin(c)));
    double beta = Math.acos((Math.cos(b) - Math.cos(c) * Math.cos(a)) / (Math.sin(c) * Math.sin(a)));

    // It is possible that both sinuses are too small so we can get nan when dividing with them
    if (Double.isNaN(alpha) || Double.isNaN(beta)) {
        return -1.0;
    }

    // If alpha or beta are zero or pi, it means that C is on the same circle as arc AB,
    // we just need to figure out if it is between AB:
    if (alpha == 0.0 || beta == 0.0) {
        return (dA + dB > dAB) ? Math.min(dA, dB) : 0.0;
    }

    // If alpha is obtuse and beta is acute angle, then
    // distance is equal to dA:
    if (alpha > Math.PI / 2 && beta < Math.PI / 2)
        return -1;

    // Analogously, if beta is obtuse and alpha is acute angle, then
    // distance is equal to dB:
    if (beta > Math.PI / 2 && alpha < Math.PI / 2)
        return -1;

    // Again, unlikely, since it would render at least pi/2*EARTH_RADIUS_IN_METERS, which is too much.
    if (Math.cos(a) == 0.0)
        return -1;

    double x = Math.atan(-1.0 / Math.tan(c) + (Math.cos(b) / (Math.cos(a) * Math.sin(c))));

    return x;
}

From source file:peasy2d.InterpolationUtil.java

static public Rotation slerp(final Rotation a, final Rotation b, final double t) {
    final double cosTheta = a.getQ0() * b.getQ0() + a.getQ1() * b.getQ1() + a.getQ2() * b.getQ2()
            + a.getQ3() * b.getQ3();/*from   ww  w .java2 s.  c o  m*/
    final double theta = Math.acos(cosTheta);
    final double sinTheta = Math.sin(theta);

    double w1, w2;
    if (sinTheta > 0.001f) {
        w1 = Math.sin((1.0f - t) * theta) / sinTheta;
        w2 = Math.sin(t * theta) / sinTheta;
    } else {
        w1 = 1.0 - t;
        w2 = t;
    }
    return new Rotation(w1 * a.getQ0() + w2 * b.getQ0(), w1 * a.getQ1() + w2 * b.getQ1(),
            w1 * a.getQ2() + w2 * b.getQ2(), w1 * a.getQ3() + w2 * b.getQ3(), true);
}