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

/**
 * This builds the content branch of our scene graph. The root of the shapes
 * supplied as a parameter is slightly tilted to reveal its 3D shape. It
 * also uses the addLights function to add some lights to the scene. The
 * group that the shape is added to has its capabilities set so that we can
 * read and write it./*from ww  w.  ja va 2  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));
    rotationGroup = new TransformGroup(rotateCube);
    //Set the capabilities so that the transform can be accessed
    rotationGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    rotationGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    contentBranch.addChild(rotationGroup);
    rotationGroup.addChild(shape);
    addLights(contentBranch);
    return contentBranch;
}

From source file:com.alvermont.terraj.planet.project.PetersProjection.java

/**
 * Carry out the projection/*  w  w w  . j  ava2  s  .c om*/
 */
public void project() {
    setcolours();

    final int width = getParameters().getProjectionParameters().getWidth();
    final int height = getParameters().getProjectionParameters().getHeight();

    final double lat = getParameters().getProjectionParameters().getLatitudeRadians();
    final double lon = getParameters().getProjectionParameters().getLongitudeRadians();

    final double scale = getParameters().getProjectionParameters().getScale();

    final double hgrid = getParameters().getProjectionParameters().getHgrid();
    final double vgrid = getParameters().getProjectionParameters().getVgrid();

    final boolean doShade = getParameters().getProjectionParameters().isDoShade();

    cacheParameters();

    colours = new short[width][height];
    shades = new short[width][height];

    depth = (3 * ((int) (log2(scale * height)))) + 6;

    double y;
    double cos2;
    double theta1;
    double scale1;
    int k;
    int i;
    int j;
    int water;
    int land;

    y = 2.0 * Math.sin(lat);
    k = (int) ((0.5 * y * width * scale) / Math.PI);

    water = 0;
    land = 0;

    progress.progressStart(height, "Generating Terrain");

    for (j = 0; j < height; ++j) {
        progress.progressStep(j);

        y = (0.5 * Math.PI * ((2.0 * (j - k)) - height)) / width / scale;

        if (Math.abs(y) > 1.0) {
            for (i = 0; i < width; ++i) {
                colours[i][j] = backgroundColour;

                if (doShade) {
                    shades[i][j] = 255;
                }
            }
        } else {
            cos2 = Math.sqrt(1.0 - (y * y));

            if (cos2 > 0.0) {
                scale1 = (scale * width) / height / cos2 / Math.PI;

                depth = (3 * ((int) (log2(scale1 * height)))) + 3;

                for (i = 0; i < width; ++i) {
                    theta1 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * i) - width)) / width / scale);

                    colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2);

                    if (doShade) {
                        shades[i][j] = shade;
                    }

                    if (colours[i][j] < colourLand0) {
                        ++water;
                    } else {
                        ++land;
                    }
                }
            }
        }
    }

    progress.progressComplete("Terrain Generated");

    log.debug("Water percentage: " + ((100 * water) / (water + land)));

    if (hgrid != 0.0) {
        /* draw horizontal gridlines */
        for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid)
            ;

        for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) {
            y = 2.0 * Math.sin(Math.toRadians(theta1));
            j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k;

            if ((j >= 0) && (j < height)) {
                for (i = 0; i < width; ++i)
                    colours[i][j] = BLACK;
            }
        }
    }

    if (vgrid != 0.0) {
        /* draw vertical gridlines */
        for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid)
            ;

        for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) {
            i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI)));

            if ((i >= 0) && (i < width)) {
                for (j = Math.max(0, (height / 2) - (int) ((width * scale) / Math.PI) + k); j < Math.min(height,
                        (height / 2) + (int) ((width * scale) / Math.PI) + k); ++j)
                    colours[i][j] = BLACK;
            }
        }
    }

    if (doShade) {
        smoothshades();
    }

    doOutlining();
}

From source file:FPSCounterDemo.java

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

   // Create the TransformGroup node and initialize it to the
   // identity. Enable the TRANSFORM_WRITE capability so that
   // our behavior code can modify it at run time. Add it to
   // the root of the subgraph.
   TransformGroup objTrans = new TransformGroup();
   objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
   objRoot.addChild(objTrans);//from  ww  w .  j ava 2  s .co m

   // Create a simple Shape3D node; add it to the scene graph.
   objTrans.addChild(new ColorCube(0.4));

   // Create a new Behavior object that will perform the
   // desired operation on the specified transform and add
   // it into the scene graph.
   Transform3D yAxis = new Transform3D();
   Alpha rotationAlpha = new Alpha(-1, 4000);

   RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
         objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
   BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
         100.0);
   rotator.setSchedulingBounds(bounds);
   objRoot.addChild(rotator);

   // Create the Framecounter behavior
   fpsCounter.setSchedulingBounds(bounds);
   objRoot.addChild(fpsCounter);

   return objRoot;
}

