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:BillboardTest.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, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);/*from  w  w  w  .j a va2 s.co  m*/

    objTrans.addChild(createBillboard("AXIS - 0,1,0", new Point3f(-40.0f, 40.0f, 0.0f),
            Billboard.ROTATE_ABOUT_AXIS, new Point3f(0.0f, 1.0f, 0.0f), bounds));

    objTrans.addChild(createBillboard("POINT - 10,0,0", new Point3f(40.0f, 00.0f, 0.0f),
            Billboard.ROTATE_ABOUT_POINT, new Point3f(10.0f, 0.0f, 0.0f), bounds));

    objTrans.addChild(new ColorCube(20.0));

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:br.prof.salesfilho.oci.service.ImageDescriptorService.java

/**
 * @param image input image (signal)//from  www .  j  av  a 2 s .  c o  m
 * @param channel RGB and grayscale (1 = RED, 2 = GREEN, 3 = BLUE and 4 =
 * GRAYSCALE, diferent value GRAYSCALE is returned)
 * @param kernel Kernel size
 * @return AutoCorrentropy array
 */
public double[] autoCorrentropy(BufferedImage image, int channel, double kernel) {

    //Vetorization and normalization
    double[] signal = OCIUtils.vetorizeWithSpatialEntropySequence(this.getColorMatrix(image, channel));

    double twokSizeSquare = 2 * Math.pow(kernel, 2d);
    int signal_length = signal.length;
    double[] autoCorrentropy = 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;
            autoCorrentropy[m] = autoCorrentropy[m] + equation;
        }
    }
    return autoCorrentropy;
}

From source file:CompileTest.java

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

    // do NOT auto compute bounds for this node
    objRoot.setBoundsAutoCompute(false);

    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);/* w  w  w .  ja v  a  2  s .c  o m*/

    objTrans.addChild(createColorCubes());

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:House.java

public JSlider setSlider(JPanel panel, int orientation, int minimumValue, int maximumValue, int initValue,
        int majorTickSpacing, int minorTickSpacing) {
    JSlider slider = new JSlider(orientation, minimumValue, maximumValue, initValue);
    slider.setPaintTicks(true);/*from   www  .j  a va2 s  . c o m*/
    slider.setMajorTickSpacing(majorTickSpacing);
    slider.setMinorTickSpacing(minorTickSpacing);
    slider.setPaintLabels(true);
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider tempSlider = (JSlider) e.getSource();

            if (tempSlider.equals(sliderTransX)) {
                transX = sliderTransX.getValue() - 150.0;
                canvas.repaint();
            } else if (tempSlider.equals(sliderTransY)) {
                transY = sliderTransY.getValue() - 150.0;
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateTheta)) {
                rotateTheta = sliderRotateTheta.getValue() * Math.PI / 180;
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateX)) {
                rotateX = sliderRotateX.getValue();
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateY)) {
                rotateY = sliderRotateY.getValue();
                canvas.repaint();
            } else if (tempSlider.equals(sliderScaleX)) {
                if (sliderScaleX.getValue() != 0.0) {
                    scaleX = sliderScaleX.getValue() / 100.0;
                    canvas.repaint();
                }
            } else if (tempSlider.equals(sliderScaleY)) {
                if (sliderScaleY.getValue() != 0.0) {
                    scaleY = sliderScaleY.getValue() / 100.0;
                    canvas.repaint();
                }
            }
        }
    });
    panel.add(slider);

    return slider;
}

From source file:SimpleSphere.java

protected BranchGroup buildContentBranch() {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    //                rotateCube.set(new AxisAngle4d(1.0,0.0,0.0,Math.PI/2.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    Appearance app = new Appearance();
    Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    float shininess = 20.0f;
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app));
    addLights(contentBranch);//from   w ww  . j  ava  2 s .co  m
    return contentBranch;
}

From source file:info.raack.appliancedetection.evaluation.model.appliance.SineWaveDevice.java

