Example usage for java.lang Math PI

List of usage examples for java.lang Math PI

Introduction

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

Prototype

double PI

To view the source code for java.lang Math PI.

Click Source Link

Document

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

Usage

From source file:org.usfirst.frc.team2084.neuralnetwork.HeadingNeuralNetworkTrainer.java

public HeadingNeuralNetworkTrainer() {
    outputGraphNetworkSeries = new XYSeries("Network Prediction");
    outputGraphDataSeries = new XYSeries("Error");
    final XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(outputGraphDataSeries);
    data.addSeries(outputGraphNetworkSeries);
    outputGraph = ChartFactory.createXYLineChart("Error vs. Output", "Time", "Error", data,
            PlotOrientation.VERTICAL, true, true, false);

    NumberAxis xAxis = new NumberAxis();
    xAxis.setRange(new Range(-Math.PI, Math.PI));
    xAxis.setAutoRange(false);// ww w  . j ava 2 s.  c o m
    NumberAxis yAxis = new NumberAxis();
    yAxis.setRange(new Range(-1, 1));

    XYPlot plot = (XYPlot) outputGraph.getPlot();
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    network = new Network(new int[] { 1, 5, 1 }, eta, momentum, new TransferFunction.HyperbolicTangent());

    try {
        SwingUtilities.invokeAndWait(() -> {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final Container content = frame.getContentPane();
            content.setLayout(new BorderLayout());

            outputGraphPanel = new ChartPanel(outputGraph);
            outputGraphPanel.setDomainZoomable(false);
            outputGraphPanel.setRangeZoomable(false);
            graphPanel.add(outputGraphPanel);

            graphPanel.setLayout(new GridLayout(1, 1));
            content.add(graphPanel, BorderLayout.CENTER);
            {

                JLabel etaLabel = new JLabel("Eta:");
                etaLabel.setLabelFor(etaField);
                etaField.setText(Double.toString(network.getEta()));
                etaField.setColumns(5);
                etaField.addPropertyChangeListener("value",
                        (evt) -> eta = ((Number) evt.getNewValue()).doubleValue());
                controlPanel.add(etaLabel);
                controlPanel.add(etaField);

                JLabel momentumLabel = new JLabel("Momentum:");
                momentumLabel.setLabelFor(etaField);
                momentumField.setText(Double.toString(network.getMomentum()));
                momentumField.setColumns(5);
                momentumField.addPropertyChangeListener("value",
                        (evt) -> momentum = ((Number) evt.getNewValue()).doubleValue());
                controlPanel.add(momentumLabel);
                controlPanel.add(momentumField);

                JLabel iterationsLabel = new JLabel("Iterations:");
                iterationsLabel.setLabelFor(iterationsField);
                iterationsField.setText(Integer.toString(iterations));
                iterationsField.setColumns(10);
                iterationsField.addPropertyChangeListener("value",
                        (evt) -> iterations = ((Number) evt.getNewValue()).intValue());
                controlPanel.add(iterationsLabel);
                controlPanel.add(iterationsField);
            }

            chooseDataButton.addActionListener((e) -> {
                if (dataDirectoryChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    dataDirectory = dataDirectoryChooser.getSelectedFile();
                    displayData();
                }
            });
            controlPanel.add(chooseDataButton);

            trainButton.addActionListener((e) -> trainNetwork());
            controlPanel.add(trainButton);

            saveButton.addActionListener((e) -> {
                saveNetwork();
            });
            controlPanel.add(saveButton);

            content.add(controlPanel, BorderLayout.SOUTH);

            dataDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        });
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.kentdisplays.synccardboarddemo.Page.java

/**
 * Sets up the drawing object data for use in an OpenGL ES context.
 *
 * @param is InputStream to the page to load the path data from.
 *///from   w  w  w .  ja va2 s .  co m
public Page(InputStream is, int glProgram, int direction) {

    this.mModel = new float[16];
    this.mGlProgram = glProgram;

    // Calculate the coordinates from the given path.
    ArrayList<Path> paths = pathsFromSamplePageInputStream(is);
    float finalCoords[] = {};
    float finalNormals[] = {};
    float finalColors[] = {};
    mNumberOfPaths = paths.size();
    for (int i = 0; i < mNumberOfPaths; i++) {
        Path path = paths.get(i);
        float x1 = (path.x1 / 13942 * 2) - 1;
        float y1 = (path.y1 / 20280 * 2) - 1;
        float x2 = (path.x2 / 13942 * 2) - 1;
        float y2 = (path.y2 / 20280 * 2) - 1;
        float width = path.width / 3000;
        width = width < 0.013f ? 0.013f : width; // Width should be at least 0.013

        float distance = (float) Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
        float angle = (float) Math.PI / 2 - (float) Math.asin((x2 - x1) / distance);
        float xdiff = (width / 2) * (float) Math.sin(angle);
        float ydiff = (width / 2) * (float) Math.cos(angle);

        float coords[] = { x1 - xdiff, y1 - ydiff, 1.0f, // top left
                x2 - xdiff, y2 - ydiff, 1.0f, // bottom left
                x1 + xdiff, y1 + ydiff, 1.0f, // top right
                x2 - xdiff, y2 - ydiff, 1.0f, // bottom left
                x2 + xdiff, y2 + ydiff, 1.0f, // bottom right
                x1 + xdiff, y1 + ydiff, 1.0f, // top right
        };

        float normals[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
                1.0f, 0.0f, 0.0f, 1.0f, };

        float colors[] = { 0.2f, 0.709803922f, 0.898039216f, 1.0f, 0.2f, 0.709803922f, 0.898039216f, 1.0f, 0.2f,
                0.709803922f, 0.898039216f, 1.0f, 0.2f, 0.709803922f, 0.898039216f, 1.0f, 0.2f, 0.709803922f,
                0.898039216f, 1.0f, 0.2f, 0.709803922f, 0.898039216f, 1.0f, };

        finalCoords = Floats.concat(finalCoords, coords);
        finalNormals = Floats.concat(finalNormals, normals);
        finalColors = Floats.concat(finalColors, colors);
    }

    ByteBuffer bbVertices = ByteBuffer.allocateDirect(finalCoords.length * 4);
    bbVertices.order(ByteOrder.nativeOrder());
    mPageVertices = bbVertices.asFloatBuffer();
    mPageVertices.put(finalCoords);
    mPageVertices.position(0);

    ByteBuffer bbNormals = ByteBuffer.allocateDirect(finalNormals.length * 4);
    bbNormals.order(ByteOrder.nativeOrder());
    mPageNormals = bbNormals.asFloatBuffer();
    mPageNormals.put(finalNormals);
    mPageNormals.position(0);

    ByteBuffer bbColors = ByteBuffer.allocateDirect(finalColors.length * 4);
    bbColors.order(ByteOrder.nativeOrder());
    mPageColors = bbColors.asFloatBuffer();
    mPageColors.put(finalColors);
    mPageColors.position(0);

    // Correctly place the page in the world.
    Matrix.setIdentityM(mModel, 0);
    switch (direction) {
    case 0:
        Matrix.translateM(mModel, 0, 0, 0, -mDistance); //Front.
        break;
    case 1:
        Matrix.translateM(mModel, 0, -mDistance, 0, 0); // Left.
        Matrix.rotateM(mModel, 0, 90, 0, 1f, 0);
        break;
    case 2:
        Matrix.translateM(mModel, 0, 0, 0, mDistance); // Behind.
        Matrix.rotateM(mModel, 0, 180, 0, 1f, 0);
        break;
    case 3:
        Matrix.translateM(mModel, 0, mDistance, 0, 0); // Right.
        Matrix.rotateM(mModel, 0, 270, 0, 1f, 0);
        break;
    }
}

From source file:com.nimbler.tp.util.DistanceLibrary.java

/** this is an overestimate */
public static double metersToDegrees(double distance) {
    return 360 * distance / (2 * Math.PI * RADIUS_OF_EARTH_IN_KM * 1000);
}

From source file:mase.app.indiana.Indiana.java

protected void placeAgents() {
    agents = new ArrayList<IndianaAgent>(par.numAgents);
    AgentController[] acs = gc.getAgentControllers(par.numAgents);
    double agentSeparation = (par.size - IndianaAgent.RADIUS) / par.numAgents;
    if (par.agentPlacement == AgentPlacement.LINE) {
        for (int i = 0; i < par.numAgents; i++) {
            IndianaAgent ag = new IndianaAgent(this, field, acs[i].clone());
            Double2D p = new Double2D((i + 1) * agentSeparation, par.size / 2);
            ag.setLocation(p);//ww w .j av a2s  .  c om
            ag.setOrientation(Math.PI);
            ag.setStopper(schedule.scheduleRepeating(ag));
            agents.add(ag);
        }
    } else if (par.agentPlacement == AgentPlacement.CIRCLES) {
        for (int i = 0; i < par.numAgents; i++) {
            IndianaAgent ag = new IndianaAgent(this, field, acs[i].clone());
            double radius = (i + 1) * agentSeparation;
            Double2D p = null;
            while (p == null) {
                double randAngle = this.random.nextDouble() * Math.PI * 2;
                Double2D candidate = new Double2D(FastMath.cos(randAngle) * radius,
                        gate.getCenter().y + FastMath.sin(randAngle) * radius);
                if (ag.checkInsideArena(candidate)) {
                    p = candidate;
                }
            }
            ag.setLocation(p);
            ag.setOrientation(random.nextDouble() * Math.PI * 2 - Math.PI);
            ag.setStopper(schedule.scheduleRepeating(ag));
            agents.add(ag);
        }
    }
    activeAgents = new ArrayList<IndianaAgent>(agents);
}

From source file:Randoms.java

/** Return a random double drawn from a Gaussian distribution with mean 0 and variance 1. */
public synchronized double nextGaussian() {
    if (!haveNextGaussian) {
        double v1 = nextUniform(), v2 = nextUniform();
        double x1, x2;
        x1 = Math.sqrt(-2 * Math.log(v1)) * Math.cos(2 * Math.PI * v2);
        x2 = Math.sqrt(-2 * Math.log(v1)) * Math.sin(2 * Math.PI * v2);
        nextGaussian = x2;//from   w  w w .  j a  v a 2 s. com
        haveNextGaussian = true;
        return x1;
    } else {
        haveNextGaussian = false;
        return nextGaussian;
    }
}

From source file:etomica.potential.EwaldSummation.java

public EwaldSummation(IBox box, AtomLeafAgentManager<MyCharge> atomAgentManager, ISpace _space, double kCut,
        double rCutRealES) {

    this.box = box;
    this.atomAgentManager = atomAgentManager;
    this.space = _space;
    this.secondDerivative = space.makeTensor();
    this.tempTensorkk = space.makeTensor();
    this.kCut = kCut;

    moleculeList = box.getMoleculeList();
    numMolecules = moleculeList.getMoleculeCount();
    boxSize = new double[] { box.getBoundary().getBoxSize().getX(0), box.getBoundary().getBoxSize().getX(1),
            box.getBoundary().getBoxSize().getX(2) };
    volume = box.getBoundary().volume();
    Lxyz = space.makeVector();//from ww  w  .ja v a  2s.co  m
    this.rCutRealES = rCutRealES;
    rCutSquared = rCutRealES * rCutRealES;
    nRealShells = new int[] { (int) Math.ceil(rCutRealES / boxSize[0] - 0.49999),
            (int) Math.ceil(rCutRealES / boxSize[1] - 0.49999),
            (int) Math.ceil(rCutRealES / boxSize[2] - 0.49999) };

    nKs = new int[] { (int) Math.ceil(boxSize[0] / 2.0 / Math.PI * kCut),
            (int) Math.ceil(boxSize[1] / 2.0 / Math.PI * kCut),
            (int) Math.ceil(boxSize[2] / 2.0 / Math.PI * kCut) };

    double s = Math.sqrt(rCutRealES * kCut / 2);

    alpha = s / rCutRealES; //=0.2406189232882774  //nX=1

    int nAtoms = box.getLeafList().getAtomCount();
    double Q2 = 0;
    for (int i = 0; i < nAtoms; i++) {//H
        IAtom atom = box.getLeafList().getAtom(i);
        double charge = atomAgentManager.getAgent(atom).charge;
        Q2 += charge * charge;
    }
    Q2 /= numMolecules;

    alpha2 = alpha * alpha;
    alpha3 = alpha * alpha2;

    basis = new double[] { 2 * Math.PI / boxSize[0], 2 * Math.PI / boxSize[1], 2 * Math.PI / boxSize[2] };
    gradient = new IVectorMutable[0];
    sinkrj = new double[0];
    coskrj = new double[0];
    rAB = space.makeVector();
    drTmp = space.makeVector();
    kVector = space.makeVector();
}

From source file:fsm.series.Series_CF.java

public double getF4Value(double y, int m, int n) {
    double Pi = Math.PI;

    double um = getMu_m(m);
    double un = getMu_m(n);
    double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um));

    double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un));
    double km = um / a;
    double kn = un / a;

    BigDecimal Ymd2;//  w ww.j  a va 2s. c o m
    BigDecimal Ynd2;

    BigDecimal cosh = new BigDecimal(alphaM * km * km * cosh(km * y));

    BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(-km * km * sin(km * y));
    BigDecimal cos = new BigDecimal(alphaM * km * km * cos(km * y));

    Ymd2 = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(alphaN * kn * kn * cosh(kn * y));

    BigDecimal sinhN = new BigDecimal(-kn * kn * sinh(kn * y));
    BigDecimal sinN = new BigDecimal(-kn * kn * sin(kn * y));
    BigDecimal cosN = new BigDecimal(alphaN * kn * kn * cos(kn * y));

    Ynd2 = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ymd2.multiply(Ynd2);

    return ans.doubleValue();
}

