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:ShowOff.java
protected void drawText(Graphics2D g2) { FontRenderContext frc = g2.getFontRenderContext(); mLayout = new TextLayout(mMessage, mFont, frc); int width = getSize().width; int height = getSize().height; Rectangle2D bounds = mLayout.getBounds(); double x = (width - bounds.getWidth()) / 2; double y = height - bounds.getHeight(); drawString(g2, x, y, 0);/*w w w . ja va 2s .c o m*/ drawString(g2, width - bounds.getHeight(), y, -Math.PI / 2); }
From source file:de.mfo.jsurf.grid.RotationGrid.java
protected static void setOptimalCameraDistance(Camera c) { float cameraDistance; switch (c.getCameraType()) { case ORTHOGRAPHIC_CAMERA: cameraDistance = 1.0f;//from w w w . j av a2 s . c om break; case PERSPECTIVE_CAMERA: cameraDistance = (float) (1.0 / Math.sin((Math.PI / 180.0) * (c.getFoVY() / 2.0))); break; default: throw new RuntimeException(); } c.lookAt(new Point3d(0, 0, cameraDistance), new Point3d(0, 0, -1), new Vector3d(0, 1, 0)); }
From source file:com.autsia.bracer.BracerParser.java
/** * Parses the math expression (complicated formula) and stores the result * * @param expression <code>String</code> input expression (math formula) * @throws <code>ParseException</code> if the input expression is not * correct * @since 3.0/*from www .jav a 2 s .c om*/ */ public void parse(String expression) throws ParseException { /* cleaning stacks */ stackOperations.clear(); stackRPN.clear(); /* * make some preparations: remove spaces; handle unary + and -, handle * degree character */ expression = expression.replace(" ", "").replace("", "*" + Double.toString(Math.PI) + "/180") .replace("(-", "(0-").replace(",-", ",0-").replace("(+", "(0+").replace(",+", ",0+") .replace("true", "1").replace("false", "0").replace("or", "|").replace("and", "&"); if (expression.charAt(0) == '-' || expression.charAt(0) == '+') { expression = "0" + expression; } /* splitting input string into tokens */ StringTokenizer stringTokenizer = new StringTokenizer(expression, OPERATORS + SEPARATOR + "()", true); /* loop for handling each token - shunting-yard algorithm */ while (stringTokenizer.hasMoreTokens()) { String token = stringTokenizer.nextToken(); if (isSeparator(token)) { while (!stackOperations.empty() && !isOpenBracket(stackOperations.lastElement())) { stackRPN.push(stackOperations.pop()); } } else if (isOpenBracket(token)) { stackOperations.push(token); } else if (isCloseBracket(token)) { while (!stackOperations.empty() && !isOpenBracket(stackOperations.lastElement())) { stackRPN.push(stackOperations.pop()); } stackOperations.pop(); if (!stackOperations.empty() && isFunction(stackOperations.lastElement())) { stackRPN.push(stackOperations.pop()); } } else if (isNumber(token)) { if (token.equals(IMAGINARY)) { stackRPN.push(complexFormat.format(new Complex(0, 1))); } else if (token.contains(IMAGINARY)) { stackRPN.push(complexFormat.format(complexFormat.parse("0+" + token))); } else { stackRPN.push(token); } } else if (isOperator(token)) { while (!stackOperations.empty() && isOperator(stackOperations.lastElement()) && getPrecedence(token) <= getPrecedence(stackOperations.lastElement())) { stackRPN.push(stackOperations.pop()); } stackOperations.push(token); } else if (isFunction(token)) { stackOperations.push(token); } else { throw new ParseException("Unrecognized token: " + token, 0); } } while (!stackOperations.empty()) { stackRPN.push(stackOperations.pop()); } /* reverse stack */ Collections.reverse(stackRPN); }
From source file:TextureTransformTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); // create the rotation interpolator to rotate the scene RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(createApplicationBounds()); objTrans.addChild(rotator);//from ww w .j a va 2s . c o m // create the box final int nScale = 50; Appearance app = new Appearance(); Box box = new Box(nScale, nScale, nScale, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, app); // load the texture image TextureLoader texLoader = new TextureLoader("texture.gif", this); app.setTexture(texLoader.getTexture()); // set the texture attributes and ensure we // can write to the Transform for the texture attributes m_TextureAttributes = new TextureAttributes(); m_TextureAttributes.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE); app.setTextureAttributes(m_TextureAttributes); // connect all the elements objTrans.addChild(box); objRoot.addChild(objTrans); objRoot.addChild(createRotator()); return objRoot; }
From source file:BackEnd.E_old_calculation.java
private FazorVektor calc_DE(double tau_real, double tau_image, DPoint Rp, DPoint R0, DPoint R0m, DPoint deltaL) throws DelaunayError { DPoint R_0 = new DPoint(R0.getX(), R0.getY(), R0.getZ()); DPoint R_0m = new DPoint(R0m.getX(), R0m.getY(), R0m.getZ()); R_0.setY(R0.getY() + R0_bundleY); // bundle korektura pre jeden druhy SMER R_0.setZ(R0.getZ() + Math.cos(beta) * R0_bundleZ); // priemety R_0.setX(R0.getX() + Math.sin(beta) * R0_bundleZ); R_0m.setY(R0m.getY() - R0_bundleY); // bundle korektura pre jeden druhy SMER R_0m.setZ(R0m.getZ() + Math.cos(beta) * R0_bundleZ); // priemety R_0m.setX(R0m.getX() + Math.sin(beta) * R0_bundleZ); // System.out.println( "R_0= " + R_0 ); // System.out.println( "Rp= " + Rp ); // System.out.println( "deltal= " + deltaL ); double K = 1 / (4 * Math.PI * constants.getEpsi0() * constants.getEpsi1()); // kontanta DPoint R_r = help.substract(Rp, R_0); // rozdiel vektorov Rp a RO DPoint R_m = help.substract(Rp, R_0m); // rozdiel vektorov RP a RO mirror DPoint R_r_unit = new DPoint(R_r); DPoint R_m_unit = new DPoint(R_m); // R_r_unit.setX(R_r_unit.getX()/get_ABS(R_r)); // R_r_unit.setY(R_r_unit.getY()/get_ABS(R_r)); // R_r_unit.setZ(R_r_unit.getZ()/get_ABS(R_r)); // /*from w ww . j av a 2 s . c o m*/ // R_m_unit.setX(R_m_unit.getX()/get_ABS(R_m)); // R_m_unit.setY(R_m_unit.getY()/get_ABS(R_m)); // R_m_unit.setZ(R_m_unit.getZ()/get_ABS(R_m)); double menovatel_r = 0; double menovatel_m = 0; menovatel_r = Math.pow(get_ABS(R_r), 3); menovatel_m = Math.pow(get_ABS(R_m), 3); double DELTA_l = get_ABS(deltaL); // //double DELTA_l = 1; //Rozptie.getKrok(); FazorVektor deltaE = new FazorVektor(new Complex(0, 0), new Complex(0, 0), new Complex(0, 0)); deltaE.setX_Real(K * (((tau_real * DELTA_l * R_r_unit.getX()) / menovatel_r) - ((tau_real * DELTA_l * R_m_unit.getX()) / menovatel_m))); deltaE.setY_Real(K * (((tau_real * DELTA_l * R_r_unit.getY()) / menovatel_r) - ((tau_real * DELTA_l * R_m_unit.getY()) / menovatel_m))); deltaE.setZ_Real(K * (((tau_real * DELTA_l * R_r_unit.getZ()) / menovatel_r) - ((tau_real * DELTA_l * R_m_unit.getZ()) / menovatel_m))); deltaE.setX_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getX()) / menovatel_r) - ((tau_image * DELTA_l * R_m_unit.getX()) / menovatel_m))); deltaE.setY_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getY()) / menovatel_r) - ((tau_image * DELTA_l * R_m_unit.getY()) / menovatel_m))); deltaE.setZ_Imaginary(K * (((tau_image * DELTA_l * R_r_unit.getZ()) / menovatel_r) - ((tau_image * DELTA_l * R_m_unit.getZ()) / menovatel_m))); return deltaE; }
From source file:org.mili.jmibs.jfree.JFreeChartBarIterationObjectLoadIntervalBenchmarkSuiteResultRenderer.java
private JFreeChart createChart(String title, CategoryDataset dataset) { JFreeChart chart = ChartFactory.createBarChart(title, "Benchmark (Iteration/Object Loading/Interval)", "Time in ns", dataset, PlotOrientation.HORIZONTAL, true, true, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false);/*from w w w. ja va2 s .c om*/ GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); return chart; }
From source file:electrical_parameters.Basic.java
public Basic(RealMatrix Dik, ArrayList<elpam_input_conductor> cnd_list, boolean exact_GMR, boolean exact_Rac, int fv, int gw) { // GMR_calculation cnd = new GMR_calculation(Conductor); // Rac_calculation cnd2 = new Rac_calculation(Conductor); this.rows = Dik.getRowDimension(); this.cols = Dik.getColumnDimension(); this.GMR = new double[cnd_list.size()]; this.R_cnd = new double[cnd_list.size()]; this.GMR = new double[cnd_list.size()]; this.rho_gnd = new double[cnd_list.size()]; this.fv = fv; this.gw = gw; if (exact_GMR) { for (int i = 0; i < cnd_list.size(); i++) { this.GMR[i] = cnd_list.get(i).getGMR(); }/* w w w . ja va 2 s. c om*/ } else { for (int i = 0; i < cnd_list.size(); i++) { this.GMR[i] = cnd_list.get(i).getGMR_default(); } } if (exact_Rac) { for (int i = 0; i < cnd_list.size(); i++) { this.R_cnd[i] = cnd_list.get(i).getRac(); } } else { for (int i = 0; i < cnd_list.size(); i++) { this.R_cnd[i] = cnd_list.get(i).getRdc(); } } this.Dik = Dik; this.f = constants.getFrequency(); for (int i = 0; i < cnd_list.size(); i++) { this.rho_gnd[i] = cnd_list.get(i).getRho_ground(); } this.R = initMatrix(Dik); this.L = initMatrix(Dik); this.X = initMatrix(Dik); this.Z = initComplexMatrix(Dik); this.R_red = new Array2DRowRealMatrix(fv, fv); this.L_red = new Array2DRowRealMatrix(fv, fv); this.X_red = new Array2DRowRealMatrix(fv, fv); this.Z_red = new ComplexMatrix(fv, fv); this.R_red_symm = new Array2DRowRealMatrix(fv, fv); this.L_red_symm = new Array2DRowRealMatrix(fv, fv); this.X_red_symm = new Array2DRowRealMatrix(fv, fv); this.Z_red_symm = new ComplexMatrix(fv, fv); this.rho_avg = arraySum(this.rho_gnd) / this.rho_gnd.length; this.Dg = 659 * Math.sqrt(this.rho_avg / this.f); this.omega = (double) 2 * Math.PI * this.f; this.mu = (4e-4) * Math.PI; this.Rg = (double) this.omega * this.mu / 8; this.mu2pi = (this.mu / (2 * Math.PI)); }
From source file:moa.classifiers.core.statisticaltests.Cramer.java
private Complex[] fft(Complex[] x) { int N = x.length; // base case/*from w w w. j a v a 2 s . c om*/ if (N == 1) { return new Complex[] { x[0] }; } // radix 2 Cooley-Tukey FFT if (N % 2 != 0) { throw new RuntimeException("N is not a power of 2"); } // fft of even terms Complex[] even = new Complex[N / 2]; for (int k = 0; k < N / 2; k++) { even[k] = x[2 * k]; } Complex[] q = fft(even); // fft of odd terms Complex[] odd = even; // reuse the array for (int k = 0; k < N / 2; k++) { odd[k] = x[2 * k + 1]; } Complex[] r = fft(odd); // combine Complex[] yy = new Complex[N]; for (int k = 0; k < N / 2; k++) { double kth = -2 * k * Math.PI / N; Complex wk = new Complex(Math.cos(kth), Math.sin(kth)); yy[k] = q[k].add(wk.multiply(r[k])); yy[k + N / 2] = q[k].subtract(wk.multiply(r[k])); } return yy; }
From source file:BackEnd.B_calculation.java
private double getI_real() { double I_real = I * Math.cos(phase * (Math.PI / 180)); return I_real; }
From source file:Pyramid2Cube.java
private BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);//from w ww. j a va2s. c om objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and behavior BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // // Create the transform group nodes for the 3 original objects // and the morphed object. Add them to the root of the // branch graph. // TransformGroup objTrans[] = new TransformGroup[4]; for (int i = 0; i < 4; i++) { objTrans[i] = new TransformGroup(); objScale.addChild(objTrans[i]); } Transform3D tr = new Transform3D(); Transform3D rotY15 = new Transform3D(); rotY15.rotY(15.0 * Math.PI / 180.0); objTrans[0].getTransform(tr); tr.setTranslation(new Vector3d(-3.0, 1.5, -6.5)); tr.mul(rotY15); objTrans[0].setTransform(tr); objTrans[1].getTransform(tr); tr.setTranslation(new Vector3d(0.0, 1.5, -6.5)); tr.mul(rotY15); objTrans[1].setTransform(tr); objTrans[2].getTransform(tr); tr.setTranslation(new Vector3d(3.0, 1.5, -6.5)); tr.mul(rotY15); objTrans[2].setTransform(tr); objTrans[3].getTransform(tr); tr.setTranslation(new Vector3d(0.0, -2.0, -5.0)); tr.mul(rotY15); objTrans[3].setTransform(tr); // Now create simple geometries. QuadArray g[] = new QuadArray[3]; Shape3D shape[] = new Shape3D[3]; for (int i = 0; i < 3; i++) { g[i] = null; shape[i] = null; } g[0] = new ColorPyramidUp(); g[1] = new ColorCube(); g[2] = new ColorPyramidDown(); Appearance a = new Appearance(); for (int i = 0; i < 3; i++) { shape[i] = new Shape3D(g[i], a); objTrans[i].addChild(shape[i]); } // // Create a Morph node, and set the appearance and input geometry // arrays. Set the Morph node's capability bits to allow the weights // to be modified at runtime. // Morph morph = new Morph((GeometryArray[]) g, a); morph.setCapability(Morph.ALLOW_WEIGHTS_READ); morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE); objTrans[3].addChild(morph); // Now create the Alpha object that controls the speed of the // morphing operation. Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 4000, 1000, 500, 4000, 1000, 500); // Finally, create the morphing behavior MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph); mBeh.setSchedulingBounds(bounds); objScale.addChild(mBeh); return objRoot; }