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:com.rapidminer.gui.plotter.charts.BarChart3DPlotter.java

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

    JFreeChart chart = ChartFactory.createBarChart3D(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
    );/*from w ww.  j  a v a2 s  .  co  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;
}

From source file:OffScreenTest.java

public BranchGroup createSceneGraph(Raster drawRaster) {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // spin object has composited transformation matrix
    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 4.0d);
    tempspin.rotY(Math.PI / 5.0d);
    spin.mul(tempspin);/*from w  ww  .java 2  s.  c o  m*/
    spin.setScale(0.7);
    spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0));

    TransformGroup objTrans = new TransformGroup(spin);
    objRoot.addChild(objTrans);

    // Create a simple shape leaf node, add it to the scene graph.
    // ColorCube is a Convenience Utility class
    objTrans.addChild(new ColorCube(0.4));

    //Create a raster
    Shape3D shape = new Shape3D(drawRaster);
    objRoot.addChild(shape);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

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

@Test
public void testDriving() throws FileNotFoundException {
    Random rand = new Random(3);
    GeoPoint start = new GeoPoint((rand.nextDouble() - 0.5) * Math.PI / 2, rand.nextDouble() * Math.PI * 2);
    GeoPoint end = start.nearby(10, rand);

    final Vector3D east = start.east();
    final Vector3D north = start.north(east);
    try (PrintWriter out = new PrintWriter(new File("drive-sim.csv"))) {
        out.printf("i, t, x, y, rpm, throttle, speed, gear");
        for (int i = 0; i < 50; i++) {
            final int trial = i;
            double t = 0;
            Car car = new Car();

            List<Car.Segment> plan = Car.plan(start, end, rand);
            assertTrue(plan.size() < 20);
            final GeoPoint currentPosition = new GeoPoint(start.as3D());
            for (Car.Segment segment : plan) {
                t = car.simulate(t, currentPosition, rand, segment, new Car.Callback() {
                    @Override/*from   ww w  .jav  a2  s .com*/
                    void call(double t, Engine arg, GeoPoint position) {
                        final Vector3D here = project(east, north, currentPosition.as3D());
                        Engine engine = car.getEngine();
                        out.printf("%d, %.2f, %.2f, %.2f, %.1f, %.1f, %.1f, %d\n", trial, t, here.getX(),
                                here.getY(), engine.getRpm(), engine.getThrottle(), engine.getSpeed(),
                                engine.getGear());
                    }
                });
                assertEquals(0, currentPosition.distance(segment.getEnd()), 0.04);
            }

            // should arrive at our destination!
            assertEquals(0.0, currentPosition.distance(end), 0.01);
        }
    }
}

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

public void initialize() {
    Dimension d = getSize();/*from   w w  w  .j ava  2  s. co m*/

    if (d != null) {
        if (vertex_ordered_list == null)
            setVertexOrder(new ArrayList<V>(getGraph().getVertices()));

        double height = d.getHeight();
        double width = d.getWidth();

        if (radius <= 0) {
            radius = 0.45 * (height < width ? height : width);
        }

        int i = 0;
        for (V v : vertex_ordered_list) {
            Point2D coord = transform(v);

            double angle = (2 * Math.PI * i) / vertex_ordered_list.size();

            coord.setLocation(Math.cos(angle) * radius + width / 2, Math.sin(angle) * radius + height / 2);

            CircleVertexData data = getCircleData(v);
            data.setAngle(angle);
            i++;
        }
    }
}

From source file:hivemall.utils.math.StatsUtils.java

/**
 * pdf(x, x_hat) = exp(-0.5 * (x-x_hat) * inv() * (x-x_hat)T) / ( 2^0.5d * det()^0.5)
 * //from w w w  .j  ava2s.  c  o  m
 * @return value of probabilistic density function
 * @link https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Density_function
 */
