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

public static double cauchy(double u, double s) {
    double res = Math.random();
    double x = Math.tan(Math.PI * (res - 0.5));
    return u + s * x;
}

From source file:Main.java

/***
 * Fetch the raw estimated time enroute given the input parameters
 * @param distance - how far to the target
 * @param speed - how fast we are moving
 * @param bearing - direction to target//from w ww .  j a v  a  2  s  .co  m
 * @param heading - direction of movement
 * @return int value of HR * 100 + MIN for the ete, -1 if not applicable
 */
private static int fetchRawEte(double distance, double speed, double bearing, double heading) {
    // We can't assume that we are heading DIRECTLY for the destination, so 
    // we need to figure out the multiply factor by taking the COS of the difference
    // between the bearing and the heading.
    double angDif = angularDifference(heading, bearing);

    // If the difference is 90 or greater, then ETE means nothing as we are not
    // closing on the target
    if (angDif >= 90)
        return -1;

    // Calculate the actual relative speed closing on the target
    double xFactor = Math.cos(angDif * Math.PI / 180);
    double eteTotal = distance / (speed * xFactor);

    // Break that down into hours and minutes
    int eteHr = (int) eteTotal;
    int eteMin = (int) Math.round((eteTotal - (double) eteHr) * 60);

    // account for the minutes being 60
    if (eteMin >= 60) {
        eteHr++;
        eteMin -= 60;
    }

    // Return with our estimate
    return eteHr * 100 + eteMin;
}

From source file:PiInterrupt.java

public void run() {
    try {//from  w w  w.  jav a2 s  . c  o m
        System.out.println("for comparison, Math.PI=" + Math.PI);
        calcPi(0.000000001);
        System.out.println("within accuracy, latest pi=" + latestPiEstimate);
    } catch (InterruptedException x) {
        System.out.println("INTERRUPTED!! latest pi=" + latestPiEstimate);
    }
}

From source file:org.eclipse.swt.snippets.Snippet209.java

static void drawTorus(GL2 gl, float r, float R, int nsides, int rings) {
    float ringDelta = 2.0f * (float) Math.PI / rings;
    float sideDelta = 2.0f * (float) Math.PI / nsides;
    float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f;
    for (int i = rings - 1; i >= 0; i--) {
        float theta1 = theta + ringDelta;
        float cosTheta1 = (float) Math.cos(theta1);
        float sinTheta1 = (float) Math.sin(theta1);
        gl.glBegin(GL2.GL_QUAD_STRIP);/*  ww  w. ja v  a  2  s . c o m*/
        float phi = 0.0f;
        for (int j = nsides; j >= 0; j--) {
            phi += sideDelta;
            float cosPhi = (float) Math.cos(phi);
            float sinPhi = (float) Math.sin(phi);
            float dist = R + r * cosPhi;
            gl.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
            gl.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
            gl.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
            gl.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
        }
        gl.glEnd();
        theta = theta1;
        cosTheta = cosTheta1;
        sinTheta = sinTheta1;
    }
}

From source file:Main.java

@SuppressWarnings("unused")
public static int getMatrixRotateDegrees(Matrix matrix) {
    synchronized (MATRIX_VALUES) {
        matrix.getValues(MATRIX_VALUES);
        final float skewX = MATRIX_VALUES[Matrix.MSKEW_X];
        final float scaleX = MATRIX_VALUES[Matrix.MSCALE_X];
        //noinspection SuspiciousNameCombination
        final int degrees = (int) Math.round(Math.atan2(skewX, scaleX) * (180 / Math.PI));
        if (degrees < 0) {
            return Math.abs(degrees);
        } else if (degrees > 0) {
            return 360 - degrees;
        } else {/*from   ww w  .j a v a2s  .  co m*/
            return 0;
        }
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform at = new AffineTransform();
    at.setToRotation(-Math.PI / 2.0, getWidth() / 2.0, getHeight() / 2.0);
    g2d.setTransform(at);//from   w ww.java2  s  .  c o  m
    g2d.drawString("Vertical text", 10, 10);
}

From source file:Main.java

public void paint(Graphics g) {
    g.fillRect(0, 0, 20, 20);/*from   w w w .ja  va  2s.  c o m*/

    Graphics2D g2 = (Graphics2D) g;

    g2.translate(50, 50);
    g2.rotate(30.0 * Math.PI / 180.0, 13, 12);

    g2.scale(2.0, 2.0);

    g.setColor(Color.red);

    g.fillRect(0, 0, 20, 20);
}

From source file:Main.java

private static float transformAngle(Matrix m, float angleRadians) {
    // Construct and transform a vector oriented at the specified clockwise
    // angle from vertical.  Coordinate system: down is increasing Y, right is
    // increasing X.
    float[] v = new float[2];
    v[0] = (float) Math.sin(angleRadians);
    v[1] = (float) Math.cos(angleRadians);
    m.mapVectors(v);//from   w w  w  .j  av a2  s .com
    // Derive the transformed vector's clockwise angle from vertical.
    float result = (float) Math.atan2(v[0], -v[1]);
    if (result < -Math.PI / 2) {
        result += Math.PI;
    } else if (result > Math.PI / 2) {
        result -= Math.PI;
    }
    return result;
}

From source file:org.eclipse.swt.snippets.Snippet195.java

static void drawTorus(float r, float R, int nsides, int rings) {
    float ringDelta = 2.0f * (float) Math.PI / rings;
    float sideDelta = 2.0f * (float) Math.PI / nsides;
    float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f;
    for (int i = rings - 1; i >= 0; i--) {
        float theta1 = theta + ringDelta;
        float cosTheta1 = (float) Math.cos(theta1);
        float sinTheta1 = (float) Math.sin(theta1);
        GL11.glBegin(GL11.GL_QUAD_STRIP);
        float phi = 0.0f;
        for (int j = nsides; j >= 0; j--) {
            phi += sideDelta;//from   ww  w . j  av  a  2 s.c o m
            float cosPhi = (float) Math.cos(phi);
            float sinPhi = (float) Math.sin(phi);
            float dist = R + r * cosPhi;
            GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
            GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
            GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
            GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
        }
        GL11.glEnd();
        theta = theta1;
        cosTheta = cosTheta1;
        sinTheta = sinTheta1;
    }
}

From source file:MainClass.java

public void paint(Graphics g) {

    g.fillRect(0, 0, 20, 20);// w  w  w  .j  av  a 2  s.  c  o m

    Graphics2D g2 = (Graphics2D) g;

    g2.translate(50, 50);
    g2.rotate(30.0 * Math.PI / 180.0);

    g2.scale(2.0, 2.0);

    g.setColor(Color.red);

    g.fillRect(0, 0, 20, 20);

}