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:jp.co.tweetmap.Fragment0.java

/**
 * Calculates distance of cameras coordinate.
 *
 * @param a old camera position./*w ww  .jav  a  2 s .  co  m*/
 * @param b new camera position.
 */
private double calcDistance(CameraPosition a, CameraPosition b) {
    if (LogUtil.isDebug())
        Log.e(TAG, "### calcDistance() ###");
    double lata = Math.toRadians(a.target.latitude);
    double lnga = Math.toRadians(a.target.longitude);

    double latb = Math.toRadians(b.target.latitude);
    double lngb = Math.toRadians(b.target.longitude);

    return MapUtil.EQUATORIAL_RADIUS * Math
            .acos(Math.sin(lata) * Math.sin(latb) + Math.cos(lata) * Math.cos(latb) * Math.cos(lngb - lnga));
}

From source file:msi.gaml.operators.Maths.java

@operator(value = "acos", can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "Returns the value (in the interval [0,180], in decimal degrees) of the arccos of the operand (which should be in [-1,1]).", masterDoc = true, usages = {
        @usage(value = "if the right-hand operand is outside of the [-1,1] interval, returns NaN") }, examples = @example(value = "acos (0)", equals = "90.0"), see = {
                "asin", "atan", "cos" })
public static Double acos(final Double rv) {
    return Math.acos(rv) * toDeg;
}

From source file:ffx.potential.bonded.ImproperTorsion.java

/**
 * Evaluate this Improper Torsion energy.
 *
 * @param gradient Evaluate the gradient.
 * @param threadID// w  w  w.j  ava2 s.com
 * @param gradX
 * @param gradY
 * @param gradZ
 * @return Returns the energy.
 */
@Override
public double energy(boolean gradient, int threadID, AtomicDoubleArray gradX, AtomicDoubleArray gradY,
        AtomicDoubleArray gradZ, AtomicDoubleArray lambdaGradX, AtomicDoubleArray lambdaGradY,
        AtomicDoubleArray lambdaGradZ) {

    double a0[] = new double[3];
    double a1[] = new double[3];
    double a2[] = new double[3];
    double a3[] = new double[3];
    /**
     * Vector from Atom 1 to Atom 0.
     */
    double v10[] = new double[3];
    /**
     * Vector from Atom 2 to Atom 1.
     */
    double v21[] = new double[3];
    /**
     * Vector from Atom 3 to Atom 2.
     */
    double v32[] = new double[3];
    /**
     * Vector from Atom 3 to Atom 1.
     */
    double v31[] = new double[3];
    /**
     * Vector from Atom 2 to Atom 0.
     */
    double v20[] = new double[3];
    double t[] = new double[3];
    double u[] = new double[3];
    double tu[] = new double[3];
    double dedu[] = new double[3];
    double dedt[] = new double[3];
    /**
     * Gradient on atoms 0, 1, 2 & 3.
     */
    double g0[] = new double[3];
    double g1[] = new double[3];
    double g2[] = new double[3];
    double g3[] = new double[3];
    /**
     * Work arrays.
     */
    double g1a[] = new double[3];
    double g2a[] = new double[3];

    energy = 0.0;
    value = 0.0;
    atoms[0].getXYZ(a0);
    atoms[1].getXYZ(a1);
    atoms[2].getXYZ(a2);
    atoms[3].getXYZ(a3);
    diff(a1, a0, v10);
    diff(a2, a1, v21);
    diff(a3, a2, v32);
    cross(v10, v21, t);
    cross(v21, v32, u);
    cross(t, u, tu);
    double rt2 = dot(t, t);
    double ru2 = dot(u, u);
    double rtru = sqrt(rt2 * ru2);
    if (rtru != 0.0) {

        /* Set the improper torsional parameters for this angle */
        //double v1 = 0.0;
        //double c1 = 0.0;
        //double s1 = 0.0;
        double v2 = improperType.k;
        double c2 = improperType.cos;
        double s2 = improperType.sin;
        //double v3 = 0.0;
        // double c3 = 0.0;
        // double s3 = 0.0;

        /* compute the multiple angle trigonometry and the phase terms */
        double rcb = r(v21);
        double cosine = dot(t, u) / rtru;
        double sine = dot(v21, tu) / (rcb * rtru);
        double cosine2 = cosine * cosine - sine * sine;
        double sine2 = 2.0 * cosine * sine;
        //double cosine3 = cosine * cosine2 - sine * sine2;
        //double sine3 = cosine * sine2 + sine * cosine2;
        //double phi1 = 1.0 + (cosine * c1 + sine * s1);
        double phi2 = 1.0 + (cosine2 * c2 + sine2 * s2);
        //double phi3 = 1.0 + (cosine3 * c3 + sine3 * s3);
        //double dphi1 = (cosine * s1 - sine * c1);
        double dphi2 = 2.0 * (cosine2 * s2 - sine2 * c2);
        //double dphi3 = 3.0 * (cosine3 * s3 - sine3 * c3);

        /* calculate improper torsion energy and master chain rule term */
        value = Math.toDegrees(Math.acos(cosine));
        //energy = ImproperTorsionType.units * (v1 * phi1 + v2 * phi2 + v3 * phi3);
        //double dedphi = ImproperTorsionType.units * (v1 * dphi1 + v2 * dphi2 + v3 * dphi3);
        final double desvPrefactor = units * scaleFactor;
        final double prefactor = units * scaleFactor * esvLambda;
        energy = prefactor * (v2 * phi2);
        double dedphi = prefactor * (v2 * dphi2);
        if (esvTerm) {
            setEsvDeriv(desvPrefactor * (v2 * phi2) * dedesvChain);
        }

        if (gradient) {
            /**
             * Chain rule terms for first derivative components.
             */
            diff(a2, a0, v20);
            diff(a3, a1, v31);
            cross(t, v21, dedt);
            cross(u, v21, dedu);
            scalar(dedt, dedphi / (rt2 * rcb), dedt);
            scalar(dedu, -dedphi / (ru2 * rcb), dedu);
            /**
             * Compute first derivative components for this angle.
             */
            cross(dedt, v21, g0);
            cross(dedt, v20, g1a);
            cross(dedu, v32, g1);
            scalar(g1a, -1.0, g1a);
            sum(g1a, g1, g1);
            cross(dedt, v10, g2a);
            cross(dedu, v31, g2);
            scalar(g2, -1.0, g2);
            sum(g2a, g2, g2);
            cross(dedu, v21, g3);
            /**
             * Accumulate derivatives.
             */
            // atoms[0].addToXYZGradient(g0[0], g0[1], g0[2]);
            // atoms[1].addToXYZGradient(g1[0], g1[1], g1[2]);
            // atoms[2].addToXYZGradient(g2[0], g2[1], g2[2]);
            // atoms[3].addToXYZGradient(g3[0], g3[1], g3[2]);
            int i0 = atoms[0].getXYZIndex() - 1;
            gradX.add(threadID, i0, g0[0]);
            gradY.add(threadID, i0, g0[1]);
            gradZ.add(threadID, i0, g0[2]);
            int i1 = atoms[1].getXYZIndex() - 1;
            gradX.add(threadID, i1, g1[0]);
            gradY.add(threadID, i1, g1[1]);
            gradZ.add(threadID, i1, g1[2]);
            int i2 = atoms[2].getXYZIndex() - 1;
            gradX.add(threadID, i2, g2[0]);
            gradY.add(threadID, i2, g2[1]);
            gradZ.add(threadID, i2, g2[2]);
            int i3 = atoms[3].getXYZIndex() - 1;
            gradX.add(threadID, i3, g3[0]);
            gradY.add(threadID, i3, g3[1]);
            gradZ.add(threadID, i3, g3[2]);
        }
    }

    // log();
    return energy;
}

