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.sym_part.Sym_Part_Objective.java

protected int findTileSYMPART(double x1, double x2) {
    int i, j, dim;
    double[] x = new double[2];
    double h1;//from w  w  w  . j av  a  2s  .  c  om
    double omega = Math.PI / 4.0;
    double si = Math.sin(omega), co = Math.cos(omega);

    x[0] = x1;
    x[1] = x2;

    //rotate( 2, x );
    for (dim = 0; dim + 1 < 2; dim += 2) {
        h1 = x[dim];
        x[dim] = co * h1 - si * x[dim + 1];
        x[dim + 1] = si * h1 + co * x[dim + 1];
    }

    int[] ij = findTile(x[0], x[1]);

    i = ij[0];
    j = ij[1];

    // restrict to 9 tiles
    if (Math.abs(i) > 1 || Math.abs(j) > 1) {
        return -1;
    }

    return (i + 1) * 3 + (j + 1);
}

From source file:neironweb.Frame.java

public Frame() {
    super("neural network");
    //JPanel pane = new JPanel();

    setLayout(null);/*from  ww w  . j  a  va 2s .  c om*/

    JPanel mailPanel = new JPanel();
    mailPanel.setLayout(null);
    mailPanel.setLocation(50, 30);
    mailPanel.setSize(300, 170);
    mailPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    JLabel mailLabel = new JLabel("e-mail:");
    mailLabel.setLocation(10, 10);
    mailLabel.setSize(50, 30);
    mailPanel.add(mailLabel);

    JLabel dirMailLabel = new JLabel("direct:");
    dirMailLabel.setLocation(10, 50);
    dirMailLabel.setSize(50, 30);
    mailPanel.add(dirMailLabel);

    JTextField mailField = new JTextField("mail@mail.ru");
    mailField.setSize(150, 30);
    mailField.setLocation(80, 10);
    mailPanel.add(mailField);

    JTextField textField = new JTextField("INBOX");
    textField.setLocation(80, 50);
    textField.setSize(150, 30);
    mailPanel.add(textField);

    JButton mailButton = new JButton("Analyze");
    mailButton.setLocation(80, 90);
    mailButton.setSize(150, 30);
    mailPanel.add(mailButton);

    //        JButton eduButton = new JButton("Start education");
    //        eduButton.setLocation(0, 50);
    //        eduButton.setSize(150, 30);
    //        buttonPanel.add(eduButton);

    XYSeries xyser = new XYSeries("");
    XYDataset xy = new XYSeriesCollection(xyser);
    JFreeChart jf = ChartFactory.createXYLineChart("Education", "X", "Y", xy);

    for (int i = 0; i < 100; i++)
        xyser.add(i, Math.cos(i));

    ChartPanel chartPanel = new ChartPanel(jf);
    chartPanel.setSize(700, 300);
    chartPanel.setLocation(50, 230);
    chartPanel.setBorder(BorderFactory.createLineBorder(Color.black));

    //        JPanel myChartPanel = new JPanel();        
    //        myChartPanel.setLayout(null);
    //        myChartPanel.setLocation(50, 230);
    //        myChartPanel.setSize(700, 300);
    //        myChartPanel
    //      myChartPanel.add(chartPanel);        

    setSize(800, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container con = this.getContentPane(); // inherit main frame
    //con.add(pane); 
    con.add(mailPanel);
    //con.add(myChartPanel);
    con.add(chartPanel);
    setVisible(true);

}

From source file:com.gwac.util.SearchBoxSphere.java

/**
 * ???searchRadius(ra,dec)??/* www. j  a v  a  2s  . c o  m*/
 *
 * @param ra ???
 * @param dec ??
 * @param searchRadius ?? ??
 * @return 0,1,2. 0?????radec?searchRadius?
 * 1?0360??[minRa, maxRa]
 * 2?0360??[minRa,360][0, maxRa]
 */
public int calSearchBox(double ra, double dec, double searchRadius) {

    int flag = 0;
    if (!(ra > 360.0 || ra < 0.0 || dec > 90.0 || dec < -90.0 || searchRadius > 20.0)) {
        minDec = dec - searchRadius;
        maxDec = dec + searchRadius;
        if (getMaxDec() > 90.0) {
            maxDec = 90;
        }
        if (getMinDec() < -90.0) {
            minDec = -90;
        }

        double tDec = Math.abs(maxDec) > Math.abs(minDec) ? Math.abs(maxDec) : Math.abs(minDec);
        ///180
        double cosd = Math.cos(tDec * 0.0174532925);
        if (cosd > searchRadius / 180.0) {
            maxRa = (ra + searchRadius / cosd + 360.0) % 360.0;
            minRa = (ra - searchRadius / cosd + 360.0) % 360.0;
        } else {
            maxRa = 360;
            minRa = 0;
        }
        if (getMinRa() > getMaxRa()) {
            /**
             * ?0360
             */
            flag = 2;
        } else {
            flag = 1;
        }
    } else {
        log.error("search box exceed max value");
    }
    return flag;
}

From source file:GraphicsUtil.java

static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) {
    double offs = headAngle * Math.PI / 180.0;
    double angle = Math.atan2(y0 - y1, x0 - x1);
    int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1,
            x1 + (int) (headLength * Math.cos(angle - offs)) };
    int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1,
            y1 + (int) (headLength * Math.sin(angle - offs)) };
    g.drawLine(x0, y0, x1, y1);/*  w  ww.  ja v  a  2s . c  o  m*/
    g.drawPolyline(xs, ys, 3);
}

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

