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:ceptraj.tool.Bearing.java

public static double bearing(Point p1, Point p2) {
    double bearing = 0;
    if (p1 != null && p2 != null) {

        switch (ConfigProvider.getSpaceType()) {
        case lat_lon:
            //In case of lat-lon space
            double p1LatRad = Math.toRadians(p1.getLat());
            double p2LatRad = Math.toRadians(p2.getLat());

            double p1LonRad = Math.toRadians(p1.getLon());
            double p2LonRad = Math.toRadians(p2.getLon());

            bearing = (Math/* w  w w.  j a  va2  s.c o m*/
                    .toDegrees((Math.atan2(Math.sin(p2LonRad - p1LonRad) * Math.cos(p2LatRad),
                            Math.cos(p1LatRad) * Math.sin(p2LatRad)
                                    - Math.sin(p1LatRad) * Math.cos(p2LatRad) * Math.cos(p2LonRad - p1LonRad))))
                    + 360) % 360;
            break;
        case cartesian:
            //In case of cartesian space
            double dy = p2.y - p1.y;
            double dx = p2.x - p1.x;
            bearing = 90 - (180 / Math.PI) * Math.atan2(dy, dx);
            if (bearing < 0) {
                bearing += 360;
            }
            break;
        }
    }

    return bearing;
}

From source file:electrical_parameters.Rac_calculation.java

private double EIR(double rho, double D, double f) {
    double delta;
    Complex x;//from   www. j a v a  2s  . c o  m
    Complex y = new Complex(1, -1);
    Complex a;
    Complex b;

    delta = 503.3 * sqrt(rho / f);
    x = y.multiply(D).divide(2 * delta);
    a = y.multiply(rho).divide(D * Math.PI * delta);
    b = Bessel_0(x).divide(Bessel_1(x));

    //        System.out.println("delta");
    //        System.out.println(delta);
    //        System.out.println("x");
    //        System.out.println(x);
    //        System.out.println("EIR");
    //        System.out.println(a.multiply(b).getReal());

    return a.multiply(b).getReal();
}

From source file:Clock.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Color colorRetainer = g.getColor();

    g.setColor(getBackground());//from w w  w  .j  a v  a2 s .com
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    calendar.setTime(new Date()); // get current time
    int hrs = calendar.get(Calendar.HOUR_OF_DAY);
    int min = calendar.get(Calendar.MINUTE);

    g.setColor(getForeground());
    if (isDigital) {
        String time = "" + hrs + ":" + min;
        g.setFont(getFont());
        FontMetrics fm = g.getFontMetrics();
        int y = (getHeight() + fm.getAscent()) / 2;
        int x = (getWidth() - fm.stringWidth(time)) / 2;
        g.drawString(time, x, y);
    } else {
        int x = getWidth() / 2;
        int y = getHeight() / 2;
        int rh = getHeight() / 4;
        int rm = getHeight() / 3;

        double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI;
        double am = min / 30.0 * Math.PI;

        g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah)));
        g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am)));
    }

    g.setColor(colorRetainer);
}

From source file:com.mergano.core.AreaChart.java

private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createAreaChart("Order statistic", // chart title
            "Days", // domain axis label
            "Order Average", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips
            false // urls
    );/* w w w  .j  a v a 2 s  .  com*/

    // 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);
    chart.setAntiAlias(true);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.getRenderer().setSeriesPaint(0, new Color(0, 191, 165));
    plot.setForegroundAlpha(0.75f);
    plot.setBackgroundPaint(Color.white);

    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); // disable this
    plot.setDomainGridlinesVisible(false);
    plot.setDomainGridlinePaint(new Color(240, 240, 240));
    plot.setRangeGridlinesVisible(false);
    plot.setRangeGridlinePaint(new Color(240, 240, 240));
    plot.setDomainCrosshairPaint(Color.MAGENTA);
    plot.setRangeCrosshairPaint(Color.CYAN);

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

/**
 * This creates some lights and adds them to the BranchGroup.
 * //from   w  ww.  j  a  v  a2s .  c  o  m
 * @param b
 *            BranchGroup that the lights are added to.
 */