From source file:msi.gaml.operators.Maths.java

@operator(value = "acos", can_be_const = true, category = { IOperatorCategory.ARITHMETIC })
@doc(value = "the arccos of the operand ")
public static Double acos(final Integer rv) {
    return Math.acos(rv) * toDeg;
}

From source file:org.eclipse.smarthome.binding.astro.internal.calc.SunCalc.java

private double getHourAngle(double h, double phi, double d) {
    return Math.acos((Math.sin(h) - Math.sin(phi) * Math.sin(d)) / (Math.cos(phi) * Math.cos(d)));
}

From source file:org.nd4j.linalg.api.complex.BaseComplexFloat.java

/**
 * Returns the argument of a complex number.
 */// w  ww  .j  ava  2s .  c o m
@Override
public Float complexArgument() {
    return (float) Math.acos(realComponent() / absoluteValue());
}

From source file:org.nd4j.linalg.api.complex.BaseComplexDouble.java

/**
 * Returns the argument of a complex number.
 */
@Override
public Double complexArgument() {
    return Math.acos(realComponent() / absoluteValue());
}

From source file:edu.umb.subway.DialogActivity.java

private double distance(double lat1, double lon1, double lat2, double lon2) {
    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);//from  w  ww.  j a v a  2  s.c o m
    dist = dist * 60 * 1.1515 / 1.6;
    return (dist);
}

From source file:com.automaster.autoview.server.servlet.ExcelServlet.java

private double caculaDistanciaEntreDoisPontos(double lat1, double lon1, double lat2, double lon2) {

    //Transforma cordenadas em radianos
    /*String lat1Reduzida = String.valueOf(lat1);
    int index = lat1Reduzida.indexOf(".");
    String latFinal1 = lat1Reduzida.substring(0, index+5);
            //from   www.  j  ava 2s .  co m
    String lon1Reduzida = String.valueOf(lon1);
    String lonFinal1 = lon1Reduzida.substring(0, index+5);
            
    String lat2Reduzida = String.valueOf(lat2);
    String latFinal2 = lat2Reduzida.substring(0, index+5);
            
    String lon2Reduzida = String.valueOf(lon2);
    String lonFinal2 = lon2Reduzida.substring(0, index+5);*/

    double lat01 = Math.toRadians(lat1);
    double lon01 = Math.toRadians(lon1);
    double lat02 = Math.toRadians(lat2);
    double lon02 = Math.toRadians(lon2);
    //calcula a distncia em KM atravs da frmula
    double dist = (6371 * Math.acos(
            Math.cos(lat01) * Math.cos(lat02) * Math.cos(lon02 - lon01) + Math.sin(lat01) * Math.sin(lat02)));
    //formata o resultado
    if (dist > 0) {
        BigDecimal decimalFormatado = new BigDecimal(dist).setScale(2, RoundingMode.HALF_EVEN);
        return decimalFormatado.doubleValue();
    }
    return 0;
    //return dist;

}

From source file:msi.gama.common.geometry.Rotation3D.java

/**
 * Get the angle of the rotation in radians
 * //www.  j ava2s .  co  m
 * @return angle of the rotation (between 0 and π)
 * @see #Rotation(GamaPoint, double)
 */
public double getAngle() {
    if (q0 < -0.1 || q0 > 0.1) {
        return 2 * Math.asin(Math.sqrt(q1 * q1 + q2 * q2 + q3 * q3));
    } else if (q0 < 0) {
        return 2 * Math.acos(-q0);
    }
    return 2 * Math.acos(q0);
}