Example usage for java.lang Math sin

List of usage examples for java.lang Math sin

Introduction

In this page you can find the example usage for java.lang Math sin.

Prototype

@HotSpotIntrinsicCandidate
public static double sin(double a) 

Source Link

Document

Returns the trigonometric sine of an angle.

Usage

From source file:gdsc.smlm.function.gaussian.EllipticalGaussian2DFunction.java

public void initialise(double[] a) {
    this.a = a;//from   w  w w .  ja  v  a  2 s  . com
    // Precalculate multiplication factors
    peakFactors = new double[npeaks][16];
    for (int j = 0; j < npeaks; j++) {
        final double theta = a[j * 6 + ANGLE];
        final double sx = a[j * 6 + X_SD];
        final double sy = a[j * 6 + Y_SD];
        final double sx2 = sx * sx;
        final double sy2 = sy * sy;
        final double sx3 = sx2 * sx;
        final double sy3 = sy2 * sy;
        final double cosSqt = Math.cos(theta) * Math.cos(theta);
        final double sinSqt = Math.sin(theta) * Math.sin(theta);
        final double sincost = Math.sin(theta) * Math.cos(theta);
        final double sin2t = Math.sin(2 * theta);
        final double cos2t = Math.cos(2 * theta);

        peakFactors[j][N] = ONE_OVER_TWO_PI / (sx * sy);
        peakFactors[j][HEIGHT] = a[j * 6 + SIGNAL] * peakFactors[j][N];

        // All prefactors are negated since the Gaussian uses the exponential to the negative:
        // (A/2*pi*sx*sy) * exp( -( a(x-x0)^2 + 2b(x-x0)(y-y0) + c(y-y0)^2 ) )

        peakFactors[j][AA] = -0.5 * (cosSqt / sx2 + sinSqt / sy2);
        peakFactors[j][BB] = -0.25 * (-sin2t / sx2 + sin2t / sy2);
        peakFactors[j][CC] = -0.5 * (sinSqt / sx2 + cosSqt / sy2);

        // For the angle gradient
        peakFactors[j][AA2] = -(-sincost / sx2 + sincost / sy2);
        peakFactors[j][BB2] = -0.5 * (-cos2t / sx2 + cos2t / sy2);
        peakFactors[j][CC2] = -(sincost / sx2 - sincost / sy2);

        // For the x-width gradient
        peakFactors[j][NX] = -1.0 / sx;
        peakFactors[j][AX] = cosSqt / sx3;
        peakFactors[j][BX] = -0.5 * sin2t / sx3;
        peakFactors[j][CX] = sinSqt / sx3;

        // For the y-width gradient
        peakFactors[j][NY] = -1.0 / sy;
        peakFactors[j][AY] = sinSqt / sy3;
        peakFactors[j][BY] = 0.5 * sin2t / sy3;
        peakFactors[j][CY] = cosSqt / sy3;
    }
}

From source file:edu.ucsf.valelab.saim.calculations.SaimErrorFunction.java

/**
 * For each observedPoint.getX calculates the predicted intensity
 * Returns the sum of absolute errors/*from  w w w  .j a va2 s  .  c  om*/
 * @param point {A, B, h}
 * @return sum of absolute errors
 */
@Override
public double value(double[] point) {
    if (point.length != 3) {
        throw new DimensionMismatchException(point.length, 3);
    }

    double A = point[0];
    double B = point[1];
    double h = point[2];

    double error = 0.0;
    for (WeightedObservedPoint observedPoint : observedPoints_) {
        double angle = observedPoint.getX();
        Complex rTE = fresnelTE_.get(angle);
        double phaseDiff = SaimCalc.PhaseDiff(data_.wavelength_, angle, data_.nSample_, h);
        double c = rTE.getReal();
        double d = rTE.getImaginary();
        double val = 1 + 2 * c * Math.cos(phaseDiff) - 2 * d * Math.sin(phaseDiff) + c * c + d * d;
        error += Math.abs(A * val + B - observedPoint.getY());
    }
    return error;
}

From source file:Main.java

