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.bc.jexp.impl.DefaultNamespace.java

private void registerDefaultSymbols() {
    registerSymbol(SymbolFactory.createConstant("PI", Math.PI));
    registerSymbol(SymbolFactory.createConstant("E", Math.E));
    registerSymbol(SymbolFactory.createConstant("NaN", Double.NaN));
}

From source file:bg.elkabel.calculator.service.CoreServiceImpl.java

private double calculateWeight(Material material, double coreSize) {
    double result = 0.0;
    switch (material.ordinal()) {
    case 0:/*from  w w  w  .  j av a2 s .c  o m*/
        result = Math.pow(coreSize, 2) * Math.PI / 4 * 2.7 * 1 / 1000;
        break;
    case 1:
        result = Math.pow(coreSize, 2) * Math.PI / 4 * 8.9 * 1 / 1000;
        break;
    }

    return BigDecimal.valueOf(result).setScale(6, RoundingMode.HALF_UP).doubleValue();
}

From source file:beast.math.distributions.NormalDistribution.java

/**
 * the natural log of the probability density function of the distribution
 *
 * @param x  argument//from   ww w.ja va2  s . c o  m
 * @param m  mean
 * @param sd standard deviation
 * @return log pdf at x
 */
public static double logPdf(double x, double m, double sd) {
    double a = 1.0 / (Math.sqrt(2.0 * Math.PI) * sd);
    double b = -(x - m) * (x - m) / (2.0 * sd * sd);

    return Math.log(a) + b;
}

From source file:beast.math.distributions.NormalGamma.java

@Override
public double calcLogP(Function fun) {
    if (fun.getDimension() != 2) {
        throw new IllegalArgumentException("Argument to calcLogP has the wrong dimension (should be 2)");
    }/* w  ww. ja  v a2s .  co  m*/

    double mu = getMu();
    double lambda = getLambda();
    double alpha = getAlpha();
    double beta = getBeta();

    double x = fun.getArrayValue(0);
    double tau = fun.getArrayValue(1);

    return alpha * Math.log(beta) + 0.5 * Math.log(lambda) + (alpha - 0.5) * Math.log(tau) - beta * tau
            - lambda * tau * Math.pow(x - mu, 2) / 2 - GammaFunction.lnGamma(alpha)
            - 0.5 * Math.log(2 * Math.PI);
}

From source file:mase.app.playground.Playground.java

protected void placeAgent(SmartAgent ag) {
    // leave at least half robot of distance to the boundaries
    Double2D pos = new Double2D(par.radius * 2 + (random.nextDouble() * (par.arenaSize - par.radius * 4)),
            par.radius * 2 + (random.nextDouble() * (par.arenaSize - par.radius * 4)));
    ag.setLocation(pos);//from   www.ja v a2  s  .c  o m
    ag.setOrientation(-Math.PI + random.nextDouble() * Math.PI * 2);
}

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

protected void setPolars(List<V> kids, Point2D parentLocation, double parentRadius) {

    int childCount = kids.size();
    if (childCount == 0)
        return;//w w w .j a  v a2 s .co m
    // handle the 1-child case with 0 limit on angle.
    double angle = Math.max(0, Math.PI / 2 * (1 - 2.0 / childCount));
    double childRadius = parentRadius * Math.cos(angle) / (1 + Math.cos(angle));
    double radius = parentRadius - childRadius;

    double rand = Math.random();

    for (int i = 0; i < childCount; i++) {
        V child = kids.get(i);
        double theta = i * 2 * Math.PI / childCount + rand;
        radii.put(child, childRadius);

        PolarPoint pp = new PolarPoint(theta, radius);
        polarLocations.put(child, pp);

        Point2D p = PolarPoint.polarToCartesian(pp);
        p.setLocation(p.getX() + parentLocation.getX(), p.getY() + parentLocation.getY());
        locations.put(child, p);
        setPolars(new ArrayList<V>(graph.getChildren(child)), p, childRadius);
    }
}

From source file:com.dianping.imcaptcha.strategy.WaveFilter.java

