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:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java

protected double convex(double[] x, int m, int M) {
    int i;//  w  ww .jav  a2s .  c  o m
    double result = 1.0;
    for (i = 1; i <= M - m; i++) {
        result *= 1.0 - Math.cos(x[i - 1] * Math.PI / 2.0);
    }

    if (m != 1) {
        result *= 1.0 - Math.sin(x[M - m] * Math.PI / 2.0);
    }

    return correct_to_01(result, EPSILON);
}

From source file:io.lonelyrobot.empires.fw.game.obj.BaseObject.java

/**
 * This function is called recursively from the {@link Star}, updating it's children
 * with an offset of {0, 0}. These children then move themselves according to the
 * position of their parent and then pass this offset to their children. These children
 * move themselves by the offset and then calculate their additional offset.
 * /*from w ww . java2s .  c  o  m*/
 * @param parentOffset
 */
public void updateOrbits(Vector2D parentOffset) {
    Vector2D offset = new Vector2D(0, 0);

    if (orbit != null && orbit.getParent() != null) {

        Vector2D p = orbit.getParent().getSolPos();

        /** Calculate own offset */
        double x = p.getX() + orbit.getRadius() * Math.cos(orbit.getStep());
        double y = p.getY() + orbit.getRadius() * Math.sin(orbit.getStep());

        orbit.setStep(orbit.getStep() + orbit.getStepSpeed());

        Vector2D newPos = new Vector2D(x, y);
        newPos.add(parentOffset);
        // offset.add(new Vector2D(x, y));

        /** Add the parent offset on top */
        // offset.add(parentOffset);

        offset.add(newPos);

        /** Apply position to self */
        this.setSolPos(newPos);

    }

    /** Only propagate orbital offsets if self is Orbitable */
    if (!(this instanceof Orbitable))
        return;

    /** Call function for all children with the new (accumilated) offset */
    Tools.safe(orbit.getChildren()).forEach((i) -> i.updateOrbits(offset));
}

From source file:Main.java

public static double eval(final String str) {
    return new Object() {
        private int pos = -1, ch;

        void nextChar() {
            ch = (++pos < str.length()) ? str.charAt(pos) : -1;
        }/*  ww  w . j a  v  a  2s. co  m*/

        boolean eat(int charToEat) {
            while (ch == ' ') {
                nextChar();
            }
            if (ch == charToEat) {
                nextChar();
                return true;
            }
            return false;
        }

        double parse() {
            nextChar();
            double x = parseExpression();
            if (pos < str.length()) {
                throw new IllegalArgumentException("Unexpected: " + (char) ch);
            }
            return x;
        }

        // Grammar:
        // expression = term | expression `+` term | expression `-` term
        // term = factor | term `*` factor | term `/` factor
        // factor = `+` factor | `-` factor | `(` expression `)`
        //        | number | functionName factor | factor `^` factor

        double parseExpression() {
            double x = parseTerm();
            for (;;) {
                if (eat('+')) {
                    x += parseTerm(); // addition
                } else {
                    if (eat('-')) {
                        x -= parseTerm(); // subtraction
                    } else {
                        return x;
                    }
                }
            }
        }

        double parseTerm() {
            double x = parseFactor();
            for (;;) {
                if (eat('*')) {
                    x *= parseFactor(); // multiplication
                } else {
                    if (eat('/')) {
                        x /= parseFactor(); // division
                    } else {
                        return x;
                    }
                }
            }
        }

        double parseFactor() {
            if (eat('+')) {
                return parseFactor(); // unary plus
            }
            if (eat('-')) {
                return -parseFactor(); // unary minus
            }

            double x;
            int startPos = this.pos;
            if (eat('(')) { // parentheses
                x = parseExpression();
                eat(')');
            } else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
                while ((ch >= '0' && ch <= '9') || ch == '.') {
                    nextChar();
                }
                x = Double.parseDouble(str.substring(startPos, this.pos));
            } else if (ch >= 'a' && ch <= 'z') { // functions
                while (ch >= 'a' && ch <= 'z') {
                    nextChar();
                }
                String func = str.substring(startPos, this.pos);
                x = parseFactor();
                switch (func) {
                case "sqrt":
                    x = Math.sqrt(x);
                    break;
                case "sin":
                    x = Math.sin(Math.toRadians(x));
                    break;
                case "cos":
                    x = Math.cos(Math.toRadians(x));
                    break;
                case "tan":
                    x = Math.tan(Math.toRadians(x));
                    break;
                default:
                    throw new IllegalArgumentException("Unknown function: " + func);
                }
            } else {
                throw new IllegalArgumentException("Unexpected: " + (char) ch);
            }

            if (eat('^')) {
                x = Math.pow(x, parseFactor()); // exponentiation
            }

            return x;
        }
    }.parse();
}