From source file:net.sf.dynamicreports.test.jasper.chart.StackedAreaChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);// w ww. j  ava2  s .  com

    JFreeChart chart = getChart("summary.chart1", 0);
    Axis axis = chart.getCategoryPlot().getDomainAxis();
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    Assert.assertEquals("renderer", StackedAreaRenderer.class, categoryPlot.getRenderer().getClass());
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    CategoryLabelPosition labelPosition = chart.getCategoryPlot().getDomainAxis().getCategoryLabelPositions()
            .getLabelPosition(RectangleEdge.LEFT);
    Assert.assertEquals("plot label rotation", (45d / 180) * Math.PI, labelPosition.getAngle());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart2", 0);
    axis = chart.getCategoryPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
}

From source file:BackgroundGeometry.java

public BranchGroup createSceneGraph() {

    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);//from  w w w. j  a  v a 2 s  .  co m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup objTrans = new TransformGroup();
    objScale.addChild(objTrans);

    Background bg = new Background();
    bg.setApplicationBounds(bounds);
    BranchGroup backGeoBranch = new BranchGroup();
    Sphere sphereObj = new Sphere(1.0f,
            Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45);
    Appearance backgroundApp = sphereObj.getAppearance();
    backGeoBranch.addChild(sphereObj);
    bg.setGeometry(backGeoBranch);
    objTrans.addChild(bg);

    TextureLoader tex = new TextureLoader(bgImage, new String("RGB"), this);
    if (tex != null)
        backgroundApp.setTexture(tex.getTexture());

    Vector3f tranlation = new Vector3f(2.0f, 0.0f, 0.0f);
    Transform3D modelTransform = new Transform3D();
    Transform3D tmpTransform = new Transform3D();
    double angleInc = Math.PI / 8.0;
    double angle = 0.0;
    int numBoxes = 16;

    float scaleX[] = { 0.1f, 0.2f, 0.2f, 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f,
            0.3f };

    float scaleY[] = { 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f,
            0.4f };

    float scaleZ[] = { 0.3f, 0.2f, 0.1f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f,
            0.2f };

    Appearance a1 = new Appearance();
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(0.5f, 0.5f, 1.0f);
    Color3f oColor = new Color3f(0.5f, 0.5f, 0.3f);

    Material m = new Material(oColor, eColor, oColor, sColor, 100.0f);
    m.setLightingEnable(true);
    a1.setMaterial(m);

    for (int i = 0; i < numBoxes; i++, angle += angleInc) {
        modelTransform.rotY(angle);
        tmpTransform.set(tranlation);
        modelTransform.mul(tmpTransform);

        TransformGroup tgroup = new TransformGroup(modelTransform);
        objTrans.addChild(tgroup);

        tgroup.addChild(new Box(scaleX[i], scaleY[i], scaleZ[i], Box.GENERATE_NORMALS, a1));
    }

    // Shine it with two lights.
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    return objRoot;
}

From source file:com.alvermont.terraj.planet.project.SinusoidProjection.java

/**
 * Carry out the projection/*www  .ja  va 2  s  .  c  o  m*/
 */