public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();
    int type = src.getType();
    WritableRaster srcRaster = src.getRaster();

    originalSpace = new Rectangle(0, 0, width, height);
    transformedSpace = new Rectangle(0, 0, width, height);
    transformSpace(transformedSpace);//from   w w w. j  a v a  2s  .  c o m

    if (dst == null) {
        ColorModel dstCM = src.getColorModel();
        dst = new BufferedImage(dstCM,
                dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height),
                dstCM.isAlphaPremultiplied(), null);
    }
    WritableRaster dstRaster = dst.getRaster();

    int[] inPixels = getRGB(src, 0, 0, width, height, null);

    if (interpolation == NEAREST_NEIGHBOUR)
        return filterPixelsNN(dst, width, height, inPixels, transformedSpace);

    int srcWidth = width;
    int srcHeight = height;
    int srcWidth1 = width - 1;
    int srcHeight1 = height - 1;
    int outWidth = transformedSpace.width;
    int outHeight = transformedSpace.height;
    int outX, outY;
    int index = 0;
    int[] outPixels = new int[outWidth];
    float radius = srcHeight * 1.0f / 2 / (float) Math.PI;
    outX = transformedSpace.x;
    outY = transformedSpace.y;
    float[] out = new float[2];

    for (int y = 0; y < outHeight; y++) {
        for (int x = 0; x < outWidth; x++) {
            transformInverse(outX + x, outY + y, out, radius);
            int srcX = (int) Math.floor(out[0]);
            int srcY = (int) Math.floor(out[1]);
            float xWeight = out[0] - srcX;
            float yWeight = out[1] - srcY;
            int nw, ne, sw, se;

            if (srcX >= 0 && srcX < srcWidth1 && srcY >= 0 && srcY < srcHeight1) {
                // Easy case, all corners are in the image
                int i = srcWidth * srcY + srcX;
                nw = inPixels[i];
                ne = inPixels[i + 1];
                sw = inPixels[i + srcWidth];
                se = inPixels[i + srcWidth + 1];
            } else {
                // Some of the corners are off the image
                nw = getPixel(inPixels, srcX, srcY, srcWidth, srcHeight);
                ne = getPixel(inPixels, srcX + 1, srcY, srcWidth, srcHeight);
                sw = getPixel(inPixels, srcX, srcY + 1, srcWidth, srcHeight);
                se = getPixel(inPixels, srcX + 1, srcY + 1, srcWidth, srcHeight);
            }
            outPixels[x] = ImageMath.bilinearInterpolate(xWeight, yWeight, nw, ne, sw, se);
        }
        setRGB(dst, 0, y, transformedSpace.width, 1, outPixels);
    }
    return dst;
}

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

@Test
public void inverseTransformTest() {
    for (int n = 2; n < 13; n++) {
        double[] theta = new double[n - 1];
        for (int j = 0; j < n - 1; j++) {
            theta[j] = RANDOM.nextDouble() * Math.PI / 2;
        }//from  w  w w  . j a v a  2 s.  c  o m
        SumToOne trans = new SumToOne(n);
        DoubleArray w = trans.transform(DoubleArray.copyOf(theta));

        DoubleArray theta2 = trans.inverseTransform(w);
        for (int j = 0; j < n - 1; j++) {
            assertEquals("element " + j + ", of vector length " + n, theta[j], theta2.get(j), 1e-9);
        }
    }
}

From source file:ws.moor.bt.gui.charts.TotalBlocksPerPeer.java

private JFreeChart createChart() {

    JFreeChart chart = ChartFactory.createStackedBarChart("Top 20 Block Peers", "Remote IP", "Blocks",
            createDataset(), PlotOrientation.VERTICAL, true, false, false);
    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

    return chart;
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz3.S_Dtlz3_Objective.java

@Override
public double evaluate(double[] x) {

    int nx = x.length;

    int i = 0;/*from   w  ww .j a  v  a2s  .co  m*/
    int j = 0;
    int k = nx - numberOfObjectives + 1;
    double g = 0;

    double[] z = new double[nx];
    double[] zz = new double[nx];
    double[] p = new double[nx];
    double[] psum = new double[numberOfObjectives];

    // denormalize vector:
    for (i = 0; i < nx; i++) {
        x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2;
    }

    for (i = 0; i < nx; i++) {
        z[i] = x[i] - o[i];

        if (z[i] < 0) {
            zz[i] = -lambda[i] * z[i];
            p[i] = -z[i] / d[i];
        } else {
            zz[i] = z[i];
            p[i] = 0;
        }
    }

    for (j = 0; j < numberOfObjectives; j++) {
        psum[j] = 0;
    }

    for (i = nx - k + 1; i <= nx; i++) {
        g += Math.pow(zz[i - 1] - 0.5, 2) - Math.cos(20 * Math.PI * (zz[i - 1] - 0.5));
        for (j = 0; j < numberOfObjectives; j++) {
            psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2));
        }
    }

    g = 100 * (k + g);

    double ff = (1 + g);

    for (j = numberOfObjectives - objNumber; j >= 1; j--) {
        ff *= Math.cos(zz[j - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2));
    }

    if (objNumber > 1) {
        ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(
                Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2));
    }

    return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1);

}