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

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Polygon p = new Polygon();
    for (int i = 0; i < 5; i++)
        p.addPoint((int) (100 + 50 * Math.cos(i * 2 * Math.PI / 5)),
                (int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5)));

    g.drawPolygon(p);/*  ww  w. ja  v a2 s.c o m*/

    Polygon s = new Polygon();
    for (int i = 0; i < 360; i++) {
        double t = i / 360.0;
        s.addPoint((int) (150 + 50 * t * Math.cos(8 * t * Math.PI)),
                (int) (150 + 50 * t * Math.sin(8 * t * Math.PI)));
    }
    g.drawPolygon(s);
}

From source file:FillPolyPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    int radius = 40;
    int centerX = 50;
    int centerY = 100;
    int angle = 30;

    int dx = (int) (radius * Math.cos(angle * Math.PI / 180));
    int dy = (int) (radius * Math.sin(angle * Math.PI / 180));

    g.fillArc(centerX - radius, centerY - radius, 2 * radius, 2 * radius, angle, 360 - 2 * angle);

    Polygon p = new Polygon();
    centerX = 150;//  w w  w  .  j  a v a 2s .  com
    for (int i = 0; i < 5; i++)
        p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)),
                (int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5)));

    g.fillPolygon(p);

    p = new Polygon();
    centerX = 250;
    for (int i = 0; i < 360; i++) {
        double t = i / 360.0;
        p.addPoint((int) (centerX + radius * t * Math.cos(8 * t * Math.PI)),
                (int) (centerY + radius * t * Math.sin(8 * t * Math.PI)));
    }
    g.fillPolygon(p);
}

From source file:AffineTransformGetRotateInstance.java

public void paint(Graphics g) {
    AffineTransform atrans = null;

    Graphics2D g2d = (Graphics2D) g;
    atrans = AffineTransform.getRotateInstance(Math.PI / 4, 50, 50);

    if (atrans != null)
        g2d.setTransform(atrans);// ww  w  .java 2  s . c  o  m

    g2d.fillRect(50, 50, 100, 50);
}

From source file:Main.java

/**
 * @return The tile index for the latitude at the given zoom
 */// w w w.  j a va  2s .co m
public static int toTileY(double lat, int zoom) {
    lat = 0.5 - ((Math.log(Math.tan((Math.PI / 4) + ((0.5 * Math.PI * lat) / 180))) / Math.PI) / 2.0);
    int scale = 1 << zoom;
    return (int) (lat * scale);
}

From source file:BasicDraw.java

public void paint(Graphics g) {

    Graphics2D g2d = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 4.0);
    g2d.setTransform(at);//w w  w  .  j  a v a  2  s  . com
    g2d.drawString("aString", 200, 100);

}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform tx = new AffineTransform();

    double radians = -Math.PI / 4;
    tx.rotate(radians);//  w  w  w . ja  va 2 s  .  co  m

    g2d.setTransform(tx);
    g2d.drawImage(new ImageIcon("a.png").getImage(), tx, this);
}

From source file:LisajousApp.Draw.java

private static XYDataset createDataset() {

    XYSeries s1 = new XYSeries("");

    for (double t = 0; t <= 2 * Math.PI; t = t + 0.0005) {
        double x = Main.a * Math.sin(Main.n * t + Main.c);
        double y = Main.b * Math.sin(t);
        s1.add(x, y);//w  w  w.  j a  v a2  s  . c om
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);
    return dataset;
}

From source file:code.elix_x.excore.utils.vecs.Vec3Utils.java

public static Vec3d getLook(float rotationYaw, float rotationPitch, float f, float prevRotationYaw,
        float prevRotationPitch) {
    float f1;/*from   www .j a  v a2s .  co  m*/
    float f2;
    float f3;
    float f4;

    if (f == 1.0F) {
        f1 = MathHelper.cos(-rotationYaw * 0.017453292F - (float) Math.PI);
        f2 = MathHelper.sin(-rotationYaw * 0.017453292F - (float) Math.PI);
        f3 = -MathHelper.cos(-rotationPitch * 0.017453292F);
        f4 = MathHelper.sin(-rotationPitch * 0.017453292F);
        return new Vec3d((double) (f2 * f3), (double) f4, (double) (f1 * f3));
    } else {
        f1 = prevRotationPitch + (rotationPitch - prevRotationPitch) * f;
        f2 = prevRotationYaw + (rotationYaw - prevRotationYaw) * f;
        f3 = MathHelper.cos(-f2 * 0.017453292F - (float) Math.PI);
        f4 = MathHelper.sin(-f2 * 0.017453292F - (float) Math.PI);
        float f5 = -MathHelper.cos(-f1 * 0.017453292F);
        float f6 = MathHelper.sin(-f1 * 0.017453292F);
        return new Vec3d((double) (f4 * f5), (double) f6, (double) (f3 * f5));
    }
}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;

    g2d.drawString("aString", 100, 100);
    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 4.0);
    g2d.setTransform(at);/*from  ww w. ja va 2 s. co  m*/
    g2d.drawString("aString", 100, 100);

}

From source file:SineFunctionPlotting.java

static int getNormalizedSine(int x, int halfY, int maxX) {
    double piDouble = 2 * Math.PI;
    double factor = piDouble / maxX;
    return (int) (Math.sin(x * factor) * halfY + halfY);
}