public static ComplexNumber exp(final ComplexNumber z) {
    ArgumentChecker.notNull(z, "z");
    final double mult = Math.exp(z.getReal());
    return new ComplexNumber(mult * Math.cos(z.getImaginary()), mult * Math.sin(z.getImaginary()));
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz3.S_Dtlz3_Objective.java

@Override
public double evaluate(double[] x) {

    int nx = x.length;

    int i = 0;/*from   w w  w . ja  va 2 s. c  o m*/
    int j = 0;
    int k = nx - numberOfObjectives + 1;
    double g = 0;

    double[] z = new double[nx];
    double[] zz = new double[nx];
    double[] p = new double[nx];
    double[] psum = new double[numberOfObjectives];

    // denormalize vector:
    for (i = 0; i < nx; i++) {
        x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2;
    }

    for (i = 0; i < nx; i++) {
        z[i] = x[i] - o[i];

        if (z[i] < 0) {
            zz[i] = -lambda[i] * z[i];
            p[i] = -z[i] / d[i];
        } else {
            zz[i] = z[i];
            p[i] = 0;
        }
    }

    for (j = 0; j < numberOfObjectives; j++) {
        psum[j] = 0;
    }

    for (i = nx - k + 1; i <= nx; i++) {
        g += Math.pow(zz[i - 1] - 0.5, 2) - Math.cos(20 * Math.PI * (zz[i - 1] - 0.5));
        for (j = 0; j < numberOfObjectives; j++) {
            psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2));
        }
    }

    g = 100 * (k + g);

    double ff = (1 + g);

    for (j = numberOfObjectives - objNumber; j >= 1; j--) {
        ff *= Math.cos(zz[j - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2));
    }

    if (objNumber > 1) {
        ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(
                Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2));
    }

    return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1);

}

From source file:edu.uci.ics.jung.algorithms.layout.BalloonLayout.java

protected void setPolars(List<V> kids, Point2D parentLocation, double parentRadius) {

    int childCount = kids.size();
    if (childCount == 0)
        return;/* w  w  w  .ja  v  a  2  s .  co  m*/
    // handle the 1-child case with 0 limit on angle.
    double angle = Math.max(0, Math.PI / 2 * (1 - 2.0 / childCount));
    double childRadius = parentRadius * Math.cos(angle) / (1 + Math.cos(angle));
    double radius = parentRadius - childRadius;

    double rand = Math.random();

    for (int i = 0; i < childCount; i++) {
        V child = kids.get(i);
        double theta = i * 2 * Math.PI / childCount + rand;
        radii.put(child, childRadius);

        PolarPoint pp = new PolarPoint(theta, radius);
        polarLocations.put(child, pp);

        Point2D p = PolarPoint.polarToCartesian(pp);
        p.setLocation(p.getX() + parentLocation.getX(), p.getY() + parentLocation.getY());
        locations.put(child, p);
        setPolars(new ArrayList<V>(graph.getChildren(child)), p, childRadius);
    }
}

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

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

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static Number opPow(MutableNumber out, Number a, double b) {
    double m = Math.pow(FastMath.hypot(a.r(), a.i()), b);
    double f = Math.atan2(a.i(), a.r()) * b;
    return out.set(m * Math.cos(f), m * Math.sin(f));
}

From source file:com.github.aptd.simulation.elements.common.CMath.java

/**
 * creates a rotation matrix/*w w  w  . ja v a2 s.c om*/
 *
 * @param p_alpha angel in radians
 * @return matrix
 *
 * @see https://en.wikipedia.org/wiki/Rotation_matrix
 */
public static DoubleMatrix2D rotationmatrix(final double p_alpha) {
    final double l_sin = Math.sin(p_alpha);
    final double l_cos = Math.cos(p_alpha);
    return new DenseDoubleMatrix2D(new double[][] { { l_cos, l_sin }, { -l_sin, l_cos } });
}