Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine 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 w ww.  j  av  a2  s .  c om
 * @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:utils.RandomVariable.java

/**
 * Generate a random number from a Gaussian (Normal) random variable.
 *
 * @param mu mean of the random variable.
 * @param sigma standard deviation of the random variable.
 * @return a double./*from w  ww .j  av a2s .  co  m*/
 */
public static double normal(double mu, double sigma) {
    double x = mu + sigma * Math.cos(2 * Math.PI * rand()) * Math.sqrt(-2 * Math.log(rand()));
    return x;
}

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

public void initialise(double[] a) {
    this.a = a;//from w  w w.  j ava2  s . 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: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:/*w  w  w .j a  va 2  s  .c  om*/
 * 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:net.gtaun.shoebill.data.Quaternion.java

public float[] rotatedMatrix(float dx, float dy, float dz, double angle) {
    float x = getX(), y = getY(), z = getZ();
    float w = (float) Math.cos(angle / 2);

    float[][] matrix = new float[3][3];

    matrix[0][0] = 1 - 2 * (y * y + z * z);
    matrix[0][1] = 2 * (x * y - w * z);/*  ww w .  jav  a 2  s. c  o  m*/
    matrix[0][2] = 2 * (w * y + x * z);

    matrix[1][0] = 2 * (x * y + w * z);
    matrix[1][1] = 1 - 2 * (x * x + z * z);
    matrix[1][2] = 2 * (y * z - w * x);

    matrix[2][0] = 2 * (x * z - w * y);
    matrix[2][1] = 2 * (y * z + w * x);
    matrix[2][2] = 1 - 2 * (x * x + y * y);

    float[] rotated = new float[3];

    rotated[0] = dx * matrix[0][0] + dy * matrix[0][1] + dz * matrix[0][2];
    rotated[1] = dx * matrix[1][0] + dy * matrix[1][1] + dz * matrix[1][2];
    rotated[2] = dx * matrix[2][0] + dy * matrix[2][1] + dz * matrix[2][2];

    return rotated;
}

From source file:com.crossover.trial.weather.domain.Airport.java

public double calculateDistance(Airport toAirport) {
    Assert.isTrue(toAirport != null, "airport is required");
    double deltaLat = Math.toRadians(toAirport.latitude - latitude);
    double deltaLon = Math.toRadians(toAirport.longitude - longitude);
    double a = Math.pow(Math.sin(deltaLat / 2), 2)
            + Math.pow(Math.sin(deltaLon / 2), 2) * Math.cos(latitude) * Math.cos(toAirport.latitude);
    double c = 2 * Math.asin(Math.sqrt(a));
    return EARTH_RADIUS * c;
}

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 av a  2 s.  c om*/
                    .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.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);//from  ww w .ja v a  2s .co  m
    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;//ww w  .  j a va2  s .co m
}

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 .ja  v  a 2 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);
}