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:SimpleWire.java

/**
 * This builds the content branch of our scene graph. It uses the buildCube
 * function to create the actual shape, adding to to the transform group so
 * that the shape is slightly tilted to reveal its 3D shape.
 * /* w  ww  . jav a2 s.c o  m*/
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch(Node shape) {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    rotationGroup.addChild(shape);
    return contentBranch;
}

From source file:TransformTransRotation.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);/* w  w  w .  j  av a2 s  .  c o m*/

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    AffineTransform rat = new AffineTransform();
    rat.setToTranslation(100, 0);
    rat.rotate(Math.PI / 6);
    g2.transform(rat);

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:jtrace.object.Sphere.java

@Override
public List<Vector3D[]> getWireFrameObjectFrame() {
    List<Vector3D[]> edgeList = new ArrayList<>();

    int nLongitudeLines = 50;
    int nLongitudeSteps = 20;

    for (int i = 0; i < nLongitudeLines; i++) {
        double theta = 2 * Math.PI * i / nLongitudeLines;
        for (int j = 0; j < nLongitudeSteps; j++) {
            double phi = Math.PI * j / nLongitudeSteps;
            double phiNext = Math.PI * (j + 1) / nLongitudeSteps;

            Vector3D p = new Vector3D(Math.sin(phi) * Math.cos(theta), Math.sin(phi) * Math.sin(theta),
                    Math.cos(phi));

            Vector3D pNext = new Vector3D(Math.sin(phiNext) * Math.cos(theta),
                    Math.sin(phiNext) * Math.sin(theta), Math.cos(phiNext));

            Vector3D[] edge = { p, pNext };
            edgeList.add(edge);/*w  w  w  . ja  v  a 2s.c  o m*/
        }
    }

    return edgeList;
}

From source file:copter.MPU9150.java