From source file:Wavelet.java

/** This is the function that is plotted. */
double func(double x) {
    Dimension d = getSize();//from   w  w w  . j  a v  a 2 s. com
    return (Math.cos(x / 9) + Math.sin(x / 3) + 1) * d.height / 4;
}

From source file:geogebra.kernel.GeoVec2D.java

public void setPolarCoords(double r, double phi) {
    x = r * Math.cos(phi);
    y = r * Math.sin(phi);
}

From source file:io.github.malapert.jwcs.coordsystem.FK4.java

/**
 * Compute the E-terms (elliptic terms of aberration) for a given epoch.
 * /*from  w  w  w  .j  a  v  a 2s.  c o m*/
 * Reference:
 * ----------
 * Seidelman, P.K.,  1992.  Explanatory Supplement to the Astronomical
 * Almanac.  University Science Books, Mill Valley
 *
 * Notes:     
 * -------
 * The method is described on page 170/171 of the ES.
 * One needs to process the e-terms for the appropriate
 * epoch This routine returns the e-term vector for arbitrary epoch.
 * 
 * @param epoch A Besselian epoch
 * @return A tuple containing the e-terms vector (DeltaD,DeltaC,DeltaC.tan(e0))
 */
public final static RealMatrix getEterms(float epoch) {
    //Julian centuries since B1950
    double T = (epoch - 1950.0d) * 1.00002135903d / 100.0d;
    //Eccentricity of the Earth's orbit
    double ec = 0.01673011d - (0.00004193d + 0.000000126d * T) * T;
    //Mean obliquity of the ecliptic. Method is different compared to 
    //functions for the obliquity defined earlier. This function depends
    //on time wrt. epoch 1950 not epoch 2000.
    double ob = (84404.836d - (46.8495d + (0.00319d + 0.00181d * T) * T) * T);
    ob = Math.toRadians(ob / 3600.0d);
    //Mean longitude of perihelion of the solar orbit
    double p = (1015489.951d + (6190.67d + (1.65d + 0.012d * T) * T) * T);
    p = Math.toRadians(p / 3600.0d);
    //Calculate the E-terms vector
    double ek = ec * Math.toRadians(20.49522d / 3600.0d); // 20.49552 is constant of aberration at J2000
    double cp = Math.cos(p);
    //       -DeltaD        DeltaC            DeltaC.tan(e0)
    double[][] array = { { ek * Math.sin(p), -1 * ek * cp * Math.cos(ob), -1 * ek * cp * Math.sin(ob) } };
    return MatrixUtils.createRealMatrix(array);
}

From source file:com.wwidesigner.geometry.calculation.DefaultHoleCalculator.java

public TransferMatrix calcTransferMatrix_2010(Hole hole, boolean isOpen, double waveNumber,
        PhysicalParameters parameters) {
    double radius = mFudgeFactor * hole.getDiameter() / 2;
    double boreRadius = hole.getBoreDiameter() / 2;
    Complex Zs = null;//www. j a v  a2 s. c  o  m
    Complex Za = null;

    // double Z0 = parameters.calcZ0(boreRadius);
    double Z0h = parameters.calcZ0(radius);

    double delta = radius / boreRadius;

    double tm = (radius * delta / 8.) * (1. + 0.207 * delta * delta * delta);
    double te = hole.getHeight() + tm;

    double ta = 0.;

    // Complex Gamma = Complex.I.multiply(wave_number);

    if (isOpen) // open
    {
        double kb = waveNumber * radius;
        double ka = waveNumber * boreRadius;
        double xhi = 0.25 * kb * kb;

        ta = (-0.35 + 0.06 * Math.tanh(2.7 * hole.getHeight() / radius)) * radius * delta * delta * delta
                * delta;

        Complex Zr = Complex.I.multiply(waveNumber * 0.61 * radius).add(xhi);

        Complex Zo = (Zr.multiply(Math.cos(waveNumber * te)).add(Complex.I.multiply(Math.sin(waveNumber * te))))
                .divide(Complex.I.multiply(Zr).multiply(Math.sin(waveNumber * te))
                        .add(Math.cos(waveNumber * te)));

        double ti = radius
                * (0.822 - 0.10 * delta - 1.57 * delta * delta + 2.14 * delta * delta * delta
                        - 1.6 * delta * delta * delta * delta + 0.50 * delta * delta * delta * delta * delta)
                * (1. + (1. - 4.56 * delta + 6.55 * delta * delta)
                        * (0.17 * ka + 0.92 * ka * ka + 0.16 * ka * ka * ka - 0.29 * ka * ka * ka * ka));

        Zs = Complex.I.multiply(waveNumber * ti).add(Zo).multiply(Z0h);

    } else {
        ta = (-0.12 - 0.17 * Math.tanh(2.4 * hole.getHeight() / radius)) * radius * delta * delta * delta
                * delta;
        Zs = Complex.valueOf(0, -Z0h / Math.tan(waveNumber * te));
    }

    Za = Complex.I.multiply(Z0h * waveNumber * ta);
    Complex Za_Zs = Za.divide(Zs);

    TransferMatrix result = new TransferMatrix(Za_Zs.divide(2.).add(1.), Za.multiply(Za_Zs.divide(4.).add(1.)),
            Complex.ONE.divide(Zs), Za_Zs.divide(2.0).add(1.));

    assert result.determinant() == Complex.ONE;

    return result;
}

