List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:demo.support.NavUtils.java
/** * Returns bearing of position 2 from position 1. * @param pt1/*from w w w.j a v a 2s. c o m*/ * @param pt2 * @return */ public static double getBearing(Point pt1, Point pt2) { double longitude1 = pt1.getLongitude(); double longitude2 = pt2.getLongitude(); double latitude1 = Math.toRadians(pt1.getLatitude()); double latitude2 = Math.toRadians(pt2.getLatitude()); double longDiff = Math.toRadians(longitude2 - longitude1); double y = Math.sin(longDiff) * Math.cos(latitude2); double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff); return (Math.toDegrees(Math.atan2(y, x)) + 360) % 360; }
From source file:DrawShapes_2008.java
/** * Generates a star Shape from the given location, radii, and points * parameters. The Shape is created by constructing a GeneralPath * that moves between the inner and outer rings. *//* ww w . j a va2 s. c o m*/ private static Shape generateStar(double x, double y, double innerRadius, double outerRadius, int pointsCount) { GeneralPath path = new GeneralPath(); double outerAngleIncrement = 2 * Math.PI / pointsCount; double outerAngle = 0.0; double innerAngle = outerAngleIncrement / 2.0; x += outerRadius; y += outerRadius; float x1 = (float) (Math.cos(outerAngle) * outerRadius + x); float y1 = (float) (Math.sin(outerAngle) * outerRadius + y); float x2 = (float) (Math.cos(innerAngle) * innerRadius + x); float y2 = (float) (Math.sin(innerAngle) * innerRadius + y); path.moveTo(x1, y1); path.lineTo(x2, y2); outerAngle += outerAngleIncrement; innerAngle += outerAngleIncrement; for (int i = 1; i < pointsCount; i++) { x1 = (float) (Math.cos(outerAngle) * outerRadius + x); y1 = (float) (Math.sin(outerAngle) * outerRadius + y); path.lineTo(x1, y1); x2 = (float) (Math.cos(innerAngle) * innerRadius + x); y2 = (float) (Math.sin(innerAngle) * innerRadius + y); path.lineTo(x2, y2); outerAngle += outerAngleIncrement; innerAngle += outerAngleIncrement; } path.closePath(); return path; }
From source file:edu.ucsf.valelab.saim.calculations.BenchmarkCalculations.java
/** * Compares two methods to calculate the Saim function * The implementation not using Complex numbers appears to be at least * 10 times faster//from w ww.j a v a 2 s . c o m * @throws Exception */ public void test() throws Exception { long nrRuns = 100000000; double wavelength = 488.0; double nSample = 1.36; double dOx = 500.0; double h = 16.0; double angle = Math.toRadians(0.0); SaimFunction sf = new SaimFunction(wavelength, dOx, nSample, false); Complex rTE = sf.getFresnelTE(0); double f = 4.0 * Math.PI * nSample * Math.cos(angle) / wavelength; double phaseDiff = f * h; // method 1 long startTime = System.nanoTime(); double c = rTE.getReal(); double d = rTE.getImaginary(); for (int i = 0; i < nrRuns; i++) { double val = 1 + 2 * c * Math.cos(phaseDiff) - 2 * d * Math.sin(phaseDiff) + c * c + d * d; } long endTime = System.nanoTime(); long took = endTime - startTime; System.out.println("First method: " + nrRuns + " runs took: " + took / 1000000 + " milliseconds"); // method 2 startTime = System.nanoTime(); for (int i = 0; i < nrRuns; i++) { Complex tmp = new Complex(Math.cos(phaseDiff), Math.sin(phaseDiff)); Complex fieldStrength = rTE.multiply(tmp); fieldStrength = fieldStrength.add(1.0); // square of absolute double val = fieldStrength.getReal() * fieldStrength.getReal() + fieldStrength.getImaginary() * fieldStrength.getImaginary(); } endTime = System.nanoTime(); took = endTime - startTime; System.out.println("Second method: " + nrRuns + " runs took: " + took / 1000000 + " milliseconds"); }
From source file:org.eclipse.swt.examples.graphics.StarPolyTab.java
@Override public void paint(GC gc, int width, int height) { int centerX = width / 2; int centerY = height / 2; int pos = 0;//from www. j a va 2 s. c om for (int i = 0; i < POINTS; ++i) { double r = Math.PI * 2 * pos / POINTS; radial[i * 2] = (int) ((1 + Math.cos(r)) * centerX); radial[i * 2 + 1] = (int) ((1 + Math.sin(r)) * centerY); pos = (pos + POINTS / 2) % POINTS; } gc.setFillRule(fillRuleCb.getSelectionIndex() != 0 ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD); gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_YELLOW)); gc.fillPolygon(radial); gc.drawPolygon(radial); }
From source file:com.google.location.lbs.gnss.gps.pseudorange.Ecef2EnuConverter.java
/** * Computes a rotation matrix for converting a vector in Earth-Centered Earth-Fixed (ECEF) * Cartesian system into a vector in local east-north-up (ENU) Cartesian system with respect to * a reference location. The matrix has the following content: * * - sinLng cosLng 0 * - sinLat * cosLng - sinLat * sinLng cosLat * cosLat * cosLng cosLat * sinLng sinLat * * <p> Reference: Pratap Misra and Per Enge * "Global Positioning System: Signals, Measurements, and Performance" Page 137. * * @param refLat Latitude of reference location * @param refLng Longitude of reference location * @return the Ecef to Enu rotation matrix */// www . j av a2 s .c o m public static RealMatrix getRotationMatrix(double refLat, double refLng) { RealMatrix rotationMatrix = new Array2DRowRealMatrix(3, 3); // Fill in the rotation Matrix rotationMatrix.setEntry(0, 0, -1 * Math.sin(refLng)); rotationMatrix.setEntry(1, 0, -1 * Math.cos(refLng) * Math.sin(refLat)); rotationMatrix.setEntry(2, 0, Math.cos(refLng) * Math.cos(refLat)); rotationMatrix.setEntry(0, 1, Math.cos(refLng)); rotationMatrix.setEntry(1, 1, -1 * Math.sin(refLat) * Math.sin(refLng)); rotationMatrix.setEntry(2, 1, Math.cos(refLat) * Math.sin(refLng)); rotationMatrix.setEntry(0, 2, 0); rotationMatrix.setEntry(1, 2, Math.cos(refLat)); rotationMatrix.setEntry(2, 2, Math.sin(refLat)); return rotationMatrix; }
From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java
/** * // http://www.movable-type.co.uk/scripts/latlong.html * // Under Creative Commons License http://creativecommons.org/licenses/by/3.0/ * Calculate distance between two GPS co-ordinate * @param lat1/* w w w . j a v a 2 s .c om*/ * @param lon1 * @param lat2 * @param lon2 * @return */ public static double getDistanceMeters(double lat1, double lon1, double lat2, double lon2) { int r = 6371; double dLat = Math.abs(lat2 - lat1) * (Math.PI / 180); double dLon = Math.abs(lon2 - lon1) * (Math.PI / 180); double a = (Math.sin(dLat / 2) * Math.sin(dLat / 2)) + (Math.cos(lat1 * (Math.PI / 180)) * Math.cos(lat2 * (Math.PI / 180)) * Math.sin(dLon / 2) * Math.sin(dLon / 2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double d = r * c * 1000; // show as meters return Double.parseDouble(mDecimalFormat.format(d)); }
From source file:geogebra.util.MyMath.java
final public static double gamma(double x, Kernel kernel) { // Michael Borcherds 2008-05-04 if (x <= 0 && Kernel.isEqual(x, Math.round(x))) return Double.NaN; // negative integers // Michael Borcherds 2007-10-15 BEGIN added case for x<0 otherwise no // results in 3rd quadrant if (x >= 0) return Math.exp(Gamma.logGamma(x)); else//w w w . j a va2s. co m return -Math.PI / (x * gamma(-x, kernel) * Math.sin(Math.PI * x)); // Michael Borcherds 2007-10-15 END }
From source file:io.yields.math.concepts.operator.CurveLengthTest.java
@Test public void testFailoverCalculation() { Function<Double, Double> curve = x -> Math.sin(x); Assertions.assertThat(length().between(0, 2 * Math.PI).apply(curve)) .isEqualTo(length().between(0, 2 * Math.PI).simpsonIntegration(curve), Delta.delta(1.e-8)); }
From source file:com.joey.software.dsp.HilbertTransform.java
public static void getHilbert(float[] reIn, float[] imIn, float[] reOut, float[] imOut) { float[] fftRe = new float[reIn.length]; float[] fftIm = new float[reIn.length]; FastFourierTransform3 fft = new FastFourierTransform3(reIn.length); fft.fft(reIn, imIn, fftRe, fftIm);/* w w w.j a v a 2 s . c om*/ for (int n = 0; n < reIn.length; n++) { for (int k = 0; k < reIn.length; k++) { double val = 2 * Math.PI * k * n / reIn.length; reOut[k] += fftRe[k] * Math.sin(val) / reIn.length; imOut[k] += fftIm[k] * Math.cos(val) / reIn.length; } } }
From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java
/** * Calculate length of the day for a specific day * //from w ww . j a v a 2 s.c om * @param latitude * the latitude * @param day * the day * @return time in hours */ public double length(double latitude, int day) { final double p = Math .asin(.39795 * Math.cos(.2163108 + 2 * Math.atan(.9671396 * Math.tan(.00860 * (day - 186))))); return (24.0d - (24.0d / Math.PI) * Math .acos((Math.sin(0.8333d * Math.PI / 180d) + Math.sin(latitude * Math.PI / 180.0d) * Math.sin(p)) / (Math.cos(latitude * Math.PI / 180.0d) * Math.cos(p)))); }