private List<Double> readAccel() {

    try {//from  w  ww.j  av  a 2s . co  m
        accelData = new byte[6];
        //gyroData = new byte[6];

        //You can read one registry at a time,
        //or you can read multiple consecutive ones, 
        //in our case we are reading 6 consecutive registries
        //from 0x3B, meaning we are reading all the 
        //accelerometer measurements
        int r = device.read(0x3B, accelData, 0, 6);
        if (r != 6) {
            //System.out.println("Error reading accel data, < 6 bytes");
        }
        //Convert the values to integers, using the
        //helper method asInt
        int accelX = ((int) (accelData[0] / 4));
        int accelY = ((int) (accelData[2] / 4));
        int accelZ = ((int) (accelData[4] / 4));
        double Ax = Math.atan(accelX / Math.sqrt(accelY * accelY + accelZ * accelZ)) * 180 / Math.PI;
        double Ay = Math.atan(accelY / Math.sqrt(accelX * accelX + accelZ * accelZ)) * 180 / Math.PI;
        double Az = Math.atan(accelZ / Math.sqrt(accelX * accelX + accelY * accelY)) * 180 / Math.PI;
        List<Double> ret = new ArrayList<>();
        Ax = Math.round(Ax);
        Ay = Math.round(Ay);
        Az = Math.round(Az);
        ret.add(Ax);
        ret.add(Ay);
        ret.add(Az);
        return ret;
    } catch (IOException ex) {
        Logger.getLogger(MPU9150.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCategoricalCorrelationPlot.java

private void createChart() {

    String title = "Categorical Plot";

    CategoryDataset chartData = createChartData();

    CategoryAxis domainAxis = new CategoryAxis(null);
    NumberAxis rangeAxis = new NumberAxis(yLabel);
    //BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();

    BoxAndWhiskerCoinPlotRenderer renderer = new BoxAndWhiskerCoinPlotRenderer();
    renderer.setDisplayAllOutliers(true);
    CategoryPlot plot = new CategoryPlot(chartData, domainAxis, rangeAxis, renderer);

    domainAxis.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(45.0 * Math.PI / 180.0));
    catCorrChart = new JFreeChart(title, plot);
    catCorrChart.removeLegend();//from   ww  w  .j  a v  a  2 s .c om
    //renderer.setFillBox(false);
    String cat = (String) chartData.getColumnKey(0);

    //renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    renderer.setToolTipGenerator(new CategoryToolTipGenerator() {
        public String generateToolTip(CategoryDataset dataset, int series, int item) {
            String tt = "";
            NumberFormat formatter = new DecimalFormat(".####");
            String key = "";
            //String s = formatter.format(-1234.567);  // -001235
            if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) {
                DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset;
                try {
                    String med = formatter.format(ds.getMedianValue(series, item));
                    tt += "Median: " + med + "<br/>";
                    tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>";
                    tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>";
                    tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>";
                    tt += "Max: "
                            + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item))
                            + "<br/>";
                    tt += "Min: "
                            + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item))
                            + "<br/>";
                    //tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>";
                    //tt += "X: " + ds.getValue(series, item).toString()+"<br/>";
                    //tt += "<br/><a href=\\\'#\\\' id=\\\'"+ds.getRowKeys().get(series)+"\\\' onclick=\\\'alert(this.id);return false;\\\'>"+ds.getRowKeys().get(series)+" plot</a><br/><br/>";
                    key = ds.getRowKeys().get(series).toString();
                } catch (Exception e) {
                }
            }

            return tt;
        }

    });

    //        renderer.setToolTipGenerator(new CategoryToolTipGenerator() {
    //           
    //         public String generateToolTip(CategoryDataset dataset,int series, int item) {
    //            String tt="";
    //            NumberFormat formatter = new DecimalFormat(".####");
    //            String key = "";
    //             //String s = formatter.format(-1234.567);  // -001235
    //            StringBuffer sb = new StringBuffer();
    //             if(dataset instanceof DefaultBoxAndWhiskerCategoryDataset){
    //                DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset)dataset;
    //                try   {
    //                   
    //                   String str;
    //                   str = (String) ds.getColumnKey(item);
    //                   sb.append(str).append(" N=");
    //                   BoxAndWhiskerItem bwitem = ds.getItem(series,item);
    //                   
    //                  str = formatter.format(ds.getMedianValue(series, item));
    //                  sb.append("Median: ").append(str);
    //                  str = formatter.format(ds.getMeanValue(series, item));
    //                  sb.append(" Mean: ").append(str);
    //                  str = formatter.format(ds.getMinRegularValue(series, item));
    //                  sb.append(" Min: ").append(str);
    //                  str = formatter.format(ds.getMaxRegularValue(series, item));
    //                  sb.append(" Max: ").append(str);
    //                  str = formatter.format(ds.getQ1Value(series, item));
    //                  sb.append(" Q1: ").append(str);   
    //                  str = formatter.format(ds.getQ3Value(series, item));
    //                  sb.append(" Q3: ").append(str);
    //                  
    //                }
    //                catch(Exception e) {}
    //             }
    //             
    //            return sb.toString();
    //            
    //         }
    //
    //      });

    plot.setNoDataMessage(null);
}

From source file:com.qaant.optionModels.QWhaley.java