public void project() {
    setcolours();

    final int width = getParameters().getProjectionParameters().getWidth();
    final int height = getParameters().getProjectionParameters().getHeight();

    final double lat = getParameters().getProjectionParameters().getLatitudeRadians();
    final double lon = getParameters().getProjectionParameters().getLongitudeRadians();

    final double scale = getParameters().getProjectionParameters().getScale();

    final double hgrid = getParameters().getProjectionParameters().getHgrid();
    final double vgrid = getParameters().getProjectionParameters().getVgrid();

    final boolean doShade = getParameters().getProjectionParameters().isDoShade();

    cacheParameters();

    colours = new short[width][height];
    shades = new short[width][height];

    double y;
    double theta1;
    double theta2;
    double cos2;
    double l1;
    double i1;
    double scale1;
    int k;
    int i;
    int j;
    int l;
    int c;

    k = (int) ((lat * width * scale) / Math.PI);

    progress.progressStart(height, "Generating Terrain");

    for (j = 0; j < height; ++j) {
        progress.progressStep(j);

        y = ((2.0 * (j - k)) - height) / width / scale * Math.PI;

        if (Math.abs(y) >= (0.5 * Math.PI)) {
            for (i = 0; i < width; ++i) {
                colours[i][j] = backgroundColour;

                if (doShade) {
                    shades[i][j] = 255;
                }
            }
        } else {
            cos2 = Math.cos(y);

            if (cos2 > 0.0) {
                scale1 = (scale * width) / height / cos2 / Math.PI;

                depth = (3 * ((int) (log2(scale1 * height)))) + 3;

                for (i = 0; i < width; ++i) {
                    l = (i * 12) / width;
                    l1 = (l * width) / 12.0;
                    i1 = i - l1;

                    theta2 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * l1) - width)) / width / scale);
                    theta1 = ((Math.PI * ((2.0 * i1) - (width / 12))) / width / scale) / cos2;

                    if (Math.abs(theta1) > (Math.PI / 12.0)) {
                        colours[i][j] = backgroundColour;

                        if (doShade) {
                            shades[i][j] = 255;
                        }
                    } else {
                        colours[i][j] = (short) planet0(Math.cos(theta1 + theta2) * cos2, Math.sin(y),
                                -Math.sin(theta1 + theta2) * cos2);

                        if (doShade) {
                            shades[i][j] = shade;
                        }
                    }
                }
            }
        }
    }

    progress.progressComplete("Terrain Generated");

    if (hgrid != 0.0) {
        /* draw horizontal gridlines */
        for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid)
            ;

        for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) {
            y = Math.toRadians(theta1);

            cos2 = Math.cos(y);

            j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k;

            if ((j >= 0) && (j < height)) {
                for (i = 0; i < width; ++i) {
                    l = (i * 12) / width;
                    l1 = (l * width) / 12.0;
                    i1 = i - l1;

                    theta2 = ((Math.PI * ((2.0 * i1) - (width / 12))) / width / scale) / cos2;

                    if (Math.abs(theta2) <= (Math.PI / 12.0)) {
                        colours[i][j] = BLACK;
                    }
                }
            }
        }
    }

    if (vgrid != 0.0) {
        /* draw vertical gridlines */
        for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid)
            ;

        for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) {
            i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI)));

            if ((i >= 0) && (i < width)) {
                for (j = Math.max(0,
                        (height / 2) - (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); j < Math.min(
                                height,
                                (height / 2) + (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); ++j) {
                    y = ((2.0 * (j - k)) - height) / width / scale * Math.PI;
                    cos2 = Math.cos(y);

                    l = (i * 12) / width;
                    l1 = ((l * width) / 12.0) + (width / 24.0);
                    i1 = i - l1;
                    c = (int) (l1 + (i1 * cos2));

                    if ((c >= 0) && (c < width)) {
                        colours[c][j] = BLACK;
                    }
                }
            }
        }
    }

    if (doShade) {
        smoothshades();
    }

    doOutlining();
}

From source file:SimpleIndexedQuadSmooth.java

/**
 * This builds the content branch of our scene graph. It uses the buildShape
 * function to create the actual shape, adding to to the transform group so
 * that the shape is slightly tilted to reveal its 3D shape. It also uses
 * the addLights function to add some lights to the scene.
 * /*from   w  w w.  j av  a 2 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);
    addLights(contentBranch);
    return contentBranch;
}

From source file:ScenegraphTest.java

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

    // create some lights for the scene
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(createApplicationBounds());
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(createApplicationBounds());
    objRoot.addChild(aLgt);//from  ww w .j  a va2  s  .  c  o  m
    objRoot.addChild(lgt1);

    // create a rotator to spin the whole model around the Y axis
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

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

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(createApplicationBounds());
    objTrans.addChild(rotator);

    // build the model itself using helper methods
    addHead(objTrans);
    objTrans.addChild(createArm(0, 0, -Math.PI * 0.5));
    objTrans.addChild(createArm(0, Math.PI, Math.PI * 0.5));

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:es.ucm.fdi.ac.outlier.Hampel.java

/**
 * Ugly lookup of 'k' given alpha. Alpha must be either 0.01 or 0.05
 * for this to work as expected.// w ww .j a va  2s  .com
 */
private static double analyticK(int n, double alpha) {
    double k;
    double logN = Math.log(n);
    double sqrtTwoLogN = Math.sqrt(2 * logN);
    double z_n_alpha = sqrtTwoLogN - Math.log(alpha / 2) / sqrtTwoLogN
            - (Math.log(logN) + Math.log(4 * Math.PI)) / (2 * sqrtTwoLogN);

    if (alpha == 0.05) {
        if ((n % 2) == 0) {//N even
            k = 1.483 * z_n_alpha + 21.61 * Math.pow(n + 1, -0.8655);
        } else {
            k = 1.483 * z_n_alpha + 14.43 * Math.pow(n - 3, -0.7939);
        }

        return k;

    } else if (alpha == 0.01) {
        if ((n % 2) == 0) {//N even
            k = 1.483 * z_n_alpha + 41.39 * Math.pow(n, -0.9143);
        } else {
            k = 1.483 * z_n_alpha + 24.48 * Math.pow(n - 5, -0.8236);
        }

        return k;
    } else {
        return Double.NaN;
        //            throw new IllegalArgumentException(
        //                    "Alpha IS RESTRICTED to be 0.01 or 0.05 ");
    }
}