public static double eval(final String str) {
    return new Object() {
        private int pos = -1, ch;

        void nextChar() {
            ch = (++pos < str.length()) ? str.charAt(pos) : -1;
        }/*from   w  w  w . j a  va  2 s . c  om*/

        boolean eat(int charToEat) {
            while (ch == ' ') {
                nextChar();
            }
            if (ch == charToEat) {
                nextChar();
                return true;
            }
            return false;
        }

        double parse() {
            nextChar();
            double x = parseExpression();
            if (pos < str.length()) {
                throw new IllegalArgumentException("Unexpected: " + (char) ch);
            }
            return x;
        }

        // Grammar:
        // expression = term | expression `+` term | expression `-` term
        // term = factor | term `*` factor | term `/` factor
        // factor = `+` factor | `-` factor | `(` expression `)`
        //        | number | functionName factor | factor `^` factor

        double parseExpression() {
            double x = parseTerm();
            for (;;) {
                if (eat('+')) {
                    x += parseTerm(); // addition
                } else {
                    if (eat('-')) {
                        x -= parseTerm(); // subtraction
                    } else {
                        return x;
                    }
                }
            }
        }

        double parseTerm() {
            double x = parseFactor();
            for (;;) {
                if (eat('*')) {
                    x *= parseFactor(); // multiplication
                } else {
                    if (eat('/')) {
                        x /= parseFactor(); // division
                    } else {
                        return x;
                    }
                }
            }
        }

        double parseFactor() {
            if (eat('+')) {
                return parseFactor(); // unary plus
            }
            if (eat('-')) {
                return -parseFactor(); // unary minus
            }

            double x;
            int startPos = this.pos;
            if (eat('(')) { // parentheses
                x = parseExpression();
                eat(')');
            } else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
                while ((ch >= '0' && ch <= '9') || ch == '.') {
                    nextChar();
                }
                x = Double.parseDouble(str.substring(startPos, this.pos));
            } else if (ch >= 'a' && ch <= 'z') { // functions
                while (ch >= 'a' && ch <= 'z') {
                    nextChar();
                }
                String func = str.substring(startPos, this.pos);
                x = parseFactor();
                switch (func) {
                case "sqrt":
                    x = Math.sqrt(x);
                    break;
                case "sin":
                    x = Math.sin(Math.toRadians(x));
                    break;
                case "cos":
                    x = Math.cos(Math.toRadians(x));
                    break;
                case "tan":
                    x = Math.tan(Math.toRadians(x));
                    break;
                default:
                    throw new IllegalArgumentException("Unknown function: " + func);
                }
            } else {
                throw new IllegalArgumentException("Unexpected: " + (char) ch);
            }

            if (eat('^')) {
                x = Math.pow(x, parseFactor()); // exponentiation
            }

            return x;
        }
    }.parse();
}

From source file:BackEnd.B_calculation.java

private FazorVektor calc_DB(DPoint Rp, DPoint R0, DPoint deltaL) throws DelaunayError {
    DPoint R_0 = new DPoint(R0.getX(), R0.getY(), R0.getZ());
    R_0.setY(R0.getY() + R0_bundleY); //  bundle korektura pre jeden druhy SMER // treba to priemetovat
    R_0.setZ(R0.getZ() + Math.cos(beta) * R0_bundleZ); // priemety
    R_0.setX(R0.getX() + Math.sin(beta) * R0_bundleZ);

    //  System.out.println( "R_0= " + R_0 );
    //  System.out.println( "Rp= " + Rp );
    ///*w w  w .ja  v  a  2  s  .  c o  m*/
    // System.out.println( "deltal= " + deltaL );
    double K = (this.mu0 * this.muR) / (4 * Math.PI); // kontanta

    DPoint R = help.substract(Rp, R_0); // rozdiel vektorov
    double menovatel = Math.pow(get_ABS(R), 3);
    FazorVektor deltaB = new FazorVektor(new Complex(0, 0), new Complex(0, 0), new Complex(0, 0));

    DPoint C = vektor_sucin(deltaL, R);

    deltaB.setX_Real(K * ((getI_real() * C.getX()) / menovatel));
    deltaB.setY_Real(K * ((getI_real() * C.getY()) / menovatel));
    deltaB.setZ_Real(K * ((getI_real() * C.getZ()) / menovatel));

    deltaB.setX_Imaginary(K * ((getI_image() * C.getX()) / menovatel));
    deltaB.setY_Imaginary(K * ((getI_image() * C.getY()) / menovatel));
    deltaB.setZ_Imaginary(K * ((getI_image() * C.getZ()) / menovatel));

    return deltaB;
}

From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java

