List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:com.cloudmade.api.Utils.java
/** * Convert latitude, longitude pair to tile coordinates * /*from ww w .j a v a 2s. c om*/ * @param latitude * @param longitude * @param zoom * @return Tile coordinates [x, y] */ public static final int[] latlon2tilenums(double latitude, double longitude, int zoom) { int factor = 1 << (zoom - 1); latitude = Math.toRadians(latitude); longitude = Math.toRadians(longitude); double xtile = 1 + longitude / Math.PI; double ytile = 1 - Math.log(Math.tan(latitude) + (1 / Math.cos(latitude))) / Math.PI; return new int[] { (int) (xtile * factor), (int) (ytile * factor) }; }
From source file:Main.java
/** * Given two angles in degrees, determine the smallest angle between them. * * For example, given angles 90 and 170, the smallest angle difference would be 80 * and the larger angle difference would be 280. * * @param firstAngleDeg/*from w w w . j a v a 2 s . c o m*/ * @param secondAngleDeg * @return smallest angle */ public static double smallestAngularDifferenceDegrees(double firstAngleDeg, double secondAngleDeg) { double rawDiffDeg = firstAngleDeg - secondAngleDeg; double rawDiffRad = rawDiffDeg * Math.PI / 180; double wrappedDiffRad = Math.atan2(Math.sin(rawDiffRad), Math.cos(rawDiffRad)); double wrappedDiffDeg = wrappedDiffRad * 180 / Math.PI; return wrappedDiffDeg; }
From source file:edu.ucsf.valelab.saim.calculations.SaimCalc.java
/** * Calculates the phase difference as a function of height as described in: * Paszek, M.J., C.C. DuFort, M.G. Rubashkin, M.W. Davidson, K.S. Thorn, J.T. * Liphardt, and V.M. Weaver. 2012. // www. ja v a 2s. c o m * Scanning angle interference microscopy reveals cell dynamics at the nanoscale. * Nat Meth. 9:825827. doi:10.1038/nmeth.2077. * * @param wavelength of the excitation light source in nm * @param nSample refractive index of the sample medium * @param angle Angle with respect to the normal in the sample in radians * @param axialPos Position in the sample above the silicon oxide (in nm) * @return phase difference (dimensionless) */ public static double PhaseDiff(final double wavelength, final double angle, final double nSample, final double axialPos) { return 4.0 * Math.PI * nSample * axialPos * Math.cos(angle) / wavelength; }
From source file:com.mapr.synth.drive.GeoPoint.java
public GeoPoint(double latitude, double longitude) { double c = Math.cos(latitude); r = new Vector3D(Math.cos(longitude) * c, Math.sin(longitude) * c, Math.sin(latitude)); }
From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.GriewankFunction.java
@Override public double map(RealVector v) { double[] x = v.toArray(); double sum = 0.0; double prod = 1.0; for (int i = 0; i < x.length; i++) { sum += x[i] * x[i] / 4000;/* w w w . jav a 2 s . c o m*/ prod *= Math.cos(x[i] / Math.sqrt(i + 1)); } return sum - prod + 1; }
From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.AckleyFunction.java
@Override public double map(RealVector v) { double[] x = v.toArray(); int n = x.length; double sum1 = 0.0, sum2 = 0.0; for (int i = 0; i < n; i++) { sum1 += x[i] * x[i];/*from w w w .j a v a 2 s . co m*/ sum2 += Math.cos(2 * Math.PI * x[i]); } double fx = -20 * Math.exp(-0.2 * Math.sqrt(sum1 / n)) - Math.exp(sum2 / n) + 20 + Math.E; return fx; }
From source file:Clock.java
public void paint(Graphics g) { int xhour, yhour, xminute, yminute, xsecond, ysecond, second, minute, hour; drawStructure(g);/*from w ww. j av a2s. c o m*/ currentDate = new Date(); formatter.applyPattern("s"); second = Integer.parseInt(formatter.format(currentDate)); formatter.applyPattern("m"); minute = Integer.parseInt(formatter.format(currentDate)); formatter.applyPattern("h"); hour = Integer.parseInt(formatter.format(currentDate)); xsecond = (int) (Math.cos(second * 3.14f / 30 - 3.14f / 2) * 45 + xcenter); ysecond = (int) (Math.sin(second * 3.14f / 30 - 3.14f / 2) * 45 + ycenter); xminute = (int) (Math.cos(minute * 3.14f / 30 - 3.14f / 2) * 40 + xcenter); yminute = (int) (Math.sin(minute * 3.14f / 30 - 3.14f / 2) * 40 + ycenter); xhour = (int) (Math.cos((hour * 30 + minute / 2) * 3.14f / 180 - 3.14f / 2) * 30 + xcenter); yhour = (int) (Math.sin((hour * 30 + minute / 2) * 3.14f / 180 - 3.14f / 2) * 30 + ycenter); // Erase if necessary, and redraw g.setColor(Color.lightGray); if (xsecond != lastxs || ysecond != lastys) { g.drawLine(xcenter, ycenter, lastxs, lastys); } if (xminute != lastxm || yminute != lastym) { g.drawLine(xcenter, ycenter - 1, lastxm, lastym); g.drawLine(xcenter - 1, ycenter, lastxm, lastym); } if (xhour != lastxh || yhour != lastyh) { g.drawLine(xcenter, ycenter - 1, lastxh, lastyh); g.drawLine(xcenter - 1, ycenter, lastxh, lastyh); } g.setColor(Color.darkGray); g.drawLine(xcenter, ycenter, xsecond, ysecond); g.setColor(Color.red); g.drawLine(xcenter, ycenter - 1, xminute, yminute); g.drawLine(xcenter - 1, ycenter, xminute, yminute); g.drawLine(xcenter, ycenter - 1, xhour, yhour); g.drawLine(xcenter - 1, ycenter, xhour, yhour); lastxs = xsecond; lastys = ysecond; lastxm = xminute; lastym = yminute; lastxh = xhour; lastyh = yhour; }
From source file:Main.java
private static float transformAngle(Matrix m, float angleRadians) { // Construct and transform a vector oriented at the specified clockwise // angle from vertical. Coordinate system: down is increasing Y, right is // increasing X. float[] v = new float[2]; v[0] = (float) Math.sin(angleRadians); v[1] = (float) -Math.cos(angleRadians); m.mapVectors(v);//from www . j av a 2s. com // Derive the transformed vector's clockwise angle from vertical. float result = (float) Math.atan2(v[0], -v[1]); if (result < -Math.PI / 2) { result += Math.PI; } else if (result > Math.PI / 2) { result -= Math.PI; } return result; }
From source file:com.offbynull.peernetic.debug.visualizer.VisualizerUtils.java
/** * Creates point on a circle./* w ww . j ava 2 s . com*/ * @param radius radius of circle * @param percentage 0 to 1 percentage of where point is on circle -- 0.0 indicates that the point is at the top middle * @return new point on circle specified by {@code radius} and {@code percentage} * @throws IllegalArgumentException if {@code radius} is negative or a special double value (e.g. NaN/infinite/etc..), or if * {@code percentage} isn't between {@code 0.0 - 1.0} */ public static Point pointOnCircle(double radius, double percentage) { Validate.inclusiveBetween(0.0, Double.MAX_VALUE, radius); Validate.inclusiveBetween(0.0, 1.0, percentage); double angle = percentage * Math.PI * 2.0; angle -= Math.PI / 2.0; // adjust so that percentage 0.0 is at top middle, if not it'ld be at middle right double y = (Math.sin(angle) * radius) + radius; // NOPMD double x = (Math.cos(angle) * radius) + radius; // NOPMD return new Point((int) x, (int) y); }
From source file:fsm.series.Series_SS.java
@Override public double getFirstDerivativeValue(double y, int m) { return Math.cos(m * Math.PI * y / a) * m * Math.PI / a; }