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:org.jstockchart.axis.TimeseriesNumberAxis.java
public List<Tick> refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { TextAnchor anchor = null;//www . jav a2 s . c om TextAnchor rotationAnchor = null; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = Math.PI / 2.0; } else { angle = -Math.PI / 2.0; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } return createTicks(logicTicks, anchor, rotationAnchor, angle); }
From source file:SimpleGame.java
/** * This builds the view branch of the scene graph. * //from w w w .jav a2 s .c o m * @return BranchGroup with viewing objects attached. */ protected BranchGroup buildViewBranch(Canvas3D c) { BranchGroup viewBranch = new BranchGroup(); Transform3D viewXfm = new Transform3D(); Matrix3d viewTilt = new Matrix3d(); viewTilt.rotX(Math.PI / -6); viewXfm.set(viewTilt, new Vector3d(0.0, 10.0, 10.0), 1.0); TransformGroup viewXfmGroup = new TransformGroup(viewXfm); ViewPlatform myViewPlatform = new ViewPlatform(); PhysicalBody myBody = new PhysicalBody(); PhysicalEnvironment myEnvironment = new PhysicalEnvironment(); viewXfmGroup.addChild(myViewPlatform); viewBranch.addChild(viewXfmGroup); View myView = new View(); myView.addCanvas3D(c); myView.attachViewPlatform(myViewPlatform); myView.setPhysicalBody(myBody); myView.setPhysicalEnvironment(myEnvironment); return viewBranch; }
From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Freqz.java
public Freqz(double[] b, int n) { FastFourierTransformer fft = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] hb = fft.transform(Arrays.copyOf(b, 2 * n), TransformType.FORWARD); H = Arrays.copyOfRange(hb, 0, n); w = new double[n]; for (int i = 0; i < H.length; i++) { w[i] = Math.PI / n * i; }//from w ww.j a v a 2 s . c om }
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 w w w . j a v a 2s. 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:etomica.models.co2.PNCO2GCPM.java
public PNCO2GCPM(ISpace space, int nBody) { super(nBody, space); pair = new MoleculePair(); sigmaC = 3.193;//from w w w .java 2 s. co m sigmaO = sigmaC * 1.0483; //paper says 3.347; coreFac = 0.57 * 0.57; epsilonC = Kelvin.UNIT.toSim(71.34); epsilonO = Kelvin.UNIT.toSim(67.72); tauO = 0.6100; tauC = tauO / 1.0483; // paper reports 0.5819, fortran uses this instead sqrtCOtau = Math.sqrt(2 * (tauC * tauC + tauO * tauO)); double[] t = new double[] { tauC, tauO, tauO }; double[] s = new double[] { sigmaC, sigmaO, sigmaO }; double[] e = new double[] { epsilonC, epsilonO, epsilonO }; tauAll = new double[3][3]; sigmaAll = new double[3][3]; epsilonAll = new double[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { sigmaAll[i][j] = 0.5 * (s[i] + s[j]); epsilonAll[i][j] = 2 * e[i] * e[j] / (e[i] + e[j]); tauAll[i][j] = Math.sqrt(2 * (t[i] * t[i] + t[j] * t[j])); } } gamma = 15.5; chargeO = Electron.UNIT.toSim(-0.3321); chargeC = Electron.UNIT.toSim(+0.6642); chargeAll = new double[] { chargeC, chargeO, chargeO }; sqrtPiCOtau = Math.sqrt(Math.PI * (tauC * tauC + tauO * tauO)); sqrtPiCCtau = Math.sqrt(Math.PI * (2 * tauC * tauC)); alphaPar = 4.05; alphaPerp = 1.95; oldMu = space.makeVector(); shift = space.makeVector(); rijVector = space.makeVector(); work = space.makeVector(); Tunit = space.makeTensor(); Tunit.E(new double[][] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }); Tij = space.makeTensor(); Eq = new IVectorMutable[0]; Ep = new IVectorMutable[0]; mu = new IVectorMutable[0]; component = Component.FULL; }
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 .ja va 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:com.opengamma.analytics.financial.interestrate.swaption.method.SwaptionPhysicalFixedIborHullWhiteNumericalIntegrationMethod.java
/** * Computes the present value of the Physical delivery swaption. * @param swaption The swaption./* w ww .j av a2 s .c o m*/ * @param hwData The Hull-White parameters and the curves. * @return The present value. */ public CurrencyAmount presentValue(final SwaptionPhysicalFixedIbor swaption, final HullWhiteOneFactorPiecewiseConstantDataBundle hwData) { Validate.notNull(swaption); Validate.notNull(hwData); double expiryTime = swaption.getTimeToExpiry(); AnnuityPaymentFixed cfe = CFEC.visit(swaption.getUnderlyingSwap(), hwData); double[] alpha = new double[cfe.getNumberOfPayments()]; double[] df = new double[cfe.getNumberOfPayments()]; double[] discountedCashFlow = new double[cfe.getNumberOfPayments()]; for (int loopcf = 0; loopcf < cfe.getNumberOfPayments(); loopcf++) { alpha[loopcf] = MODEL.alpha(hwData.getHullWhiteParameter(), 0.0, expiryTime, expiryTime, cfe.getNthPayment(loopcf).getPaymentTime()); df[loopcf] = hwData.getCurve(cfe.getDiscountCurve()) .getDiscountFactor(cfe.getNthPayment(loopcf).getPaymentTime()); discountedCashFlow[loopcf] = df[loopcf] * cfe.getNthPayment(loopcf).getAmount(); } // Integration final SwaptionIntegrant integrant = new SwaptionIntegrant(discountedCashFlow, alpha); final double limit = 10.0; final double absoluteTolerance = 1.0E-2; final double relativeTolerance = 1.0E-6; final RungeKuttaIntegrator1D integrator = new RungeKuttaIntegrator1D(absoluteTolerance, relativeTolerance, NB_INTEGRATION); double pv = 0.0; try { pv = 1.0 / Math.sqrt(2.0 * Math.PI) * integrator.integrate(integrant, -limit, limit) * (swaption.isLong() ? 1.0 : -1.0); } catch (final Exception e) { throw new RuntimeException(e); } return CurrencyAmount.of(swaption.getCurrency(), pv); }
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 ava 2s . co m */ 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:com.opengamma.analytics.financial.model.option.pricing.fourier.FourierModelGreeks.java
public double[] getGreeks(final BlackFunctionData data, final EuropeanVanillaOption option, final MartingaleCharacteristicExponent ce, final double alpha, final double limitTolerance) { Validate.notNull(data, "data"); Validate.notNull(option, "option"); Validate.notNull(ce, "characteristic exponent"); Validate.isTrue(limitTolerance > 0, "limit tolerance must be > 0"); Validate.isTrue(alpha <= ce.getLargestAlpha() && alpha >= ce.getSmallestAlpha(), "The value of alpha is not valid for the Characteristic Exponent and will most likely lead to mispricing. Choose a value between " + ce.getSmallestAlpha() + " and " + ce.getLargestAlpha()); final EuropeanCallFourierTransform psi = new EuropeanCallFourierTransform(ce); final double strike = option.getStrike(); final double t = option.getTimeToExpiry(); final double forward = data.getForward(); final double discountFactor = data.getDiscountFactor(); final Function1D<ComplexNumber, ComplexNumber> characteristicFunction = psi.getFunction(t); final double xMax = LIMIT_CALCULATOR.solve(characteristicFunction, alpha, limitTolerance); double kappa = Math.log(strike / forward); int n = ce.getCharacteristicExponentAdjoint(MINUS_I, 1.0).length; //TODO have method like getNumberOfparameters Function1D<ComplexNumber, ComplexNumber[]> adjointFuncs = ce.getAdjointFunction(t); double[] res = new double[n - 1]; //TODO This is inefficient as a call to ajointFuncs.evaluate(z), will return several values (the value of the characteristic function and its derivatives), but only one // of these values is used by each of the the integraters - a parallel quadrature scheme would be good here for (int i = 0; i < n - 1; i++) { final Function1D<Double, Double> func = getIntegrandFunction(adjointFuncs, alpha, kappa, i + 1); final double integral = Math.exp(-alpha * Math.log(strike / forward)) * _integrator.integrate(func, 0.0, xMax) / Math.PI; res[i] = discountFactor * forward * integral; }//w w w . j a v a 2s. c o m return res; }
From source file:org.web4thejob.orm.test.AbstractHibernateDependentTest.java
@Before public void initializeData() { if (initialized) { return;//from www . j a v a2 s . com } Properties datasource = new Properties(); try { datasource.load(new ClassPathResource(DatasourceProperties.PATH).getInputStream()); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } JobletInstaller jobletInstaller; jobletInstaller = ContextUtil.getBean(JobletInstaller.class); jobletInstaller.setConnectionInfo(datasource); List<Exception> errors = jobletInstaller.installAll(); if (errors.isEmpty()) { ContextUtil.addActiveProfile("installed"); ContextUtil.refresh(); } else { throw new RuntimeException("Test Context initialization failed."); } initialized = true; final DataWriterService dataWriterService = ContextUtil.getDWS(); for (int i = 1; i <= iterations; i++) { Reference2 reference2 = new Reference2(UUID.randomUUID().toString()); dataWriterService.save(reference2); Reference1 reference1 = new Reference1(reference2, UUID.randomUUID().toString()); dataWriterService.save(reference1); final Master1 master1 = new Master1(); master1.setName(master1.getEntityType().getName()); master1.setReference1(reference1); dataWriterService.save(master1); final Master2 master2 = new Master2(); master2.setKey(UUID.randomUUID().toString()); master2.setName(master2.getEntityType().getName()); dataWriterService.save(master2); final Detail detail = new Detail(); detail.setId(new DetailId(master1, master2, UUID.randomUUID().toString(), new Random(master1.getId()).nextLong())); detail.setFclass(detail.getEntityType()); detail.setFdate(new Date()); detail.setFdouble(java.lang.Math.PI); detail.setFint(new LocalDate().getMonthOfYear()); detail.setFstring(new LocalDate().toString()); detail.setFtimestamp(new Timestamp(System.currentTimeMillis())); dataWriterService.save(detail); } }