List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java
public static ComplexNumber sin(final ComplexNumber z) { Validate.notNull(z, "z"); final double x = z.getReal(); final double y = z.getImaginary(); return new ComplexNumber(Math.sin(x) * Math.cosh(y), Math.cos(x) * Math.sinh(y)); }
From source file:Clock.java
public void paintComponent(Graphics g) { super.paintComponent(g); Color colorRetainer = g.getColor(); g.setColor(getBackground());/*from ww w .j ava2s.co m*/ g.fillRect(0, 0, getWidth(), getHeight()); getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); calendar.setTime(new Date()); // get current time int hrs = calendar.get(Calendar.HOUR_OF_DAY); int min = calendar.get(Calendar.MINUTE); g.setColor(getForeground()); if (isDigital) { String time = "" + hrs + ":" + min; g.setFont(getFont()); FontMetrics fm = g.getFontMetrics(); int y = (getHeight() + fm.getAscent()) / 2; int x = (getWidth() - fm.stringWidth(time)) / 2; g.drawString(time, x, y); } else { int x = getWidth() / 2; int y = getHeight() / 2; int rh = getHeight() / 4; int rm = getHeight() / 3; double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI; double am = min / 30.0 * Math.PI; g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah))); g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am))); } g.setColor(colorRetainer); }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java
protected double mixed(double[] x, int A, double alpha) { double tmp = 2.0 * A * Math.PI; return correct_to_01(Math.pow(1.0 - x[0] - Math.cos(tmp * x[0] + Math.PI / 2.0) / tmp, alpha), EPSILON); }
From source file:utils.RandomVariable.java
/** * Generate a random number from a LogNormal random variable. * * @param mu mean of the Normal random variable. * @param sigma standard deviation of the Normal random variable. * @return a double.//from w w w . j av a 2s . c om */ public static double logNormal(double mu, double sigma) { double x = mu + sigma * Math.cos(2 * Math.PI * rand()) * Math.sqrt(-2 * Math.log(rand())); return x; }
From source file:net.ostis.scpdev.scg.geometry.GraphLayout.java
private void calculateForces() { int n = nodes.size(); RealVector[] forces = new RealVector[n]; for (int i = 0; i < n; ++i) forces[i] = new ArrayRealVector(new double[] { 0, 0 }); Map<IFigure, Integer> obj_f = new HashMap<IFigure, Integer>(); Point[] o_pos = new Point[n]; ///* w ww .j a v a2 s . co m*/ // Calculation repulsion forces. // for (int idx = 0; idx < n; ++idx) { obj_f.put(nodes.get(idx), idx); Point p1 = nodes.get(idx).getBounds().getLocation(); RealVector p1v = new ArrayRealVector(2); p1v.setEntry(0, p1.x); p1v.setEntry(0, p1.y); double l = nullVector.getDistance(p1v); RealVector f = p1v.mapMultiply(gravity * (l - 3.0)); forces[idx].subtract(f); for (int jdx = idx + 1; jdx < n; ++jdx) { Point p2 = nodes.get(idx).getBounds().getLocation(); RealVector p2v = new ArrayRealVector(2); p2v.setEntry(0, p2.x); p2v.setEntry(0, p2.y); l = p1v.getDistance(p2v); if (l > max_rep_length) continue; if (l > 0.5) { f = p1v.subtract(p2v).mapMultiply(repulsion / l / l); } else { f = new ArrayRealVector(new double[] { Math.cos(0.17 * idx) * length * 7, Math.sin(0.17 * (idx + 1)) * length * 7 }); } forces[idx].add(f); forces[jdx].subtract(f); } } for (int idx = 0; idx < n; ++idx) { RealVector f = forces[idx]; f.mapMultiply(stepSize); nodes.get(idx).setLocation(new Point(f.getEntry(0), f.getEntry(1))); } }
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 w w .j av a2s. co 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:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.BeginInlineImage.java
/** * process : BI : begin inline image.//from www. j a va 2s . co m * @param operator The operator that is being executed. * @param arguments List * @throws java.io.IOException If there is an error displaying the inline image. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context; PDPage page = drawer.getPage(); //begin inline image object ImageParameters params = operator.getImageParameters(); PDInlinedImage image = new PDInlinedImage(); image.setImageParameters(params); image.setImageData(operator.getImageData()); BufferedImage awtImage = image.createImage(context.getColorSpaces()); if (awtImage == null) { log.warn("BeginInlineImage.process(): createImage returned NULL"); return; } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = drawer.getPageSize().getHeight(); Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.findRotation(); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(ctmAT); // calculate the inverse rotation angle // scaleX = m00 = cos // shearX = m01 = -sin // tan = sin/cos double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX()); Matrix translationMatrix = null; if (pageRotation == 0 || pageRotation == 180) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()), (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale())); } else if (pageRotation == 90 || pageRotation == 270) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()), (float) (pageHeight - 2 * ctm.getYPosition())); } rotationMatrix = rotationMatrix.multiply(translationMatrix); rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1)); rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0)); AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1), rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0), rotationMatrix.getValue(2, 1)); drawer.drawImage(awtImage, at); }
From source file:com.day.cq.wcm.foundation.TableTest.java
@org.junit.Test public void testDoubleDataTable() throws IOException { Table table = new Table(); // fill table for (int r = 0; r < 25; r++) { for (int c = 0; c < 25; c++) { double v = Math.sin(r * 2.0 * Math.PI / 25.0) + Math.cos(c * 2.0 * Math.PI / 25.0); table.getCell(r, c, true).setText(String.valueOf(v)); }// w w w.java 2 s. c o m } // check entire table double[][] data = table.getDoubleData(); for (int y = 0; y < data.length; y++) { for (int x = 0; x < data[y].length; x++) { double d = data[y][x]; double v = Math.sin(y * 2.0 * Math.PI / 25.0) + Math.cos(x * 2.0 * Math.PI / 25.0); assertEquals(d, v, 0.0); } } }
From source file:CircleLayoutTest.java
public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int containerWidth = parent.getSize().width - insets.left - insets.right; int containerHeight = parent.getSize().height - insets.top - insets.bottom; int xradius = (containerWidth - maxComponentWidth) / 2; int yradius = (containerHeight - maxComponentHeight) / 2; setSizes(parent);/*from ww w . ja va 2 s . co m*/ int centerX = insets.left + containerWidth / 2; int centerY = insets.top + containerHeight / 2; int comCount = parent.getComponentCount(); for (int i = 0; i < comCount; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension size = c.getPreferredSize(); double angle = 2 * Math.PI * i / comCount; int x = centerX + (int) (Math.cos(angle) * xradius); int y = centerY + (int) (Math.sin(angle) * yradius); c.setBounds(x - size.width / 2, y - size.height / 2, size.width, size.height); } } }
From source file:BackEnd.E_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(R0.getX(), R0.getY(), R0.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)); 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 = Math.pow(get_ABS(R_r), 2); double menovatel_m = Math.pow(get_ABS(R_m), 2); double DELTA_l = get_ABS(deltaL); //// w ww . j av a 2 s . co m //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; }