From source file:Text3DTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 4000, 0, 0, 0);

    TornadoRotation rotator = new TornadoRotation(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);/*from   w  w  w  .  j a v  a2 s . c  o  m*/

    objTrans.addChild(createText3D(rotator, "setString", 1, 10.0f, 6.0f, Text3D.PATH_RIGHT));
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:PureImmediateStereo.java

void computeSharedData() {
    // Compute angle of rotation based on alpha value
    angle = rotAlpha.value() * 2.0 * Math.PI;
    cmt.rotY(angle);
}

From source file:br.prof.salesfilho.oci.util.OCIUtils.java

/**
 * @param signal input signal//from ww w.  ja  va 2s  .  co m
 * @param kernel Kernel size
 * @precond input != null and Kernel size great then 0 and less then 10
 * @return AutoCorrentropy array
 */
public static double[] computeAutoCorrentropy(double[] signal, double kernel) {
    double twokSizeSquare = 2 * Math.pow(kernel, 2d);
    int signal_length = signal.length;
    double[] Y = new double[signal_length];
    double b = 1 / kernel * Math.sqrt(2 * Math.PI);
    int N = signal_length;

    for (int m = 0; m < signal_length; m++) {
        for (int n = m + 1; n < signal_length; n++) {
            double pow = Math.pow((signal[n] - signal[n - m - 1]), 2);
            double exp = Math.exp(-pow / twokSizeSquare);
            double equation = (1d / (N - m + 1d)) * b * exp;
            Y[m] = Y[m] + equation;
        }
    }
    return Y;
}