public static ComplexNumber cosh(final ComplexNumber z) {
    Validate.notNull(z, "z");
    return new ComplexNumber(Math.cosh(z.getReal()) * Math.cos(z.getImaginary()),
            Math.sinh(z.getReal()) * Math.sin(z.getImaginary()));
}

From source file:jtrace.object.Sphere.java

@Override
public List<Vector3D[]> getWireFrameObjectFrame() {
    List<Vector3D[]> edgeList = new ArrayList<>();

    int nLongitudeLines = 50;
    int nLongitudeSteps = 20;

    for (int i = 0; i < nLongitudeLines; i++) {
        double theta = 2 * Math.PI * i / nLongitudeLines;
        for (int j = 0; j < nLongitudeSteps; j++) {
            double phi = Math.PI * j / nLongitudeSteps;
            double phiNext = Math.PI * (j + 1) / nLongitudeSteps;

            Vector3D p = new Vector3D(Math.sin(phi) * Math.cos(theta), Math.sin(phi) * Math.sin(theta),
                    Math.cos(phi));

            Vector3D pNext = new Vector3D(Math.sin(phiNext) * Math.cos(theta),
                    Math.sin(phiNext) * Math.sin(theta), Math.cos(phiNext));

            Vector3D[] edge = { p, pNext };
            edgeList.add(edge);//w  w w  . j  a v a  2 s. c  o  m
        }
    }

    return edgeList;
}

From source file:CircleLayoutDemo.java

/**
 * Arranges the parent's Component objects in either an Ellipse or a Circle.
 * Ellipse is not yet implemented./*  w w  w  . ja  v a 2  s  .c om*/
 */
public void layoutContainer(Container parent) {
    int x, y, w, h, s, c;
    int n = parent.getComponentCount();
    double parentWidth = parent.getSize().width;
    double parentHeight = parent.getSize().height;
    Insets insets = parent.getInsets();
    int centerX = (int) (parentWidth - (insets.left + insets.right)) / 2;
    int centerY = (int) (parentHeight - (insets.top + insets.bottom)) / 2;

    Component comp = null;
    Dimension compPS = null;
    if (n == 1) {
        comp = parent.getComponent(0);
        x = centerX;
        y = centerY;
        compPS = comp.getPreferredSize();
        w = compPS.width;
        h = compPS.height;
        comp.setBounds(x, y, w, h);
    } else {
        double r = (Math.min(parentWidth - (insets.left + insets.right),
                parentHeight - (insets.top + insets.bottom))) / 2;
        r *= 0.75; // Multiply by .75 to account for extreme right and bottom
                   // Components
        for (int i = 0; i < n; i++) {
            comp = parent.getComponent(i);
            compPS = comp.getPreferredSize();
            if (isCircle) {
                c = (int) (r * Math.cos(2 * i * Math.PI / n));
                s = (int) (r * Math.sin(2 * i * Math.PI / n));
            } else {
                c = (int) ((centerX * 0.75) * Math.cos(2 * i * Math.PI / n));
                s = (int) ((centerY * 0.75) * Math.sin(2 * i * Math.PI / n));
            }
            x = c + centerX;
            y = s + centerY;

            w = compPS.width;
            h = compPS.height;

            comp.setBounds(x, y, w, h);
        }
    }

}

From source file:edu.uci.ics.jung.algorithms.layout.CircleLayout.java

public void initialize() {
    Dimension d = getSize();// w ww.  ja  v  a2  s  .  c om

    if (d != null) {
        if (vertex_ordered_list == null)
            setVertexOrder(new ArrayList<V>(getGraph().getVertices()));

        double height = d.getHeight();
        double width = d.getWidth();

        if (radius <= 0) {
            radius = 0.45 * (height < width ? height : width);
        }

        int i = 0;
        for (V v : vertex_ordered_list) {
            Point2D coord = transform(v);

            double angle = (2 * Math.PI * i) / vertex_ordered_list.size();

            coord.setLocation(Math.cos(angle) * radius + width / 2, Math.sin(angle) * radius + height / 2);

            CircleVertexData data = getCircleData(v);
            data.setAngle(angle);
            i++;
        }
    }
}

From source file:edu.ucsf.valelab.saim.calculations.SaimCalc.java

