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:demo.support.NavUtils.java

/**
 * Returns coordinates of position which is given distance and bearing from given point.
 * @param pt1//from   ww w .ja v  a 2  s. c  o m
 * @param dist
 * @param brg
 * @return
 */
public static Point getPosition(Point pt1, double d, double brg) {
    if (Double.doubleToRawLongBits(d) == 0) {
        return pt1;
    }

    double lat1 = Math.toRadians(pt1.getLatitude());
    double lon1 = Math.toRadians(pt1.getLongitude());
    double brgAsRadians = Math.toRadians(brg);

    double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / EARTH_RADIUS_IN_METERS)
            + Math.cos(lat1) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(brgAsRadians));
    double x = Math.sin(brgAsRadians) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(lat1);
    double y = Math.cos(d / EARTH_RADIUS_IN_METERS) - Math.sin(lat1) * Math.sin(lat2);
    double lon2 = lon1 + Math.atan2(x, y);

    return new Point(Math.toDegrees(lat2), Math.toDegrees(lon2));

}

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

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

From source file:org.n52.oss.IT.OpenSearchSpatialExtensionIT.java

public static double haversine(double lat1, double lon1, double lat2, double lon2) {
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    lat1 = Math.toRadians(lat1);//w  w w .  java 2s  .c om
    lat2 = Math.toRadians(lat2);

    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
}

From source file:uk.org.todome.Util.java

public static double getDistanceBetween(GeoPoint point1, GeoPoint point2) {
    // Implemented from code at
    // http://www.movable-type.co.uk/scripts/latlong.html
    int R = 6371; // radius of Earth in km

    double lat2 = Math.toRadians(point2.getLatitudeE6() * 1e-6);
    double lat1 = Math.toRadians(point1.getLatitudeE6() * 1e-6);

    double dLat = lat2 - lat1;
    double dLon = Math.toRadians((point2.getLongitudeE6() - point1.getLongitudeE6()) * 1e-6);

    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = R * c;

    return d;//from w w w .ja  v a2s  . co  m
}

From source file:ceptraj.tool.Bearing.java

public static double bearing(Point p1, Point p2) {
    double bearing = 0;
    if (p1 != null && p2 != null) {

        switch (ConfigProvider.getSpaceType()) {
        case lat_lon:
            //In case of lat-lon space
            double p1LatRad = Math.toRadians(p1.getLat());
            double p2LatRad = Math.toRadians(p2.getLat());

            double p1LonRad = Math.toRadians(p1.getLon());
            double p2LonRad = Math.toRadians(p2.getLon());

            bearing = (Math//from   w  w w .j  ava  2 s. c  o m
                    .toDegrees((Math.atan2(Math.sin(p2LonRad - p1LonRad) * Math.cos(p2LatRad),
                            Math.cos(p1LatRad) * Math.sin(p2LatRad)
                                    - Math.sin(p1LatRad) * Math.cos(p2LatRad) * Math.cos(p2LonRad - p1LonRad))))
                    + 360) % 360;
            break;
        case cartesian:
            //In case of cartesian space
            double dy = p2.y - p1.y;
            double dx = p2.x - p1.x;
            bearing = 90 - (180 / Math.PI) * Math.atan2(dy, dx);
            if (bearing < 0) {
                bearing += 360;
            }
            break;
        }
    }

    return bearing;
}

From source file:org.eclipse.swt.examples.graphics.CardsTab.java

@Override
public void next(int width, int height) {
    rotationAngle = (rotationAngle + 10) % 360;

    // scaleVal goes from 0 to 1, then 1 to 0, then starts over
    scaleArg = (float) ((scaleArg == 1) ? scaleArg - 0.1 : scaleArg + 0.1);
    scale = (float) Math.cos(scaleArg);

    movClubX += inc_club;//from   w ww.ja  va  2  s.  co m
    movDiamondX += inc_diamond;
    movHeart += inc_hearts;
    movSpade += inc_spade;

    scaleWidth = (float) ((movClubY / height) * 0.35 + 0.15);
    movClubY = 2 * height / 5 * (float) Math.sin(0.01 * movClubX - 90) + 2 * height / 5;
    movDiamondY = 2 * height / 5 * (float) Math.cos(0.01 * movDiamondX) + 2 * height / 5;

    if (movClubX + clubWidth * scaleWidth > width) {
        movClubX = width - clubWidth * scaleWidth;
        inc_club = -inc_club;
    }
    if (movClubX < 0) {
        movClubX = 0;
        inc_club = -inc_club;
    }
    if (movDiamondX + diamondWidth * scaleWidth > width) {
        movDiamondX = width - diamondWidth * scaleWidth;
        inc_diamond = -inc_diamond;
    }
    if (movDiamondX < 0) {
        movDiamondX = 0;
        inc_diamond = -inc_diamond;
    }
    if (movHeart + heartWidth * heartScale > width) {
        movHeart = width - heartWidth * heartScale;
        inc_hearts = -inc_hearts;
    }
    if (movHeart < 0) {
        movHeart = 0;
        inc_hearts = -inc_hearts;
    }
    if (movSpade + spadeHeight * spadeScale > height) {
        movSpade = height - spadeHeight * spadeScale;
        inc_spade = -inc_spade;
    }
    if (movSpade < 0) {
        movSpade = 0;
        inc_spade = -inc_spade;
    }
}

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