public static double pdf(@Nonnull final RealVector x, @Nonnull final RealVector x_hat,
        @Nonnull final RealMatrix sigma) {
    final int dim = x.getDimension();
    Preconditions.checkArgument(x_hat.getDimension() == dim,
            "|x| != |x_hat|, |x|=" + dim + ", |x_hat|=" + x_hat.getDimension());
    Preconditions.checkArgument(sigma.getRowDimension() == dim,
            "|x| != |sigma|, |x|=" + dim + ", |sigma|=" + sigma.getRowDimension());
    Preconditions.checkArgument(sigma.isSquare(), "Sigma is not square matrix");

    LUDecomposition LU = new LUDecomposition(sigma);
    final double detSigma = LU.getDeterminant();
    double denominator = Math.pow(2.d * Math.PI, 0.5d * dim) * Math.pow(detSigma, 0.5d);
    if (denominator == 0.d) { // avoid divide by zero
        return 0.d;
    }

    final RealMatrix invSigma;
    DecompositionSolver solver = LU.getSolver();
    if (solver.isNonSingular() == false) {
        SingularValueDecomposition svd = new SingularValueDecomposition(sigma);
        invSigma = svd.getSolver().getInverse(); // least square solution
    } else {
        invSigma = solver.getInverse();
    }
    //EigenDecomposition eigen = new EigenDecomposition(sigma);
    //double detSigma = eigen.getDeterminant();
    //RealMatrix invSigma = eigen.getSolver().getInverse();

    RealVector diff = x.subtract(x_hat);
    RealVector premultiplied = invSigma.preMultiply(diff);
    double sum = premultiplied.dotProduct(diff);
    double numerator = Math.exp(-0.5d * sum);

    return numerator / denominator;
}

From source file:com.kiyoshi.gui.AreaChart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );// w w  w.j a  va 2s.  c  o  m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //      legend.setAnchor(StandardLegend.SOUTH);
    chart.setBackgroundPaint(Color.white);
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(0.5f);

    //      plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.addCategoryLabelToolTip("Type 1", "The first type.");
    domainAxis.addCategoryLabelToolTip("Type 2", "The second type.");
    domainAxis.addCategoryLabelToolTip("Type 3", "The third type.");

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelAngle(0 * Math.PI / 2.0);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:Sampler.java

private void createTransformations() {
    AffineTransform at;//from  ww w  .  j  av  a 2  s  .  c o  m
    at = AffineTransform.getRotateInstance(Math.PI / 6, 0, 285);
    mOps.put("Rotate nearest neighbor", new AffineTransformOp(at, null));

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    mOps.put("Rotate bilinear", new AffineTransformOp(at, rh));

    at = AffineTransform.getScaleInstance(.5, .5);
    mOps.put("Scale .5, .5", new AffineTransformOp(at, null));

    at = AffineTransform.getRotateInstance(Math.PI / 6);
    mOps.put("Rotate bilinear (origin)", new AffineTransformOp(at, rh));
}

From source file:org.jfree.graphics2d.demo.ImageTest.java

private static void drawArcTest(Graphics2D g2) {
    g2.setPaint(Color.GREEN);// w w w . jav  a2s  .  c  om
    g2.drawRect(0, 20, 70, 50);
    g2.setPaint(Color.RED);
    Path2D path1 = new Path2D.Double();
    double[] pts = calculateReferenceArc(90);
    path1.moveTo(pts[0], pts[1]);
    path1.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]);
    AffineTransform t = new AffineTransform();
    t.translate(35, 45);
    t.scale(35, 25);
    t.rotate(Math.PI / 4);
    path1.transform(t);
    g2.draw(path1);

    Path2D path2 = new Path2D.Double();
    path2.moveTo(pts[0], pts[1]);
    path2.curveTo(pts[2], pts[3], pts[4], pts[5], pts[6], pts[7]);
    AffineTransform t2 = new AffineTransform();
    t2.rotate(3 * Math.PI / 4);
    t2.scale(35, 25);
    t2.translate(35, 35);
    path2.transform(t2);
    //g2.draw(path2);
    Path2D arc = new Path2D.Double();
    arc.append(path1, false);
    arc.append(path2, false);
    //g2.draw(arc);
    //g2.draw(path1);
    //g2.transform(t);
    g2.setPaint(Color.BLUE);
    g2.drawArc(0, 20, 70, 50, 0, -270);
    //Arc2D arc2d = new Arc2D.Double(0d, 20d, 70d, 50d, 0d, 90, Arc2D.OPEN);
    //g2.draw(arc2d);
}

