List of usage examples for java.lang Math PI
double PI
To view the source code for java.lang Math PI.
Click Source Link
From source file:TrigonometricDemo.java
public static void main(String[] args) { double degrees = 45.0; double radians = Math.toRadians(degrees); System.out.println("The value of pi is " + Math.PI); System.out.println("The sine of " + degrees + " is " + Math.sin(radians)); System.out.println("The cosine of " + degrees + " is " + Math.cos(radians)); System.out.println("The tangent of " + degrees + " is " + Math.tan(radians)); System.out.println("The arc sine of " + Math.sin(radians) + " is " + Math.toDegrees(Math.asin(Math.sin(radians))) + " degrees"); System.out.println("The arc cosine of " + Math.cos(radians) + " is " + Math.toDegrees(Math.acos(Math.cos(radians))) + " degrees"); System.out.println("The arc tangent of " + Math.tan(radians) + " is " + Math.toDegrees(Math.atan(Math.tan(radians))) + " degrees"); }
From source file:Rotate45Degrees.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font);// w ww .ja v a2s. com gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("SWT", 10, 10, true); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAdvanced(true); if (!gc.getAdvanced()) { gc.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc.drawImage(image, x, y); x += rect.width + 30; Transform transform = new Transform(display); // Rotate by 45 degrees //float cos45 = (float)Math.cos(45); float cos45 = (float) Math.cos(Math.PI / 4); //float sin45 = (float)Math.sin(45); float sin45 = (float) Math.sin(Math.PI / 4); transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); gc.setTransform(transform); gc.drawImage(image, 350, 100); transform.dispose(); } }); shell.setSize(350, 550); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:DataTypePrintTest.java
public static void main(String[] args) { Thread objectData = new Thread(); String stringData = "Java Mania"; char[] charArrayData = { 'a', 'b', 'c' }; int integerData = 4; long longData = Long.MIN_VALUE; float floatData = Float.MAX_VALUE; double doubleData = Math.PI; boolean booleanData = true; System.out.println(objectData); System.out.println(stringData); System.out.println(charArrayData); System.out.println(integerData); System.out.println(longData); System.out.println(floatData); System.out.println(doubleData); System.out.println(booleanData); }
From source file:org.jfree.graphics2d.demo.BufferedImageDemo.java
/** * Starting point for the demo./*ww w.j a v a2s .c om*/ * * @param args ignored. * * @throws IOException */ public static void main(String[] args) throws IOException { BufferedImage image = new BufferedImage(600, 400, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); ImageIcon icon = new ImageIcon(BufferedImageDemo.class.getResource("jfree_chart_1.jpg")); g2.rotate(Math.PI / 12); g2.setStroke(new BasicStroke(2.0f)); g2.setPaint(Color.WHITE); g2.fill(new Rectangle(0, 0, 600, 400)); g2.setPaint(Color.RED); g2.draw(new Rectangle(0, 0, 600, 400)); g2.drawImage(icon.getImage(), 10, 20, null); ImageIO.write(image, "png", new File("image-test.png")); }
From source file:net.liuxuan.temp.filterTest.java
public static void main(String[] args) { double constantVoltage = 10d; double measurementNoise = 0.1d; double processNoise = 1e-5d; // A = [ 1 ]/* w w w.j a v a2 s . c o m*/ RealMatrix A = new Array2DRowRealMatrix(new double[] { 1d }); // B = null RealMatrix B = null; // H = [ 1 ] RealMatrix H = new Array2DRowRealMatrix(new double[] { 1d }); // x = [ 10 ] RealVector x = new ArrayRealVector(new double[] { constantVoltage }); // Q = [ 1e-5 ] RealMatrix Q = new Array2DRowRealMatrix(new double[] { processNoise }); // P = [ 1 ] RealMatrix P0 = new Array2DRowRealMatrix(new double[] { 1d }); // R = [ 0.1 ] RealMatrix R = new Array2DRowRealMatrix(new double[] { measurementNoise }); ProcessModel pm = new DefaultProcessModel(A, B, Q, x, P0); MeasurementModel mm = new DefaultMeasurementModel(H, R); KalmanFilter filter = new KalmanFilter(pm, mm); // process and measurement noise vectors RealVector pNoise = new ArrayRealVector(1); RealVector mNoise = new ArrayRealVector(1); RandomGenerator rand = new JDKRandomGenerator(); // iterate 60 steps for (int i = 0; i < 60; i++) { filter.predict(); // simulate the process // pNoise.setEntry(0, processNoise * rand.nextGaussian()); pNoise.setEntry(0, Math.sin(Math.PI * 2 * i / 6)); // System.out.println("============"); // System.out.println(Math.sin(Math.PI*2*i/6)); // x = A * x + p_noise x = A.operate(x).add(pNoise); // simulate the measurement // mNoise.setEntry(0, measurementNoise * rand.nextGaussian()); mNoise.setEntry(0, 0); // z = H * x + m_noise RealVector z = H.operate(x).add(mNoise); filter.correct(z); double voltage = filter.getStateEstimation()[0]; System.out.println(voltage); // state estimate shouldn't be larger than the measurement noise double diff = Math.abs(x.getEntry(0) - filter.getStateEstimation()[0]); System.out.println("diff = " + diff); } }
From source file:jtrace.scenes.JustAPlane.java
public static void main(String[] args) throws IOException { Scene scene = new Scene(); //scene.setBackground(Colour.cyan.mix(0.8, Colour.white)); Camera camera = new Camera(new Vector3D(0, -3, 1), new Vector3D(0, 0, 0), Vector3D.PLUS_K, 1.0, 1440.0 / 900.0);/*from www .j ava2 s . c o m*/ scene.setCamera(camera); LightSource light = new LightSource(new Vector3D(-3, -3, 3), 4); scene.addLightSource(light); FlatTexture floorTexture = new FlatTexture(new ImagePigment(new File("wood.jpg"), 1.0)); floorTexture.addFinish(new DiffuseFinish(1.0)); floorTexture.addFinish(new AmbientFinish(0.1)); Plane plane = new Plane(); plane.addTexture(floorTexture); plane.addTransformation(new Scale(2, 1, 1)); // plane.addTransformation(new Rotation(Vector3D.PLUS_K, Math.PI/16)); plane.addTransformation(new Rotation(Vector3D.PLUS_J, Math.PI / 16)); // plane.addTransformation(new Translation(0,-0.5,0)); scene.addObject(plane); BufferedImage image = scene.renderWireFrame(1440, 900, 10); ImageIO.write(image, "PNG", new File("out.png")); }
From source file:jtrace.scenes.OneCubeAnimate.java
public static void main(String[] args) throws IOException { Scene scene = new Scene(); scene.addLightSource(new LightSource(new Vector3D(-3, 3, -3), 4)); scene.addLightSource(new LightSource(new Vector3D(6, 6, -3), 4)); FlatTexture cubeTexture = (new FlatTexture(new SolidPigment(new Colour(0, 0, 1)))); cubeTexture.addFinish(new DiffuseFinish(1.0)); cubeTexture.addFinish(new AmbientFinish(0.1)); cubeTexture.addFinish(new MirrorFinish(0.2)); Cube cube = new Cube(new Vector3D(0, 0, 0), 0.5); cube.addTexture(cubeTexture);/*from w ww . j a v a 2 s . c om*/ scene.addObject(cube); // FlatTexture floorTexture = new FlatTexture(new CheckeredPigment( // new Colour(.5,.5,.5), new Colour(1,1,1), 1)); FlatTexture floorTexture = new FlatTexture(new ImagePigment(new File("wood.jpg"), 1.0)); floorTexture.addFinish(new DiffuseFinish(1.0)); Plane plane = new Plane(new Vector3D(0, -0.25, 0), Vector3D.PLUS_J, Vector3D.PLUS_K); plane.addTexture(floorTexture); scene.addObject(plane); Vector3D pointAt = new Vector3D(0, 0, 0); int steps = 100; for (int i = 0; i < steps; i++) { double R = 2.0; double x = R * Math.sin(i * 2 * Math.PI / steps); double z = -R * Math.cos(i * 2 * Math.PI / steps); Camera camera = new Camera(new Vector3D(x, 1, z), pointAt, Vector3D.PLUS_J, 1.0, 800.0 / 600.0); scene.setCamera(camera); BufferedImage image = scene.render(800, 600, 10); ImageIO.write(image, "PNG", new File(String.format("out_%02d.png", i))); } }
From source file:org.eclipse.swt.snippets.Snippet207.java
public static void main(String[] args) { final Display display = new Display(); final Image image = new Image(display, 110, 60); GC gc = new GC(image); Font font = new Font(display, "Times", 30, SWT.BOLD); gc.setFont(font);/*w w w . j a v a 2 s . co m*/ gc.setBackground(display.getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, 110, 60); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); gc.drawText("SWT", 10, 10, true); font.dispose(); gc.dispose(); final Rectangle rect = image.getBounds(); Shell shell = new Shell(display); shell.setText("Matrix Tranformations"); shell.setLayout(new FillLayout()); final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED); canvas.addPaintListener(e -> { GC gc1 = e.gc; gc1.setAdvanced(true); if (!gc1.getAdvanced()) { gc1.drawText("Advanced graphics not supported", 30, 30, true); return; } // Original image int x = 30, y = 30; gc1.drawImage(image, x, y); x += rect.width + 30; Transform transform = new Transform(display); // Note that the tranform is applied to the whole GC therefore // the coordinates need to be adjusted too. // Reflect around the y axis. transform.setElements(-1, 0, 0, 1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, -1 * x - rect.width, y); x = 30; y += rect.height + 30; // Reflect around the x axis. transform.setElements(1, 0, 0, -1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, x, -1 * y - rect.height); x += rect.width + 30; // Reflect around the x and y axes transform.setElements(-1, 0, 0, -1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, -1 * x - rect.width, -1 * y - rect.height); x = 30; y += rect.height + 30; // Shear in the x-direction transform.setElements(1, 0, -1, 1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, 300, y); // Shear in y-direction transform.setElements(1, -1, 0, 1, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, 150, 475); // Rotate by 45 degrees float cos45 = (float) Math.cos(Math.PI / 4); float sin45 = (float) Math.sin(Math.PI / 4); transform.setElements(cos45, sin45, -sin45, cos45, 0, 0); gc1.setTransform(transform); gc1.drawImage(image, 400, 60); transform.dispose(); }); shell.setSize(350, 550); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } image.dispose(); display.dispose(); }
From source file:info.financialecology.finance.utilities.sandbox.SimpleStrategyCOND.java
public static void main(String[] args) { SimpleStrategyCOND strategyCOND = new SimpleStrategyCOND(); int nTicks = 200; // Number of ticks double sinus_shift = 0.0; double sinus_amplitude = 10.0; double sinus_lambda = 50.0; double sinus_t_prev = sinus_amplitude + sinus_shift + sinus_amplitude * Math.sin(2 * 0 * Math.PI / sinus_lambda); for (int i = 1; i < nTicks; i++) { double sinus_t = sinus_amplitude + sinus_shift + sinus_amplitude * Math.sin(2 * i * Math.PI / sinus_lambda); logger.info("Tick: " + i + ", value: " + sinus_t + ", position: " + strategyCOND.newPosition(sinus_t, sinus_t_prev)); sinus_t_prev = sinus_t;/*from w w w .j av a2 s.c o m*/ } }
From source file:Draw2DTest.java
public static void main(String[] args) { final Graphics2DRenderer renderer = new Graphics2DRenderer(); Shell shell = new Shell(); shell.setSize(350, 350);// w w w. j ava 2 s. c o m shell.open(); shell.setText("Draw2d Hello World"); LightweightSystem lws = new LightweightSystem(shell); IFigure figure = new Figure() { protected void paintClientArea(org.eclipse.draw2d.Graphics graphics) { Dimension controlSize = getSize(); renderer.prepareRendering(graphics); // prepares the Graphics2D renderer // gets the Graphics2D context and switch on the antialiasing Graphics2D g2d = renderer.getGraphics2D(); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // paints the background with a color gradient g2d.setPaint(new GradientPaint(0.0f, 0.0f, java.awt.Color.yellow, (float) controlSize.width, (float) controlSize.width, java.awt.Color.white)); g2d.fillRect(0, 0, controlSize.width, controlSize.width); // draws rotated text g2d.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 16)); g2d.setColor(java.awt.Color.blue); g2d.translate(controlSize.width / 2, controlSize.width / 2); int nbOfSlices = 18; for (int i = 0; i < nbOfSlices; i++) { g2d.drawString("Angle = " + (i * 360 / nbOfSlices) + "\u00B0", 30, 0); g2d.rotate(-2 * Math.PI / nbOfSlices); } // now that we are done with Java2D, renders Graphics2D // operation // on the SWT graphics context renderer.render(graphics); // now we can continue with pure SWT paint operations graphics.drawOval(0, 0, controlSize.width, controlSize.width); } }; lws.setContents(figure); Display display = Display.getDefault(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } renderer.dispose(); }