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:org.elasticsoftware.elasticactors.geoevents.Coordinate.java

public double distance(final double latitude, final double longitude, LengthUnit unit) {
    double a = 6378137, b = 6356752.3142;
    // ellipsiod// w w  w.  jav a2  s .c o  m
    double L = (longitude - this.longitude) * degToRad;
    double U1 = Math.atan((1 - f) * Math.tan(this.latitude * degToRad));
    double U2 = Math.atan((1 - f) * Math.tan(latitude * degToRad));
    double sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
    double sinU2 = Math.sin(U2), cosU2 = Math.cos(U2);

    double cosSqAlpha, sinSigma, cos2SigmaM, cosSigma, sigma;

    double lambda = L, lambdaP, iterLimit = 20;
    do {
        double sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda);
        sinSigma = Math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda)
                + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
        if (sinSigma == 0)
            return 0; // co-incident points
        cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
        sigma = Math.atan2(sinSigma, cosSigma);
        double sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
        cosSqAlpha = 1 - sinAlpha * sinAlpha;
        cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha;
        if (cos2SigmaM == Double.NaN)
            cos2SigmaM = 0; // equatorial line: cosSqAlpha=0 (?6)
        double C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha));
        lambdaP = lambda;
        lambda = L + (1 - C) * f * sinAlpha
                * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
    } while (Math.abs(lambda - lambdaP) > EPSILON && --iterLimit > 0);

    if (iterLimit == 0)
        return Double.NaN;
    double uSquared = cosSqAlpha * (a * a - b * b) / (b * b);
    double A = 1 + uSquared / 16384 * (4096 + uSquared * (-768 + uSquared * (320 - 175 * uSquared)));
    double B = uSquared / 1024 * (256 + uSquared * (-128 + uSquared * (74 - 47 * uSquared)));
    double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)
            - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
    double s = b * A * (sigma - deltaSigma);

    return unit.convert(s, LengthUnit.METRES);
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.sym_part.Sym_Part_Objective.java

protected int findTileSYMPART(double x1, double x2) {
    int i, j, dim;
    double[] x = new double[2];
    double h1;/*from ww w .j a  v  a2  s  .  c om*/
    double omega = Math.PI / 4.0;
    double si = Math.sin(omega), co = Math.cos(omega);

    x[0] = x1;
    x[1] = x2;

    //rotate( 2, x );
    for (dim = 0; dim + 1 < 2; dim += 2) {
        h1 = x[dim];
        x[dim] = co * h1 - si * x[dim + 1];
        x[dim + 1] = si * h1 + co * x[dim + 1];
    }

    int[] ij = findTile(x[0], x[1]);

    i = ij[0];
    j = ij[1];

    // restrict to 9 tiles
    if (Math.abs(i) > 1 || Math.abs(j) > 1) {
        return -1;
    }

    return (i + 1) * 3 + (j + 1);
}

From source file:org.honeybee.coderally.Modelt.java

@Override
public void onTimeStep() {
    if (!gogogogo)
        return;// w ww  .j  a va2s.c om

    Point checkpoint = schewy.getMidPoint(getCar().getCheckpoint());

    double heading = getCar().calculateHeading(checkpoint);
    double rotation;
    if (heading < 1) {
        rotation = -90;
    } else if (heading > 1) {
        rotation = 90;
    } else {
        rotation = 0;
    }

    Point position = getCar().getPosition();
    double radians = getCar().getRotation().getRadians() - Math.PI / 2 + Math.toRadians(rotation);
    Point target = new Point(position.getX() + Math.cos(radians) * 500,
            position.getY() + Math.sin(radians) * 500);
    getCar().setTarget(target);

    slowForTightCorner(getCar());

}

From source file:RLCcircuit.RLCcircuitJFrame.java

public void ValueCaculate(double time) {
    angularFrequency = 2 * pi * frequency;
    inputVoltage = voltage0 * Math.sin(angularFrequency * time);
    phaseAngle = Math.atan((Lreactance - Creactance) / R) * 180 / pi;

    Lreactance = angularFrequency * L;//from   w  w w .  j  av a  2  s .  c o  m
    Creactance = 1 / angularFrequency / C;
    impedance = Math.sqrt(Math.pow(R, 2) + Math.pow(2 * pi * frequency * L - 1 / (2 * pi * frequency * C), 2));
    current0 = voltage0 / impedance;
    current = current0 * Math.sin(angularFrequency * time + phaseAngle);

    Rvoltage = current0 * R * Math.sin(angularFrequency * time);
    Lvoltage = current0 * Lreactance * Math.sin(angularFrequency * time - pi / 2);
    Cvoltage = current0 * Creactance * Math.sin(angularFrequency * time + pi / 2);
}