protected int powerDrawAtOnCycleTimestep(int totalSeconds, int secondIndex, int globalTimestep) {
    return (int) (Math.sin((2 * Math.PI) * (float) secondIndex / wavelength) * maxAmplitude)
            + (int) Math.ceil(maxAmplitude);
}

From source file:ardufocuser.starfocusing.Utils.java

public static double computeFWHM_v1(int[][] image) {

    int npix = image.length * image[0].length;
    int pixel_value;
    double fwhm_value = 0.0;
    double x2_sum = 0;

    double mean = computeMean(image);

    for (int i = 0; i < image.length; i++) {
        for (int j = 0; j < image[0].length; j++) {
            pixel_value = image[i][j];//from   w w  w  .  j  a  va 2s.  co m
            x2_sum += pow((double) pixel_value - mean, 2);
        }
    }

    x2_sum /= (double) npix;
    fwhm_value = sqrt(x2_sum) * 2.3548;
    fwhm_value = sqrt(fwhm_value / Math.PI) * 2;

    return fwhm_value;
}

From source file:com.ccxt.whl.utils.CommonUtils.java

/**
 * ??(?)?/* w  w  w  .j  av a 2  s .  com*/
 * 
 * @param long1
 *            ?
 * @param lat1
 *            
 * @param long2
 *            ?
 * @param lat2
 *            
 * @return ? ??
 */
public static double Distance(double long1, double lat1, double long2, double lat2) {
    double a, b, R;
    R = 6378137; // ??
    lat1 = lat1 * Math.PI / 180.0;
    lat2 = lat2 * Math.PI / 180.0;
    a = lat1 - lat2;
    b = (long1 - long2) * Math.PI / 180.0;
    double d;
    double sa2, sb2;
    sa2 = Math.sin(a / 2.0);
    sb2 = Math.sin(b / 2.0);
    d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2));
    return d;
}

From source file:com.tc.object.ApplicatorDNAEncodingTest.java

public void testNonPrimitiveArrays() throws Exception {
    final TCByteBufferOutputStream output = new TCByteBufferOutputStream();

    final Object[] array = new Object[] { new ObjectID(12), new Integer(34), new Double(Math.PI),
            ObjectID.NULL_ID, new Long(Long.MIN_VALUE + 34), "timmy" };

    final DNAEncoding encoding = getApplicatorEncoding();
    encoding.encodeArray(array, output);

    final TCByteBufferInputStream input = new TCByteBufferInputStream(output.toArray());

    assertTrue(Arrays.equals(array, (Object[]) encoding.decode(input)));

    assertEquals(0, input.available());/*from  www  .ja  v  a2 s.co  m*/
}

From source file:com.opengamma.strata.math.impl.minimization.SumToOneTest.java

@Test
public void solverTest() {
    double[] w = new double[] { 0.01, 0.5, 0.3, 0.19 };
    final int n = w.length;
    final SumToOne trans = new SumToOne(n);
    Function<DoubleArray, DoubleArray> func = new Function<DoubleArray, DoubleArray>() {

        @Override/* ww  w.j a  v  a2  s  . c  om*/
        public DoubleArray apply(DoubleArray theta) {
            return trans.transform(theta);
        }
    };

    DoubleArray sigma = DoubleArray.filled(n, 1e-4);
    DoubleArray start = DoubleArray.filled(n - 1, 0.8);

    LeastSquareResults res = SOLVER.solve(DoubleArray.copyOf(w), sigma, func, start/*, maxJump*/);
    assertEquals("chi sqr", 0.0, res.getChiSq(), 1e-9);
    double[] fit = res.getFitParameters().toArray();
    double[] expected = trans.inverseTransform(w);
    for (int i = 0; i < n - 1; i++) {
        //put the fit result back in the range 0 - pi/2
        double x = fit[i];
        if (x < 0) {
            x = -x;
        }
        if (x > Math.PI / 2) {
            int p = (int) (x / Math.PI);
            x -= p * Math.PI;
            if (x > Math.PI / 2) {
                x = -x + Math.PI;
            }
        }

        assertEquals(expected[i], x, 1e-9);
    }

}