Example usage for org.apache.commons.math3.util FastMath cos

List of usage examples for org.apache.commons.math3.util FastMath cos

Introduction

In this page you can find the example usage for org.apache.commons.math3.util FastMath cos.

Prototype

public static double cos(double x) 

Source Link

Document

Cosine function.

Usage

From source file:cc.redberry.core.number.ComplexUtils.java

/**
 * Numeric cosine form complex number.//from www.  j  ava  2s  .c  o  m
 *
 * @param complex argument
 * @return cosine
 */
public static Complex cos(Complex complex) {
    if (complex.isReal())
        return new Complex(FastMath.cos(complex.getReal().doubleValue()));
    return new Complex(new org.apache.commons.math3.complex.Complex(complex.getReal().doubleValue(),
            complex.getImaginary().doubleValue()).cos());
}

From source file:com.tussle.main.Utility.java

public static double[] getXYfromDM(double direction, double magnitude) {
    double[] returnVect = new double[2];
    returnVect[0] = magnitude * FastMath.cos(FastMath.toRadians(direction));
    returnVect[1] = magnitude * FastMath.sin(FastMath.toDegrees(direction));
    return returnVect;
}

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Cheb.java

public static double[] cheb(int n, double[] x) {

    if (n <= 0) {
        throw new IllegalArgumentException("cheb: n has to be a positive integer");
    }//from ww  w. j a  v a 2 s.c om

    if (x.length == 0) {
        return new double[0];
    }
    //# avoid resizing latencies
    double[] T = new double[x.length];
    for (int i = 0; i < x.length; i++) {
        if (Math.abs(x[i]) > 1) {
            T[i] = FastMath.cos(n * FastMath.acos(x[i]));
        } else {
            T[i] = FastMath.cosh(n * FastMath.acosh(x[i]));
        }
    }
    return T;
}

From source file:com.tussle.collision.CollisionCorner.java

public CollisionCorner(double x, double y, double min, double max) {
    this.x = x;//from  w  ww. j  a va 2s  .c  om
    this.y = y;
    minVec = new ProjectionVector(FastMath.cos(FastMath.toRadians(min)), FastMath.sin(FastMath.toRadians(min)),
            1);
    maxVec = new ProjectionVector(FastMath.cos(FastMath.toRadians(max)), FastMath.sin(FastMath.toRadians(max)),
            1);
}

From source file:edu.unc.cs.gamma.rvo.Circle.java

private void setupScenario() {
    // Specify the global time step of the simulation.
    Simulator.instance.setTimeStep(0.25);

    // Specify the default parameters for agents that are subsequently
    // added.//from  ww  w.  ja  v  a  2 s  .co m
    Simulator.instance.setAgentDefaults(15.0, 10, 10.0, 10.0, 1.5, 2.0, Vector2D.ZERO);

    // Add agents, specifying their start position, and store their goals on
    // the opposite side of the environment.
    final double angle = 0.008 * FastMath.PI;

    for (int i = 0; i < 250; i++) {
        Simulator.instance
                .addAgent(new Vector2D(FastMath.cos(i * angle), FastMath.sin(i * angle)).scalarMultiply(200.0));
        goals.add(Simulator.instance.getAgentPosition(i).negate());
    }
}

From source file:net.nicoulaj.benchmarks.math.DoubleCos.java

@GenerateMicroBenchmark
public void commonsmath(BlackHole hole) {
    for (int i = 0; i < data.length - 1; i++)
        hole.consume(FastMath.cos(data[i]));
}

From source file:com.wwidesigner.geometry.calculation.DefaultFippleMouthpieceCalculator.java

