List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:com.hurence.tmp.FFT.java
public static Complex[] fft(Complex[] x) { int N = x.length; // base case/*from w w w . j av a2 s. c o m*/ if (N == 1) { return new Complex[] { x[0] }; } // radix 2 Cooley-Tukey FFT if (N % 2 != 0) { throw new RuntimeException("N is not a power of 2"); } // fft of even terms Complex[] even = new Complex[N / 2]; for (int k = 0; k < N / 2; k++) { even[k] = x[2 * k]; } Complex[] q = fft(even); // fft of odd terms Complex[] odd = even; // reuse the array for (int k = 0; k < N / 2; k++) { odd[k] = x[2 * k + 1]; } Complex[] r = fft(odd); // combine Complex[] y = new Complex[N]; for (int k = 0; k < N / 2; k++) { double kth = -2 * k * Math.PI / N; Complex wk = new Complex(Math.cos(kth), Math.sin(kth)); y[k] = q[k].add(wk.multiply(r[k])); y[k + N / 2] = q[k].subtract(wk.multiply(r[k])); } return y; }
From source file:geogebra.util.MyMath.java
final public static double sec(double a) { return 1 / Math.cos(a); }
From source file:Main.java
private static BufferedImage createRotatedImage(Object src, int width, int height, int angle) { angle = angle % 360;/*from ww w. j a v a2s . com*/ if (angle < 0) { angle += 360; } if (angle == 0) { return renderRotatedObject(src, 0, width, height, 0, 0); } else if (angle == 90) { return renderRotatedObject(src, -Math.PI / 2, height, width, -width, 0); } else if (angle == 180) { return renderRotatedObject(src, Math.PI, width, height, -width, -height); } else if (angle == 270) { return renderRotatedObject(src, Math.PI / 2, height, width, 0, -height); } else if (angle > 0 && angle < 90) { double angleInRadians = ((-angle * Math.PI) / 180.0); double cosTheta = Math.abs(Math.cos(angleInRadians)); double sineTheta = Math.abs(Math.sin(angleInRadians)); int dW = (int) (width * cosTheta + height * sineTheta); int dH = (int) (width * sineTheta + height * cosTheta); return renderRotatedObject(src, angleInRadians, dW, dH, -width * sineTheta * sineTheta, width * sineTheta * cosTheta); } else if (angle > 90 && angle < 180) { double angleInRadians = ((-angle * Math.PI) / 180.0); double cosTheta = Math.abs(Math.cos(angleInRadians)); double sineTheta = Math.abs(Math.sin(angleInRadians)); int dW = (int) (width * cosTheta + height * sineTheta); int dH = (int) (width * sineTheta + height * cosTheta); return renderRotatedObject(src, angleInRadians, dW, dH, -(width + height * sineTheta * cosTheta), -height / 2); } else if (angle > 180 && angle < 270) { double angleInRadians = ((-angle * Math.PI) / 180.0); double cosTheta = Math.abs(Math.cos(angleInRadians)); double sineTheta = Math.abs(Math.sin(angleInRadians)); int dW = (int) (width * cosTheta + height * sineTheta); int dH = (int) (width * sineTheta + height * cosTheta); return renderRotatedObject(src, angleInRadians, dW, dH, -(width * cosTheta * cosTheta), -(height + width * cosTheta * sineTheta)); } else if (angle > 270 && angle < 360) { double angleInRadians = ((-angle * Math.PI) / 180.0); double cosTheta = Math.abs(Math.cos(angleInRadians)); double sineTheta = Math.abs(Math.sin(angleInRadians)); int dW = (int) (width * cosTheta + height * sineTheta); int dH = (int) (width * sineTheta + height * cosTheta); return renderRotatedObject(src, angleInRadians, dW, dH, (height * cosTheta * sineTheta), -(height * sineTheta * sineTheta)); } return renderRotatedObject(src, 0, width, height, 0, 0); }
From source file:IK.G.java
public static double cos(double in) { return Math.cos(in); }
From source file:geogebra.util.MyMath.java
final public static double cot(double a) { return Math.cos(a) / Math.sin(a); }
From source file:com.opengamma.analytics.math.rootfinding.CubicRootFinder.java
/** * {@inheritDoc}//from w w w . j a va2 s . c o m * @throws IllegalArgumentException If the function is not cubic */ @Override public ComplexNumber[] getRoots(final RealPolynomialFunction1D function) { Validate.notNull(function, "function"); final double[] coefficients = function.getCoefficients(); Validate.isTrue(coefficients.length == 4, "Function is not a cubic"); final double divisor = coefficients[3]; final double a = coefficients[2] / divisor; final double b = coefficients[1] / divisor; final double c = coefficients[0] / divisor; final double aSq = a * a; final double q = (aSq - 3 * b) / 9; final double r = (2 * a * aSq - 9 * a * b + 27 * c) / 54; final double rSq = r * r; final double qCb = q * q * q; final double constant = a / 3; if (rSq < qCb) { final double mult = -2 * Math.sqrt(q); final double theta = Math.acos(r / Math.sqrt(qCb)); return new ComplexNumber[] { new ComplexNumber(mult * Math.cos(theta / 3) - constant, 0), new ComplexNumber(mult * Math.cos((theta + TWO_PI) / 3) - constant, 0), new ComplexNumber(mult * Math.cos((theta - TWO_PI) / 3) - constant, 0) }; } final double s = -Math.signum(r) * Math.cbrt(Math.abs(r) + Math.sqrt(rSq - qCb)); final double t = CompareUtils.closeEquals(s, 0, 1e-16) ? 0 : q / s; final double sum = s + t; final double real = -0.5 * sum - constant; final double imaginary = Math.sqrt(3) * (s - t) / 2; return new ComplexNumber[] { new ComplexNumber(sum - constant, 0), new ComplexNumber(real, imaginary), new ComplexNumber(real, -imaginary) }; }
From source file:de.tuberlin.uebb.jdae.diff.partial.PDOperations.java
public final void sin(final double[] values, final double[] target) { compose(Math.sin(values[0]), Math.cos(values[0]), values, target); }
From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.RastriginFunction.java
@Override public double map(RealVector v) { double fx = Double.NaN; double[] x = v.toArray(); int n = x.length; fx = 10 * n;/*from ww w. j av a2s . co m*/ for (int i = 0; i < n; i++) { fx += x[i] * x[i] - 10 * Math.cos(2 * Math.PI * x[i]); } return fx; }
From source file:dnimp.Statistics.java
private double studT(double t, int n) { t = Math.abs(t);/*from w w w. j a va 2 s . c o m*/ double th = Math.atan(t / Math.sqrt(n)); double sth = Math.sin(th); double cth = Math.cos(th); if (n == 1) return 1 - th / (Math.PI / 2.0); if (n % 2 == 1) { return 1 - (th + sth * cth * statCom(cth * cth, 2, n - 3, -1)) / (Math.PI / 2.0); } else { return 1 - sth * statCom(cth * cth, 1, n - 3, -1); } }
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// w ww. ja 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"); }