protected void addLights(BranchGroup b) {
    // Create a bounds for the lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    //Set up the ambient light
    Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f);
    AmbientLight ambientLight = new AmbientLight(ambientColour);
    ambientLight.setInfluencingBounds(bounds);
    Color3f blueColour = new Color3f(0.0f, 0.0f, 1.0f);
    Point3f bluePosition = new Point3f(1.8f, 1.8f, 1.8f);
    Point3f blueAtten = new Point3f(1.0f, 0.0f, 0.0f);
    Vector3f blueDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    SpotLight blueLight = new SpotLight(blueColour, bluePosition, blueAtten, blueDir, (float) (Math.PI / 2.0),
            0.0f);
    blueLight.setInfluencingBounds(bounds);
    Color3f greenColour = new Color3f(0.0f, 1.0f, 0.0f);
    Point3f greenPosition = new Point3f(0.0f, 0.0f, 3.0f);
    Point3f greenAtten = new Point3f(1.0f, 0.0f, 0.0f);
    Vector3f greenDir = new Vector3f(0.0f, 0.0f, -1.0f);
    SpotLight greenLight = new SpotLight(greenColour, greenPosition, greenAtten, greenDir,
            (float) (Math.PI / 2.0), 0.0f);
    greenLight.setInfluencingBounds(bounds);
    //Add the lights to the BranchGroup
    b.addChild(ambientLight);
    b.addChild(greenLight);
    b.addChild(blueLight);
}

From source file:ArrowIcon.java

protected Image getArrowImage() {
    if (arrowImage == null) {
        arrowImage = createTranslucentImage(size, size);
        AffineTransform atx = direction != SOUTH ? new AffineTransform() : null;
        switch (direction) {
        case NORTH:
            atx.setToRotation(Math.PI, size / 2, size / 2);
            break;
        case EAST:
            atx.setToRotation(-(Math.PI / 2), size / 2, size / 2);
            break;
        case WEST:
            atx.setToRotation(Math.PI / 2, size / 2, size / 2);
        case SOUTH:
        default: {
            /* no xform*/ }
        }// ww  w. j  a va2  s.  c om
        Graphics2D ig = (Graphics2D) arrowImage.getGraphics();
        if (atx != null) {
            ig.setTransform(atx);
        }
        int width = size;
        int height = size / 2 + 1;
        int xx = (size - width) / 2;
        int yy = (size - height + 1) / 2;

        Color base = color != null ? color : UIManager.getColor("controlDkShadow").darker();

        paintArrow(ig, base, xx, yy);
        paintArrowBevel(ig, base, xx, yy);
        paintArrowBevel(ig, deriveColorHSB(base, 0f, 0f, .20f), xx, yy + 1);
    }
    return arrowImage;
}

From source file:com.wattzap.view.graphs.DistributionGraph.java

public DistributionGraph(ArrayList<Telemetry> telemetry[], DistributionAccessor da, String domainLabel,
        int scale) {
    super();//from  w  w w. ja  v a2  s .c  o  m

    this.telemetry = telemetry;
    this.da = da;

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("", domainLabel, // domain
            // axis
            // label
            "Time %", // range axis label
            null, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    plot = (CategoryPlot) chart.getPlot();

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.gray, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    // OPTIONAL CUSTOMISATION COMPLETED.

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(100, 800);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);

    BucketPanel bucketPanel = new BucketPanel(this, scale);
    add(bucketPanel, BorderLayout.SOUTH);

    setBackground(Color.black);
    chartPanel.revalidate();
    setVisible(true);
}

From source file:datavis.BarGraph.java

public JFreeChart getChartPanel() {
    JFreeChart chart = ChartFactory.createBarChart(getBarGraphName(), getIntervalTypeName(),
            getNumberTypeName(), getBarGraph(), PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.darkGray);
    plot.setDomainGridlinePaint(new Color(240, 180, 180));
    plot.setRangeGridlinePaint(new Color(240, 180, 180));

    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardBarPainter());

    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, new Color(170, 240, 240), 0.0f, 0.0f,
            new Color(170, 240, 240));

    renderer.setSeriesPaint(0, gp0);/*w w  w  .  j a v  a  2 s  .  c o m*/

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    return chart;
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java

protected double mixed(double[] x, int A, double alpha) {
    double tmp = 2.0 * A * Math.PI;
    return correct_to_01(Math.pow(1.0 - x[0] - Math.cos(tmp * x[0] + Math.PI / 2.0) / tmp, alpha), EPSILON);
}

From source file:se.trillian.goodies.spring.DomainObjectFactoryFactoryBeanTest.java

public void testCreateFactoryConstructor3() throws Exception {
    ListableBeanFactory beanFactory = (ListableBeanFactory) mock(ListableBeanFactory.class);
    beanFactory.getBeansOfType(C.class);
    Map<String, Object> beans = new HashMap<String, Object>();
    beans.put("c", new C());
    modify().returnValue(beans);/* w w  w  . ja  va2  s .co m*/

    startVerification();

    factoryBean.afterPropertiesSet();
    factoryBean.setBeanFactory(beanFactory);
    Interface.Factory factory = (Interface.Factory) factoryBean.getObject();
    Implementation impl = (Implementation) factory.create(Math.PI);
    assertEquals(Math.PI, impl.u);
    assertThat(impl.dependency, is.instanceOf(C.class));
}