@Override
protected TransferMatrix calcTransferMatrix(Mouthpiece mouthpiece, double waveNumber,
        PhysicalParameters parameters) {
    if (mouthpiece.isPressureNode()) {
        // Resort to default if this is not a flow-node mouthpiece.
        return super.calcTransferMatrix(mouthpiece, waveNumber, parameters);
    }//from   ww  w  .j a va  2  s  . c  o  m
    // Use a simplified version of PhysicalParameters: no editable pressure
    // nor CO2 concentration. This mouthpiece representation gives very
    // wrong answers when they are varied.
    // The SimplePhysicalParameters gives correct answers for varying
    // temperature and humidity, all that a NAF maker is likely to measure.
    mParams = new SimplePhysicalParameters(parameters);

    double radius = 0.5 * mouthpiece.getBoreDiameter();
    double z0 = parameters.calcZ0(radius);
    double omega = waveNumber * parameters.getSpeedOfSound();
    double k_delta_l = calcKDeltaL(mouthpiece, omega, z0);
    // Add a series resistance for radiation loss.
    double r_rad = Tube.calcR(omega / (2 * Math.PI), radius, parameters);
    double cos_kl = FastMath.cos(k_delta_l);
    double sin_kl = FastMath.sin(k_delta_l);

    Complex A = new Complex(cos_kl, r_rad * sin_kl / z0);
    Complex B = new Complex(0., 1.).multiply(sin_kl * z0).add(r_rad * cos_kl);
    Complex C = new Complex(0., 1.).multiply(sin_kl / z0);
    Complex D = new Complex(cos_kl);
    return new TransferMatrix(A, B, C, D);
}

From source file:lambertmrev.conversions.java

public static Vector3D radec2geo(Tracklet tracklet, double rho, TopocentricFrame staF, Frame inertialFrame,
        TimeScale utc) {/*from w  w w  . java  2 s.  c  om*/

    double rho_k = rho * FastMath.sin(tracklet.getDEC());
    double rho_j = rho * FastMath.cos(tracklet.getDEC()) * FastMath.sin(tracklet.getRA());
    double rho_i = rho * FastMath.cos(tracklet.getDEC()) * FastMath.cos(tracklet.getRA());

    Vector3D rho_vec = new Vector3D(rho_i, rho_j, rho_k);
    //        System.out.println("rho used: " +  rho_vec);

    AbsoluteDate year = new AbsoluteDate(Main.YEAR, utc);
    AbsoluteDate epoch = new AbsoluteDate(year, tracklet.getDOY() * 24 * 3600);

    Vector3D out = new Vector3D(0, 0, 0);

    try {
        //            System.out.println("at epoch " + epoch + "\t the station is at: " + staF.getPVCoordinates(epoch, inertialFrame).getPosition());
        out = rho_vec.add(staF.getPVCoordinates(epoch, inertialFrame).getPosition());
    } catch (OrekitException e) {
        System.out.println("station coordinates not computed");
    }

    return out;
}

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Cheby2.java