public void initialise(double[] a) {
    this.a = a;//from www  . j a  v  a 2s  . c o m
    // Precalculate multiplication factors
    peakFactors = new double[npeaks][13];
    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 sin2t = Math.sin(2.0 * 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 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:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz2.S_Dtlz2_Objective.java

@Override
public double evaluate(double[] x) {
    int nx = x.length;

    int i = 0;//from ww w.j a  va2  s.  co  m
    int j = 0;
    int k = nx - numberOfObjectives + 1;
    double g = 0;
    double[] z = new double[nx];
    double[] zz = new double[nx];
    double[] p = new double[nx];
    double[] psum = new double[numberOfObjectives];

    // denormalize vector:
    for (i = 0; i < nx; i++) {
        x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2;
    }

    for (i = 0; i < nx; i++) {
        z[i] = x[i] - o[i];

        if (z[i] < 0) {
            zz[i] = -lambda[i] * z[i];
            p[i] = -z[i] / d[i];
        } else {
            zz[i] = z[i];
            p[i] = 0;
        }
    }

    for (j = 0; j < numberOfObjectives; j++) {
        psum[j] = 0;
    }

    for (i = nx - k + 1; i <= nx; i++) {
        g += Math.pow(zz[i - 1] - 0.5, 2);
        for (j = 0; j < numberOfObjectives; j++) {
            psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2));
        }
    }

    double ff = (1 + g);

    for (j = numberOfObjectives - objNumber; j >= 1; j--) {
        ff *= Math.cos(zz[j - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2));
    }

    if (objNumber > 1) {
        ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(
                Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2));
    }

    return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1);
}

From source file:io.github.malapert.jwcs.coordsystem.Utility.java

/**
 * Calculates the matrix that represents a 3d rotation around the X axis.
 * //from  w  w  w  . j  av  a2  s  .  co  m
 * Reference:  
 * ----------
 * Diebel, J. 2006, Stanford University, Representing Attitude:
 * Euler angles, Unit Quaternions and Rotation Vectors. 
 * http://ai.stanford.edu/~diebel/attitude.html
 * 
 * Notes:
 * ------
 * Return the rotation matrix for a rotation around the X axis.
 * This is a rotation in the YZ plane. Note that we construct
 * a new vector with: xnew = R1.x
 * In the literature, this rotation is usually called R1
 *
 * @param angle Rotation angle in degrees
 * @return A 3x3 matrix representing the rotation about angle around X axis.
 */
public final static RealMatrix rotX(final double angle) {
    double angleRadians = Math.toRadians(angle);
    double[][] array = { { 1.d, 0.d, 0.d }, { 0.d, Math.cos(angleRadians), Math.sin(angleRadians) },
            { 0.d, -1 * Math.sin(angleRadians), Math.cos(angleRadians) } };
    return MatrixUtils.createRealMatrix(array);
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz3.S_Dtlz3_Objective.java

@Override
public double evaluate(double[] x) {

    int nx = x.length;

    int i = 0;//from   w  w  w . ja va2s  .  c om
    int j = 0;
    int k = nx - numberOfObjectives + 1;
    double g = 0;

    double[] z = new double[nx];
    double[] zz = new double[nx];
    double[] p = new double[nx];
    double[] psum = new double[numberOfObjectives];

    // denormalize vector:
    for (i = 0; i < nx; i++) {
        x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2;
    }

    for (i = 0; i < nx; i++) {
        z[i] = x[i] - o[i];

        if (z[i] < 0) {
            zz[i] = -lambda[i] * z[i];
            p[i] = -z[i] / d[i];
        } else {
            zz[i] = z[i];
            p[i] = 0;
        }
    }

    for (j = 0; j < numberOfObjectives; j++) {
        psum[j] = 0;
    }

    for (i = nx - k + 1; i <= nx; i++) {
        g += Math.pow(zz[i - 1] - 0.5, 2) - Math.cos(20 * Math.PI * (zz[i - 1] - 0.5));
        for (j = 0; j < numberOfObjectives; j++) {
            psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2));
        }
    }

    g = 100 * (k + g);

    double ff = (1 + g);

    for (j = numberOfObjectives - objNumber; j >= 1; j--) {
        ff *= Math.cos(zz[j - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2));
    }

    if (objNumber > 1) {
        ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(
                Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2));
    }

    return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1);

}