private void wWhaley() {

    pModelName = "Whaley QAANT";
    modelNumber = 2;// w  w w .ja  v a 2s  . com
    tipoEjercicio = AMERICAN;

    //     q=(tipoContrato==STOCK) ? dividendRate:rate; 
    //q: si es una accion q es el dividendo, si es un futuro q se toma la rate para descontar el valor futr a presente 
    //Se hace este reemplazo para poder usar la misma form en STOCK y FUTURO

    double xx;

    switch (tipoContrato) {
    case STOCK:
        q = dividendRate;
        b = rate;
        break;

    case FUTURES:
        q = rate;
        b = 0;
        break;
    }
    double vlt2 = volatModel * volatModel;
    double VltSqrDayYear = volatModel * sqrDayYear;
    double h = 1 - z; //descuento para valor presente

    double alfa = 2 * rate / vlt2;
    double beta = 2 * (b - q) / vlt2;

    double lambda = (-(beta - 1) + cpFlag * Math.sqrt((beta - 1) * (beta - 1) + 4 * alfa / h)) / 2;

    double eex = Math.exp(-q * dayYear);//descuento por dividendos

    double s1 = strike;
    double zz = 1 / Math.sqrt(2 * Math.PI);
    double zerror = 1;
    do {
        double d1 = (Math.log(s1 / strike) + ((rate - q) + vlt2 / 2) * dayYear) / VltSqrDayYear;
        xx = (1 - eex * new NormalDistribution().cumulativeProbability(cpFlag * d1));

        double corr = s1 / lambda * xx;

        QBlackScholes option = new QBlackScholes(tipoContrato, s1, volatModel, dividendRate, callPut, strike,
                daysToExpiration, rate, 0);

        double mBlackScholes = option.getPrima();
        double rhs = mBlackScholes + cpFlag * corr;

        double lhs = cpFlag * (s1 - strike);
        zerror = lhs - rhs;
        double nd1 = zz * Math.exp(-0.5 * d1 * d1); //standard normal prob?
        double slope = cpFlag * (1 - 1 / lambda) * xx + 1 / lambda * (eex * nd1) * 1 / VltSqrDayYear;
        s1 = s1 - zerror / slope;

    } while (Math.abs(zerror) > 0.000001);

    double a = cpFlag * s1 / lambda * xx;

    switch (callPut) {
    case CALL: //Call
        if (underlyingValue >= s1) {
            prima = underlyingValue - strike;
        } else {
            prima += a * Math.pow((underlyingValue / s1), lambda);
        }
        break;

    case PUT: //Put
        if (underlyingValue <= s1) {
            prima = strike - underlyingValue;
        } else {
            prima += a * Math.pow((underlyingValue / s1), lambda);
        }
        //prima=10.1;
        break;
    }
}

From source file:Estadistica.java

/**
 * Metodo calcular el valor f/*from   ww  w . j  av  a 2  s  .  c  om*/
 * param  dos valores double x y dof
 * @return el valor f
 */
public static double f(double x, double dof) {
    double cal = 0;
    cal = Math.pow((1 + x * x / dof), -(dof + 1) / 2) * gamma((dof + 1) / 2);
    cal = cal / (Math.sqrt(dof * Math.PI) * gamma(dof / 2));
    return cal;
}

From source file:com.mapr.synth.drive.GeoPoint.java

public ObjectNode asJson(ObjectNode node) {
    node.set("latitude", nodeFactory.numberNode(180 / Math.PI * Math.asin(r.getZ())));
    node.set("longitude", nodeFactory.numberNode(180 / Math.PI * Math.atan2(r.getY(), r.getX())));
    return node;/*from w w w.j  a v  a2s. c  om*/
}

From source file:com.v2soft.misto.Providers.MapnikProvider.java

@Override
public TileInfo getTileInfoByLocation(Location location, int zoom) {
    TileInfo res = new TileInfo();
    res.setHeight(TILE_SIZE);//w w  w .  j av  a2  s.c  om
    res.setWidth(TILE_SIZE);
    res.setZoom(zoom);
    res.setLatitude((int) Math.floor((1 - Math.log(Math.tan(location.getLatitude() * Math.PI / 180)
            + 1 / Math.cos(location.getLatitude() * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom)));
    double longitude = Math.floor((location.getLongitude() + 180) * worldTilesCount(zoom) / 360);
    res.setLongitude((int) longitude);
    return res;
}

From source file:com.rapidminer.gui.plotter.charts.BarChart2DPlotter.java

public JFreeChart createChart(CategoryDataset categoryDataSet, String groupByName, String valueName,
        boolean createLegend) {

    JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            groupByName, // domain axis label
            valueName, // range axis label
            categoryDataSet, // data
            PlotOrientation.VERTICAL, // orientation
            ((createLegend) && (groupByName != null)), // include legend if group by column is set
            true, // tooltips
            false // URLs
    );/*ww w .j a v a 2  s  .  c o  m*/

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(230, 230, 230));
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set up paints for series
    if (groupByName == null) {
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, SwingTools.LIGHT_BLUE);
        renderer.setSeriesPaint(1, SwingTools.LIGHT_YELLOW);
    }

    // domain axis labels
    CategoryAxis domainAxis = plot.getDomainAxis();
    if (groupByName == null) {
        domainAxis.setTickLabelsVisible(true);
        domainAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    } else {
        domainAxis.setTickLabelsVisible(false);
    }

    return chart;
}