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

private void calcPi(double accuracy) throws InterruptedException {

    latestPiEstimate = 0.0;/*  w  ww.  j a  v a2  s  .c  o  m*/
    long iteration = 0;
    int sign = -1;

    while (Math.abs(latestPiEstimate - Math.PI) > accuracy) {

        if (Thread.interrupted()) {
            throw new InterruptedException();
        }

        iteration++;
        sign = -sign;
        latestPiEstimate += sign * 4.0 / ((2 * iteration) - 1);
    }
}

From source file:fsm.series.Series_SS.java

@Override
public double getFunctionValue(double y, int m) {

    return Math.sin(m * Math.PI * y / a);
}

From source file:Main.java

/************************************************************************************************************************************                                                              
  This routine calculates the distance between two points (given the    
  latitude/longitude of those points). It is being used to calculate     
  the distance between two locations//from w ww.jav a 2  s  . c o m
                                                                                     
  Definitions:                                                          
South latitudes are negative, east longitudes are positive           
                                                                                     
  Passed to function:                                                    
lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees)  
lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees)  
unit = the unit you desire for results                               
       where: 'M' is statute miles                                   
              'K' is kilometers (default)                            
              'N' is nautical miles                                 
                          
 *************************************************************************************************************************************/
public static double Distance(double lat1, double lon1, double lat2, double lon2, String unit) {
    double radius = 6371.0090667;
    lat1 = lat1 * Math.PI / 180.0;
    lon1 = lon1 * Math.PI / 180.0;
    lat2 = lat2 * Math.PI / 180.0;
    lon2 = lon2 * Math.PI / 180.0;
    double dlon = lon1 - lon2;

    double distance = Math
            .acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(dlon)) * radius;
    if (unit == "K") {
        return distance;
    } else if (unit == "M") {
        return (distance * 0.621371192);
    } else if (unit == "F") { //FEET
        return ((distance * 0.621371192) * 5280);
    } else if (unit == "N") {
        return (distance * 0.539956803);
    } else {
        return 0;
    }
}

From source file:Main.java

/**
 * Applies a gaussian blur of the given radius to the given {@link BufferedImage} using a kernel
 * convolution./*  ww w  .j av a 2s . c om*/
 *
 * @param source The source image.
 * @param radius The blur radius, in pixels.
 * @return A new, blurred image, or the source image if no blur is performed.
 */
public static BufferedImage blurredImage(BufferedImage source, double radius) {
    if (radius == 0) {
        return source;
    }

    final int r = (int) Math.ceil(radius);
    final int rows = r * 2 + 1;
    final float[] kernelData = new float[rows * rows];

    final double sigma = radius / 3;
    final double sigma22 = 2 * sigma * sigma;
    final double sqrtPiSigma22 = Math.sqrt(Math.PI * sigma22);
    final double radius2 = radius * radius;

    double total = 0;
    int index = 0;
    double distance2;

    int x, y;
    for (y = -r; y <= r; y++) {
        for (x = -r; x <= r; x++) {
            distance2 = 1.0 * x * x + 1.0 * y * y;
            if (distance2 > radius2) {
                kernelData[index] = 0;
            } else {
                kernelData[index] = (float) (Math.exp(-distance2 / sigma22) / sqrtPiSigma22);
            }
            total += kernelData[index];
            ++index;
        }
    }

    for (index = 0; index < kernelData.length; index++) {
        kernelData[index] /= total;
    }

    // We first pad the image so the kernel can operate at the edges.
    BufferedImage paddedSource = paddedImage(source, r);
    BufferedImage blurredPaddedImage = operatedImage(paddedSource,
            new ConvolveOp(new Kernel(rows, rows, kernelData), ConvolveOp.EDGE_ZERO_FILL, null));
    return blurredPaddedImage.getSubimage(r, r, source.getWidth(), source.getHeight());
}

From source file:SineDraw.java

public void setCycles(int newCycles) {
    cycles = newCycles;/*from  www.  j a v a  2s .c o m*/
    points = SCALEFACTOR * cycles * 2;
    sines = new double[points];
    for (int i = 0; i < points; i++) {
        double radians = (Math.PI / SCALEFACTOR) * i;
        sines[i] = Math.sin(radians);
    }
    repaint();
}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 6, -Math.PI / 6);

    g2.setTransform(at);//  w w  w  .  j a  v a  2s.c om
    g2.draw(shape);

}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 6);

    g2.setTransform(at);//w w  w  . jav  a 2 s .co m
    g2.draw(shape);

}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = AffineTransform.getRotateInstance(0.2, -Math.PI / 6, -Math.PI / 6);

    g2.setTransform(at);/*from  ww  w. j  a v a2 s. c o m*/
    g2.draw(shape);

}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = AffineTransform.getRotateInstance(0.2, 0.2, -Math.PI / 6, -Math.PI / 6);

    g2.setTransform(at);/* w w  w  . j  a  v a  2 s . co  m*/
    g2.draw(shape);

}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToScale(Math.PI / 6, Math.PI / 6);

    g2.setTransform(at);/*ww w .j a  v a2 s.c o m*/
    g2.draw(shape);

}