/**
 * Calculates the transverse electric (TE) component, perpendicular to the 
 * plane of incidence, of the Fresnel coefficient of reflection between the 
 * sample interface and the virtual silicon oxidesilicon layer, 
 * as described in:/*from w  w  w. ja  v  a 2s .  c o m*/
 * Paszek, M.J., C.C. DuFort, M.G. Rubashkin, M.W. Davidson, K.S. Thorn, J.T. 
 * Liphardt, and V.M. Weaver. 2012. 
 * Scanning angle interference microscopy reveals cell dynamics at the nanoscale. 
 * Nat Meth. 9:825827. doi:10.1038/nmeth.2077.
 * 
 * 
 * 1/11/2016: Note that the above manuscript contains a mistake that is corrected
 * in a later publication: http://dx.doi.org/10.1016/B978-0-12-420138-5.00013-6
 * That correction is now applied.
 * 
 * 
 * @param wavelength of the excitation light source in nm
 * @param angle with respect to the normal in radiance
 * @param dOx Thickness of the Silicon Oxide layer in nm
 * @param nSample Refractive index of the sample's buffer
 * @return FresnelCoefficient for these conditions
 */
public static Complex fresnelTE(final double wavelength, final double angle, final double dOx,
        final double nSample) {

    double nSi = RI.getRI(RI.Compound.SILICON, wavelength);
    double nOx = RI.getRI(RI.Compound.SILICONOXIDE, wavelength);
    double kOx = k(wavelength, nOx);
    double angleOx = snell2(angle, nSample, RI.getRI(RI.Compound.SILICONOXIDE, wavelength));
    double cosOx = Math.cos(angleOx);
    double cosSi = Math.cos(snell2(angleOx, nOx, RI.getRI(RI.Compound.SILICON, wavelength)));
    double p0 = nSi * cosSi;
    double p1 = nOx * cosOx;
    double p2 = nSample * Math.cos(angle);
    double kOxdOxCosOx = kOx * dOx * cosOx;

    double cosOfkOxdOxCosOx = Math.cos(kOxdOxCosOx);
    double sinOfkOxdOxCosOx = Math.sin(kOxdOxCosOx);

    double m11TE = cosOfkOxdOxCosOx;
    Complex m12TE = Complex.I.multiply(-1 / p1 * sinOfkOxdOxCosOx);
    Complex m21TE = Complex.I.multiply(-p1 * sinOfkOxdOxCosOx);
    double m22TE = cosOfkOxdOxCosOx;

    Complex tmp1 = ((m12TE.multiply(p0)).add(m11TE)).multiply(p2);
    // this is the only line changed due to the error in the NM paper
    Complex tmp2 = tmp1.subtract(m21TE.add(m22TE * p0));
    //Complex tmp2 = tmp1.add( m21TE.subtract(m22TE * p0) );
    Complex tmp3 = tmp1.add(m21TE.add(m22TE * p0));
    Complex rTE = tmp2.divide(tmp3);

    return rTE;
}

From source file:jat.core.cm.TwoBodyAPL.java

public VectorN position(double t) {

    double[] temp = new double[6];

    // Determine step size
    double n = this.meanMotion();

    // determine initial E and M
    double sqrome2 = Math.sqrt(1.0 - this.e * this.e);
    double cta = Math.cos(this.ta);
    double sta = Math.sin(this.ta);
    double sine0 = (sqrome2 * sta) / (1.0 + this.e * cta);
    double cose0 = (this.e + cta) / (1.0 + this.e * cta);
    double e0 = Math.atan2(sine0, cose0);

    double ma = e0 - this.e * Math.sin(e0);

    ma = ma + n * t;/*  www . j  a va2 s.  com*/
    double ea = solveKepler(ma, this.e);

    double sinE = Math.sin(ea);
    double cosE = Math.cos(ea);
    double den = 1.0 - this.e * cosE;

    double sinv = (sqrome2 * sinE) / den;
    double cosv = (cosE - this.e) / den;

    this.ta = Math.atan2(sinv, cosv);
    if (this.ta < 0.0) {
        this.ta = this.ta + 2.0 * Constants.pi;
    }

    temp = this.randv();
    this.rv = new VectorN(temp);

    // Reset everything to before
    this.ta = initial_ta;

    VectorN out = new VectorN(3);
    out.x[0] = temp[0];
    out.x[1] = temp[1];
    out.x[2] = temp[2];
    // out.print("sat pos at t");
    return out;

}