From source file:com.opengamma.analytics.math.minimization.NonLinearTransformFunctionTest.java

@Test
public void testNullTransform() {
    BitSet fixed = new BitSet();
    fixed.set(0);//from w w w .  j a v a 2  s  .co m
    DoubleMatrix1D start = new DoubleMatrix1D(new double[] { Math.PI / 4, 1 });
    UncoupledParameterTransforms transforms = new UncoupledParameterTransforms(start, NULL_TRANSFORMS, fixed);
    NonLinearTransformFunction transFunc = new NonLinearTransformFunction(FUNCTION, JACOBIAN, transforms);
    Function1D<DoubleMatrix1D, DoubleMatrix1D> func = transFunc.getFittingFunction();
    Function1D<DoubleMatrix1D, DoubleMatrix2D> jacFunc = transFunc.getFittingJacobian();

    DoubleMatrix1D x = new DoubleMatrix1D(new double[] { 0.5 });
    final double rootHalf = Math.sqrt(0.5);
    DoubleMatrix1D y = func.evaluate(x);
    assertEquals(3, y.getNumberOfElements());
    assertEquals(rootHalf * Math.cos(0.5), y.getEntry(0), 1e-9);
    assertEquals(rootHalf * Math.sin(0.5), y.getEntry(1), 1e-9);
    assertEquals(rootHalf, y.getEntry(2), 1e-9);

    DoubleMatrix2D jac = jacFunc.evaluate(x);
    assertEquals(3, jac.getNumberOfRows());
    assertEquals(1, jac.getNumberOfColumns());
    assertEquals(-rootHalf * Math.sin(0.5), jac.getEntry(0, 0), 1e-9);
    assertEquals(rootHalf * Math.cos(0.5), jac.getEntry(1, 0), 1e-9);
    assertEquals(0, jac.getEntry(2, 0), 1e-9);
}

From source file:com.androidquery.simplefeed.data.Place.java

public static double distFrom(double lat1, double lng1, double lat2, double lng2) {

    double earthRadius = 3958.75;
    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));
    double dist = earthRadius * c;

    int meterConversion = 1609;
    return new Double(dist * meterConversion);

}

From source file:dtu.ds.warnme.services.impl.EventsServiceImpl.java

@Override
public List<EventEntity> getEvents(Float latitude, Float longitude, Float bearing, Float radius,
        EventType[] types) {/*  w w  w  . java2s .  c  om*/
    Float northMargin, eastMargin, southMargin, westMargin;

    northMargin = southMargin = eastMargin = westMargin = SOURROUNDING_MARGIN;

    if (bearing >= 0 && bearing < 90) {
        northMargin = radius;
        eastMargin = radius;
    } else if (bearing >= 90 && bearing < 180) {
        eastMargin = radius;
        southMargin = radius;
    } else if (bearing >= 180 && bearing < 270) {
        southMargin = radius;
        westMargin = radius;
    } else if (bearing >= 270 && bearing < 360) {
        westMargin = radius;
        northMargin = radius;
    } else {
        northMargin = southMargin = eastMargin = westMargin = radius;
    }

    Float latMeter = 1f / 110540f;
    Float longMeter = 1f / (float) (111320 * Math.cos(latitude));

    northMargin *= latMeter;
    southMargin *= latMeter;
    westMargin *= longMeter;
    eastMargin *= longMeter;

    Float nLat = latitude + northMargin;
    Float sLat = latitude - southMargin;
    Float eLng = longitude + eastMargin;
    Float wLng = longitude - westMargin;

    return eventsDao.getNearestEvents(nLat, sLat, eLng, wLng, types);
}