private Cheby2(int n, double Rs, double[] W, boolean digital, boolean stop) {
    super(W, digital, stop);

    if (Rs < 0) {
        throw new IllegalArgumentException("cheby2: stopband attenuation must be positive decibels");
    }/*from  w  w w  .  j av a2  s .  c  o m*/

    this.Rs = Rs;

    //## Generate splane poles and zeros for the chebyshev type 2 filter
    //## From: Stearns, SD; David, RA; (1988). Signal Processing Algorithms.
    //##       New Jersey: Prentice-Hall.
    int C = 1; //# default cutoff frequency
    final double lambda = FastMath.pow(10, Rs / 20);
    final double phi = FastMath.log(lambda + FastMath.sqrt(FastMath.pow(lambda, 2) - 1)) / n;
    final double[] theta = new double[n];
    final double[] alpha = new double[n];
    final double[] beta = new double[n];

    for (int i = 0; i < n; i++) {
        theta[i] = FastMath.PI * (i + 0.5) / n;
        alpha[i] = -FastMath.sinh(phi) * FastMath.sin(theta[i]);
        beta[i] = FastMath.cosh(phi) * FastMath.cos(theta[i]);
    }
    final Complex IMAG_ONE = new Complex(0.0, 1);
    if (n % 2 != 0) {
        //## drop theta==pi/2 since it results in a zero at infinity
        zero = new Complex[n - 1];
        for (int i = 0; i < n / 2; i++) {
            zero[i] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
        for (int i = n / 2 + 1; i < n; i++) {
            zero[i - 1] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
    } else {
        zero = new Complex[n];
        for (int i = 0; i < n; i++) {
            zero[i] = IMAG_ONE.multiply(C / FastMath.cos(theta[i]));
        }
    }
    pole = new Complex[n];
    for (int i = 0; i < n; i++) {
        pole[i] = new Complex(C / (FastMath.pow(alpha[i], 2) + FastMath.pow(beta[i], 2)))
                .multiply(new Complex(alpha[i], -beta[i]));
    }

    /*
    ## Compensate for amplitude at s=0
    ## Because of the vagaries of floating point computations, the
    ## prod(pole)/prod(zero) sometimes comes out as negative and
    ## with a small imaginary component even though analytically
    ## the gain will always be positive, hence the abs(real(...))
     */
    gain = FastMath.abs(OctaveBuildIn.prod(pole).divide(OctaveBuildIn.prod(zero)).getReal());
}

From source file:com.bc.jexp.impl.DefaultNamespace.java

private void registerDefaultFunctions() {
    registerFunction(new AbstractFunction.D("sin", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return FastMath.sin(args[0].evalD(env));
        }//from  w ww  .  j av a 2 s.  c o m
    });
    registerFunction(new AbstractFunction.D("cos", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return FastMath.cos(args[0].evalD(env));
        }
    });
    registerFunction(new AbstractFunction.D("tan", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return FastMath.tan(args[0].evalD(env));
        }
    });
    registerFunction(new AbstractFunction.D("asin", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return FastMath.asin(args[0].evalD(env));
        }
    });
    registerFunction(new AbstractFunction.D("acos", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return FastMath.acos(args[0].evalD(env));
        }
    });
    registerFunction(new AbstractFunction.D("atan", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return FastMath.atan(args[0].evalD(env));
        }
    });
    registerFunction(new AbstractFunction.D("atan2", 2) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return Math.atan2(args[0].evalD(env), args[1].evalD(env));
        }
    });
    registerFunction(new AbstractFunction.D("log", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return Math.log(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("log10", 1) {
        public double evalD(EvalEnv env, Term[] args) throws EvalException {
            return Math.log10(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("exp", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return FastMath.exp(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("exp10", 1) {

        public double evalD(EvalEnv env, Term[] args) throws EvalException {
            return FastMath.pow(10.0, args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("sqr", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            double v = args[0].evalD(env);
            return v * v;
        }
    });

    registerFunction(new AbstractFunction.D("sqrt", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return Math.sqrt(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("pow", 2) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return FastMath.pow(args[0].evalD(env), args[1].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.I("min", 2) {

        public int evalI(final EvalEnv env, final Term[] args) {
            return Math.min(args[0].evalI(env), args[1].evalI(env));
        }
    });

    registerFunction(new AbstractFunction.D("min", 2) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return Math.min(args[0].evalD(env), args[1].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.I("max", 2) {

        public int evalI(final EvalEnv env, final Term[] args) {
            return Math.max(args[0].evalI(env), args[1].evalI(env));
        }
    });

    registerFunction(new AbstractFunction.D("max", 2) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return Math.max(args[0].evalD(env), args[1].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("floor", 1) {
        public double evalD(EvalEnv env, Term[] args) throws EvalException {
            return Math.floor(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("round", 1) {
        public double evalD(EvalEnv env, Term[] args) throws EvalException {
            return Math.round(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("ceil", 1) {
        public double evalD(EvalEnv env, Term[] args) throws EvalException {
            return Math.ceil(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("rint", 1) {
        public double evalD(EvalEnv env, Term[] args) throws EvalException {
            return Math.rint(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.I("sign", 1) {

        public int evalI(final EvalEnv env, final Term[] args) {
            return ExtMath.sign(args[0].evalI(env));
        }
    });

    registerFunction(new AbstractFunction.D("sign", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return ExtMath.sign(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.I("abs", 1) {

        public int evalI(final EvalEnv env, final Term[] args) {
            return Math.abs(args[0].evalI(env));
        }
    });

    registerFunction(new AbstractFunction.D("abs", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return Math.abs(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("deg", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return Math.toDegrees(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("rad", 1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            return Math.toRadians(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("ampl", 2) {

        public double evalD(final EvalEnv env, final Term[] args) {
            final double a = args[0].evalD(env);
            final double b = args[1].evalD(env);
            return Math.sqrt(a * a + b * b);
        }
    });

    registerFunction(new AbstractFunction.D("phase", 2) {

        public double evalD(final EvalEnv env, final Term[] args) {
            final double a = args[0].evalD(env);
            final double b = args[1].evalD(env);
            return Math.atan2(b, a);
        }
    });

    registerFunction(new AbstractFunction.B("feq", 2) {
        public boolean evalB(EvalEnv env, Term[] args) throws EvalException {
            final double x1 = args[0].evalD(env);
            final double x2 = args[1].evalD(env);
            return ExtMath.feq(x1, x2, EPS);
        }
    });

    registerFunction(new AbstractFunction.B("feq", 3) {
        public boolean evalB(EvalEnv env, Term[] args) throws EvalException {
            final double x1 = args[0].evalD(env);
            final double x2 = args[1].evalD(env);
            final double eps = args[2].evalD(env);
            return ExtMath.feq(x1, x2, eps);
        }
    });

    registerFunction(new AbstractFunction.B("fneq", 2) {
        public boolean evalB(EvalEnv env, Term[] args) throws EvalException {
            final double x1 = args[0].evalD(env);
            final double x2 = args[1].evalD(env);
            return ExtMath.fneq(x1, x2, EPS);
        }
    });

    registerFunction(new AbstractFunction.B("fneq", 3) {
        public boolean evalB(EvalEnv env, Term[] args) throws EvalException {
            final double x1 = args[0].evalD(env);
            final double x2 = args[1].evalD(env);
            final double eps = args[2].evalD(env);
            return ExtMath.fneq(x1, x2, eps);
        }
    });

    registerFunction(new AbstractFunction.B("inf", 1) {
        public boolean evalB(EvalEnv env, Term[] args) throws EvalException {
            return Double.isInfinite(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.B("nan", 1) {
        public boolean evalB(EvalEnv env, Term[] args) throws EvalException {
            return Double.isNaN(args[0].evalD(env));
        }
    });

    registerFunction(new AbstractFunction.D("distance", -1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            double sqrSum = 0.0;
            final int n = args.length / 2;
            for (int i = 0; i < n; i++) {
                final double v = args[i + n].evalD(env) - args[i].evalD(env);
                sqrSum += v * v;
            }
            return Math.sqrt(sqrSum);
        }
    });

    registerFunction(new AbstractFunction.D("distance_deriv", -1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            double sqrSum = 0.0;
            final int n = args.length / 2;
            for (int i = 0; i < n - 1; i++) {
                final double v1 = args[i + 1].evalD(env) - args[i].evalD(env);
                final double v2 = args[i + n + 1].evalD(env) - args[i + n].evalD(env);
                sqrSum += (v1 - v2) * (v1 - v2);
            }
            return Math.sqrt(sqrSum);
        }
    });

    registerFunction(new AbstractFunction.D("distance_integ", -1) {

        public double evalD(final EvalEnv env, final Term[] args) {
            double sqrSum = 0.0;
            double v1Sum = 0.0;
            double v2Sum = 0.0;
            final int n = args.length / 2;
            for (int i = 0; i < n; i++) {
                v1Sum += args[i].evalD(env);
                v2Sum += args[i + n].evalD(env);
                sqrSum += (v2Sum - v1Sum) * (v2Sum - v1Sum);
            }
            return Math.sqrt(sqrSum);
        }
    });

    registerFunction(new AbstractFunction.B("inrange", -1) {

        public boolean evalB(final EvalEnv env, final Term[] args) {
            final int n1 = args.length / 3;
            final int n2 = n1 + args.length / 3;
            for (int i = 0; i < n1; i++) {
                final double v = args[i].evalD(env);
                final double v1 = args[i + n1].evalD(env);
                final double v2 = args[i + n2].evalD(env);
                if (v < v1 || v > v2) {
                    return false;
                }
            }
            return true;
        }
    });

    registerFunction(new AbstractFunction.B("inrange_deriv", -1) {

        public boolean evalB(final EvalEnv env, final Term[] args) {
            final int n1 = args.length / 3;
            final int n2 = 2 * n1;
            for (int i = 0; i < n1 - 1; i++) {
                final double v = args[i + 1].evalD(env) - args[i].evalD(env);
                final double v1 = args[i + n1 + 1].evalD(env) - args[i + n1].evalD(env);
                final double v2 = args[i + n2 + 1].evalD(env) - args[i + n2].evalD(env);
                if (v < v1 || v > v2) {
                    return false;
                }
            }
            return true;
        }
    });

    registerFunction(new AbstractFunction.B("inrange_integ", -1) {

        public boolean evalB(final EvalEnv env, final Term[] args) {
            final int n1 = args.length / 3;
            final int n2 = 2 * n1;
            double vSum = 0.0;
            double v1Sum = 0.0;
            double v2Sum = 0.0;
            for (int i = 0; i < n1; i++) {
                vSum += args[i].evalD(env);
                v1Sum += args[i + n1].evalD(env);
                v2Sum += args[i + n2].evalD(env);
                if (vSum < v1Sum || vSum > v2Sum) {
                    return false;
                }
            }
            return true;
        }
    });

}