From source file:jtrace.texture.TransparentFinish.java

/**
 * Obtain ray refracted according to Snell's law.
 * /*  w  w w  .j a v a  2 s.  c om*/
 * @param incidentRay
 * @param normalRay
 * @return refracted ray
 */
Ray getRefractedRay(Ray incidentRay, Ray normalRay) {

    // Check direction of incident ray (inside to out or outside to in)
    // and adjust ior accordingly:
    double snellFactor;
    Vector3D axis;
    if (incidentRay.direction.dotProduct(normalRay.direction) < 0.0) {
        snellFactor = 1.0 / ior;
        axis = incidentRay.direction.crossProduct(normalRay.direction);
    } else {
        snellFactor = ior;
        axis = normalRay.direction.crossProduct(incidentRay.direction);
    }

    if (axis.getNorm() > 0) {
        axis = axis.normalize();
    } else {
        return new Ray(normalRay.getOrigin(), incidentRay.direction);
    }

    double angle = Math
            .asin((incidentRay.direction.normalize().crossProduct(normalRay.direction).normalize()).getNorm());
    double newAngle = Math.asin(snellFactor * Math.sin(angle));

    Rotation rotation = new Rotation(axis, newAngle - angle);

    Vector3D refractedDir = rotation.applyTo(incidentRay.direction);

    return new Ray(normalRay.getOrigin(), refractedDir);
}

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

public static ComplexNumber exp(final ComplexNumber z) {
    ArgumentChecker.notNull(z, "z");
    final double mult = Math.exp(z.getReal());
    return new ComplexNumber(mult * Math.cos(z.getImaginary()), mult * Math.sin(z.getImaginary()));
}

From source file:com.github.aptd.simulation.elements.common.CMath.java

/**
 * creates a rotation matrix//from w w  w .j  a va  2  s.  c o m
 *
 * @param p_alpha angel in radians
 * @return matrix
 *
 * @see https://en.wikipedia.org/wiki/Rotation_matrix
 */
public static DoubleMatrix2D rotationmatrix(final double p_alpha) {
    final double l_sin = Math.sin(p_alpha);
    final double l_cos = Math.cos(p_alpha);
    return new DenseDoubleMatrix2D(new double[][] { { l_cos, l_sin }, { -l_sin, l_cos } });
}

From source file:Main.java

/**
 * Creates a region surrounding a line segment by 'widening' the line
 * segment.  A typical use for this method is the creation of a
 * 'clickable' region for a line that is displayed on-screen.
 *
 * @param line  the line (<code>null</code> not permitted).
 * @param width  the width of the region.
 *
 * @return A region that surrounds the line.
 */// www  .j av a2  s.  c  om
public static Shape createLineRegion(final Line2D line, final float width) {
    final GeneralPath result = new GeneralPath();
    final float x1 = (float) line.getX1();
    final float x2 = (float) line.getX2();
    final float y1 = (float) line.getY1();
    final float y2 = (float) line.getY2();
    if ((x2 - x1) != 0.0) {
        final double theta = Math.atan((y2 - y1) / (x2 - x1));
        final float dx = (float) Math.sin(theta) * width;
        final float dy = (float) Math.cos(theta) * width;
        result.moveTo(x1 - dx, y1 + dy);
        result.lineTo(x1 + dx, y1 - dy);
        result.lineTo(x2 + dx, y2 - dy);
        result.lineTo(x2 - dx, y2 + dy);
        result.closePath();
    } else {
        // special case, vertical line
        result.moveTo(x1 - width / 2.0f, y1);
        result.lineTo(x1 + width / 2.0f, y1);
        result.lineTo(x2 + width / 2.0f, y2);
        result.lineTo(x2 - width / 2.0f, y2);
        result.closePath();
    }
    return result;
}

From source file:GraphicsUtil.java

static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) {
    double offs = headAngle * Math.PI / 180.0;
    double angle = Math.atan2(y0 - y1, x0 - x1);
    int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1,
            x1 + (int) (headLength * Math.cos(angle - offs)) };
    int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1,
            y1 + (int) (headLength * Math.sin(angle - offs)) };
    g.drawLine(x0, y0, x1, y1);//from w w w .j  a  v  a2  s. com
    g.drawPolyline(xs, ys, 3);
}

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static Number opPow(MutableNumber out, Number a, double b) {
    double m = Math.pow(FastMath.hypot(a.r(), a.i()), b);
    double f = Math.atan2(a.i(), a.r()) * b;
    return out.set(m * Math.cos(f), m * Math.sin(f));
}