From source file:CircleLayoutDemo.java

/**
 * Arranges the parent's Component objects in either an Ellipse or a Circle.
 * Ellipse is not yet implemented.//from www. java  2s.co  m
 */
public void layoutContainer(Container parent) {
    int x, y, w, h, s, c;
    int n = parent.getComponentCount();
    double parentWidth = parent.getSize().width;
    double parentHeight = parent.getSize().height;
    Insets insets = parent.getInsets();
    int centerX = (int) (parentWidth - (insets.left + insets.right)) / 2;
    int centerY = (int) (parentHeight - (insets.top + insets.bottom)) / 2;

    Component comp = null;
    Dimension compPS = null;
    if (n == 1) {
        comp = parent.getComponent(0);
        x = centerX;
        y = centerY;
        compPS = comp.getPreferredSize();
        w = compPS.width;
        h = compPS.height;
        comp.setBounds(x, y, w, h);
    } else {
        double r = (Math.min(parentWidth - (insets.left + insets.right),
                parentHeight - (insets.top + insets.bottom))) / 2;
        r *= 0.75; // Multiply by .75 to account for extreme right and bottom
                   // Components
        for (int i = 0; i < n; i++) {
            comp = parent.getComponent(i);
            compPS = comp.getPreferredSize();
            if (isCircle) {
                c = (int) (r * Math.cos(2 * i * Math.PI / n));
                s = (int) (r * Math.sin(2 * i * Math.PI / n));
            } else {
                c = (int) ((centerX * 0.75) * Math.cos(2 * i * Math.PI / n));
                s = (int) ((centerY * 0.75) * Math.sin(2 * i * Math.PI / n));
            }
            x = c + centerX;
            y = s + centerY;

            w = compPS.width;
            h = compPS.height;

            comp.setBounds(x, y, w, h);
        }
    }

}

From source file:contactangle.ImageControl.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (img != null)
        g.drawImage(img, 0, 0, this);
    else/*w ww .  ja  va2s .co m*/
        g.drawString("NO IMAGE", 0, 15);

    g.setColor(Color.RED);

    if (x1 < x2 && y1 < y2)
        g.drawRect(x1, y1, x2 - x1, y2 - y1);
    else if (x1 >= x2 && y1 < y2)
        g.drawRect(x2, y1, x1 - x2, y2 - y1);
    else if (x1 < x2 && y1 >= y2)
        g.drawRect(x1, y2, x2 - x1, y1 - y2);
    else
        g.drawRect(x2, y2, x1 - x2, y1 - y2);

    if (valid && img != null) {

        if (x1 >= x2) {
            int temp = x1;
            x1 = x2;
            x2 = temp;
        }
        if (y1 >= y2) {
            int temp = y1;
            y1 = y2;
            y2 = temp;
        }

        choosenPoints = new ArrayList<Point>();
        for (int y = y1; y < y2; y++) {
            for (int x = x1; x < x2; x++) {
                int pixelData = img.getRGB(x, y);
                if (pixelData == -1)
                    choosenPoints.add(new Point(x, y));
            }
        }

        SimpleRegression reg = new SimpleRegression();
        for (Point p : choosenPoints) {
            reg.addData(p.x, p.y);
        }

        int firstX = choosenPoints.get(0).x;
        int firstY = choosenPoints.get(0).y;
        double slope = reg.getSlope();
        g.setColor(Color.GREEN);
        g.drawLine(firstX, firstY, firstX + (70), firstY + (int) (slope * (70)));
        g.drawLine(firstX, firstY, firstX - (70), firstY - (int) (slope * (70)));

        double contactDegrees = (Math.atan(reg.getSlope()) / (2 * Math.PI)) * 360.0;

        DecimalFormat d = new DecimalFormat("##.###");

        g.drawString("Contact Angle = ", 25, 25);
        g.drawString(d.format(contactDegrees) + " degrees", 25, 38);
    }

}