List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java
public static double sin(final double x) { return Math.sin(x); }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz2.R_Dtlz2_Objective.java
@Override public double evaluate(double[] x) { int nx = x.length; int i = 0, j = 0; int k = nx - numberOfObjectives + 1; double g = 0; double[] z = new double[nx]; double[] zz = new double[nx]; double[] p = new double[nx]; double[] psum = new double[numberOfObjectives]; // denormalize vector: for (i = 0; i < nx; i++) { x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2; }/*from ww w .j a v a 2 s. co m*/ for (i = 0; i < nx; i++) { z[i] = 0; for (j = 0; j < nx; j++) { z[i] += M[i][j] * x[j]; } if (z[i] >= 0 && z[i] <= 1) { zz[i] = z[i]; p[i] = 0; } else if (z[i] < 0) { zz[i] = -lambda[i] * z[i]; p[i] = -z[i]; } else { zz[i] = 1 - lambda[i] * (z[i] - 1); p[i] = z[i] - 1; } } for (j = 0; j < numberOfObjectives; j++) { psum[j] = 0; } for (i = nx - k + 1; i <= nx; i++) { g += Math.pow(zz[i - 1] - 0.5, 2) - Math.cos(20 * Math.PI * (zz[i - 1] - 0.5)); for (j = 0; j < numberOfObjectives; j++) { psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2)); } } g = 100 * (k + g); double ff = (1 + g); for (j = numberOfObjectives - objNumber; j >= 1; j--) { ff *= Math.cos(zz[j - 1] * Math.PI / 2.0); psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2)); } if (objNumber > 1) { ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0); psum[objNumber - 1] = Math.sqrt( Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2)); } return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1); }
From source file:io.lonelyrobot.empires.fw.game.obj.BaseObject.java
/** * This function is called recursively from the {@link Star}, updating it's children * with an offset of {0, 0}. These children then move themselves according to the * position of their parent and then pass this offset to their children. These children * move themselves by the offset and then calculate their additional offset. * /*ww w .jav a 2 s . c o m*/ * @param parentOffset */ public void updateOrbits(Vector2D parentOffset) { Vector2D offset = new Vector2D(0, 0); if (orbit != null && orbit.getParent() != null) { Vector2D p = orbit.getParent().getSolPos(); /** Calculate own offset */ double x = p.getX() + orbit.getRadius() * Math.cos(orbit.getStep()); double y = p.getY() + orbit.getRadius() * Math.sin(orbit.getStep()); orbit.setStep(orbit.getStep() + orbit.getStepSpeed()); Vector2D newPos = new Vector2D(x, y); newPos.add(parentOffset); // offset.add(new Vector2D(x, y)); /** Add the parent offset on top */ // offset.add(parentOffset); offset.add(newPos); /** Apply position to self */ this.setSolPos(newPos); } /** Only propagate orbital offsets if self is Orbitable */ if (!(this instanceof Orbitable)) return; /** Call function for all children with the new (accumilated) offset */ Tools.safe(orbit.getChildren()).forEach((i) -> i.updateOrbits(offset)); }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java
protected double convex(double[] x, int m, int M) { int i;/*from www. j a va 2 s. com*/ double result = 1.0; for (i = 1; i <= M - m; i++) { result *= 1.0 - Math.cos(x[i - 1] * Math.PI / 2.0); } if (m != 1) { result *= 1.0 - Math.sin(x[M - m] * Math.PI / 2.0); } return correct_to_01(result, EPSILON); }
From source file:Wavelet.java
/** This is the function that is plotted. */ double func(double x) { Dimension d = getSize();/*w w w . j a va 2 s . com*/ return (Math.cos(x / 9) + Math.sin(x / 3) + 1) * d.height / 4; }
From source file:geogebra.kernel.GeoVec2D.java
public void setPolarCoords(double r, double phi) { x = r * Math.cos(phi); y = r * Math.sin(phi); }
From source file:edu.stanford.slac.archiverappliance.PB.data.LargePBLineTest.java
@Test public void testLargeLines() throws Exception { // We create vector doubles with a large number of elements; write it out and then test the read. String pvName = ConfigServiceForTests.ARCH_UNIT_TEST_PVNAME_PREFIX + "LargeLineTest" + largeLineTest.getPartitionGranularity(); ArchDBRTypes type = ArchDBRTypes.DBR_WAVEFORM_DOUBLE; short year = TimeUtils.getCurrentYear(); for (int i = 1; i < 7200; i++) { try (BasicContext context = new BasicContext()) { ArrayListEventStream strm = new ArrayListEventStream(1024, new RemotableEventStreamDesc(type, pvName, year)); DBR_TIME_Double retvd = new DBR_TIME_Double(ArrayUtils .toPrimitive(Collections.nCopies(i, Math.sin(i * Math.PI / 3600)).toArray(new Double[0]))); retvd.setTimeStamp(new gov.aps.jca.dbr.TimeStamp(TimeUtils.getStartOfCurrentYearInSeconds() + i)); retvd.setSeverity(1);/*from w w w . ja v a2s .c o m*/ retvd.setStatus(0); strm.add(new PBVectorDouble(retvd)); largeLineTest.appendData(context, pvName, strm); } catch (Exception ex) { logger.error("Exception appending data " + i, ex); fail(ex.getMessage()); } } Path[] allPaths = PlainPBPathNameUtility.getAllPathsForPV(new ArchPaths(), largeLineTest.getRootFolder(), pvName, ".pb", largeLineTest.getPartitionGranularity(), CompressionMode.NONE, configService.getPVNameToKeyConverter()); assertTrue("testLargeLines returns null for getAllFilesForPV for " + pvName, allPaths != null); assertTrue("testLargeLines returns empty array for getAllFilesForPV for " + pvName, allPaths.length > 0); for (Path destPath : allPaths) { try { PBFileInfo info = new PBFileInfo(destPath); info.getLastEventEpochSeconds(); assertTrue("File validation failed for " + destPath.toAbsolutePath().toString(), ValidatePBFile.validatePBFile(destPath, false)); } catch (Exception ex) { logger.error("Exception parsing file" + destPath.toAbsolutePath().toString(), ex); fail(ex.getMessage()); } } }
From source file:com.wwidesigner.geometry.calculation.DefaultHoleCalculator.java
public TransferMatrix calcTransferMatrix_2010(Hole hole, boolean isOpen, double waveNumber, PhysicalParameters parameters) { double radius = mFudgeFactor * hole.getDiameter() / 2; double boreRadius = hole.getBoreDiameter() / 2; Complex Zs = null;/*from w w w.j a v a 2 s . c o m*/ Complex Za = null; // double Z0 = parameters.calcZ0(boreRadius); double Z0h = parameters.calcZ0(radius); double delta = radius / boreRadius; double tm = (radius * delta / 8.) * (1. + 0.207 * delta * delta * delta); double te = hole.getHeight() + tm; double ta = 0.; // Complex Gamma = Complex.I.multiply(wave_number); if (isOpen) // open { double kb = waveNumber * radius; double ka = waveNumber * boreRadius; double xhi = 0.25 * kb * kb; ta = (-0.35 + 0.06 * Math.tanh(2.7 * hole.getHeight() / radius)) * radius * delta * delta * delta * delta; Complex Zr = Complex.I.multiply(waveNumber * 0.61 * radius).add(xhi); Complex Zo = (Zr.multiply(Math.cos(waveNumber * te)).add(Complex.I.multiply(Math.sin(waveNumber * te)))) .divide(Complex.I.multiply(Zr).multiply(Math.sin(waveNumber * te)) .add(Math.cos(waveNumber * te))); double ti = radius * (0.822 - 0.10 * delta - 1.57 * delta * delta + 2.14 * delta * delta * delta - 1.6 * delta * delta * delta * delta + 0.50 * delta * delta * delta * delta * delta) * (1. + (1. - 4.56 * delta + 6.55 * delta * delta) * (0.17 * ka + 0.92 * ka * ka + 0.16 * ka * ka * ka - 0.29 * ka * ka * ka * ka)); Zs = Complex.I.multiply(waveNumber * ti).add(Zo).multiply(Z0h); } else { ta = (-0.12 - 0.17 * Math.tanh(2.4 * hole.getHeight() / radius)) * radius * delta * delta * delta * delta; Zs = Complex.valueOf(0, -Z0h / Math.tan(waveNumber * te)); } Za = Complex.I.multiply(Z0h * waveNumber * ta); Complex Za_Zs = Za.divide(Zs); TransferMatrix result = new TransferMatrix(Za_Zs.divide(2.).add(1.), Za.multiply(Za_Zs.divide(4.).add(1.)), Complex.ONE.divide(Zs), Za_Zs.divide(2.0).add(1.)); assert result.determinant() == Complex.ONE; return result; }
From source file:com.androidquery.simplefeed.data.Place.java
public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; int meterConversion = 1609; return new Double(dist * meterConversion); }
From source file:com.opengamma.analytics.math.minimization.NonLinearTransformFunctionTest.java
@Test public void testNullTransform() { BitSet fixed = new BitSet(); fixed.set(0);//from w ww. j av a2 s.c o m DoubleMatrix1D start = new DoubleMatrix1D(new double[] { Math.PI / 4, 1 }); UncoupledParameterTransforms transforms = new UncoupledParameterTransforms(start, NULL_TRANSFORMS, fixed); NonLinearTransformFunction transFunc = new NonLinearTransformFunction(FUNCTION, JACOBIAN, transforms); Function1D<DoubleMatrix1D, DoubleMatrix1D> func = transFunc.getFittingFunction(); Function1D<DoubleMatrix1D, DoubleMatrix2D> jacFunc = transFunc.getFittingJacobian(); DoubleMatrix1D x = new DoubleMatrix1D(new double[] { 0.5 }); final double rootHalf = Math.sqrt(0.5); DoubleMatrix1D y = func.evaluate(x); assertEquals(3, y.getNumberOfElements()); assertEquals(rootHalf * Math.cos(0.5), y.getEntry(0), 1e-9); assertEquals(rootHalf * Math.sin(0.5), y.getEntry(1), 1e-9); assertEquals(rootHalf, y.getEntry(2), 1e-9); DoubleMatrix2D jac = jacFunc.evaluate(x); assertEquals(3, jac.getNumberOfRows()); assertEquals(1, jac.getNumberOfColumns()); assertEquals(-rootHalf * Math.sin(0.5), jac.getEntry(0, 0), 1e-9); assertEquals(rootHalf * Math.cos(0.5), jac.getEntry(1, 0), 1e-9); assertEquals(0, jac.getEntry(2, 0), 1e-9); }