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:Main.java

/**
 * Function: arcToCurves//w w w  . j a  v  a 2s .c  o  m
 * 
 * Converts the given arc to a series of curves.
 */
public static double[] arcToCurves(double x0, double y0, double r1, double r2, double angle,
        double largeArcFlag, double sweepFlag, double x, double y) {
    x -= x0;
    y -= y0;

    if (r1 == 0 || r2 == 0) {
        return new double[0];
    }

    double fS = sweepFlag;
    double psai = angle;
    r1 = Math.abs(r1);
    r2 = Math.abs(r2);
    double ctx = -x / 2;
    double cty = -y / 2;
    double cpsi = Math.cos(psai * Math.PI / 180);
    double spsi = Math.sin(psai * Math.PI / 180);
    double rxd = cpsi * ctx + spsi * cty;
    double ryd = -1 * spsi * ctx + cpsi * cty;
    double rxdd = rxd * rxd;
    double rydd = ryd * ryd;
    double r1x = r1 * r1;
    double r2y = r2 * r2;
    double lamda = rxdd / r1x + rydd / r2y;
    double sds;

    if (lamda > 1) {
        r1 = Math.sqrt(lamda) * r1;
        r2 = Math.sqrt(lamda) * r2;
        sds = 0;
    } else {
        double seif = 1;

        if (largeArcFlag == fS) {
            seif = -1;
        }

        sds = seif * Math.sqrt((r1x * r2y - r1x * rydd - r2y * rxdd) / (r1x * rydd + r2y * rxdd));
    }

    double txd = sds * r1 * ryd / r2;
    double tyd = -1 * sds * r2 * rxd / r1;
    double tx = cpsi * txd - spsi * tyd + x / 2;
    double ty = spsi * txd + cpsi * tyd + y / 2;
    double rad = Math.atan2((ryd - tyd) / r2, (rxd - txd) / r1) - Math.atan2(0, 1);
    double s1 = (rad >= 0) ? rad : 2 * Math.PI + rad;
    rad = Math.atan2((-ryd - tyd) / r2, (-rxd - txd) / r1) - Math.atan2((ryd - tyd) / r2, (rxd - txd) / r1);
    double dr = (rad >= 0) ? rad : 2 * Math.PI + rad;

    if (fS == 0 && dr > 0) {
        dr -= 2 * Math.PI;
    } else if (fS != 0 && dr < 0) {
        dr += 2 * Math.PI;
    }

    double sse = dr * 2 / Math.PI;
    int seg = (int) Math.ceil(sse < 0 ? -1 * sse : sse);
    double segr = dr / seg;
    double t = 8 / 3 * Math.sin(segr / 4) * Math.sin(segr / 4) / Math.sin(segr / 2);
    double cpsir1 = cpsi * r1;
    double cpsir2 = cpsi * r2;
    double spsir1 = spsi * r1;
    double spsir2 = spsi * r2;
    double mc = Math.cos(s1);
    double ms = Math.sin(s1);
    double x2 = -t * (cpsir1 * ms + spsir2 * mc);
    double y2 = -t * (spsir1 * ms - cpsir2 * mc);
    double x3 = 0;
    double y3 = 0;

    double[] result = new double[seg * 6];

    for (int n = 0; n < seg; ++n) {
        s1 += segr;
        mc = Math.cos(s1);
        ms = Math.sin(s1);

        x3 = cpsir1 * mc - spsir2 * ms + tx;
        y3 = spsir1 * mc + cpsir2 * ms + ty;
        double dx = -t * (cpsir1 * ms + spsir2 * mc);
        double dy = -t * (spsir1 * ms - cpsir2 * mc);

        // CurveTo updates x0, y0 so need to restore it
        int index = n * 6;
        result[index] = x2 + x0;
        result[index + 1] = y2 + y0;
        result[index + 2] = x3 - dx + x0;
        result[index + 3] = y3 - dy + y0;
        result[index + 4] = x3 + x0;
        result[index + 5] = y3 + y0;

        x2 = x3 + dx;
        y2 = y3 + dy;
    }

    return result;
}

From source file:Main.java

public static double[] gcj02tobd09(double lng, double lat) {
    double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_pi);
    double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_pi);
    double bd_lng = z * Math.cos(theta) + 0.0065;
    double bd_lat = z * Math.sin(theta) + 0.006;
    return new double[] { bd_lng, bd_lat };
}

From source file:Main.java

private static byte generateCalling(int step, float freq, int samplingRate) {
    double phase = calcPhase(step, freq * 0.08f, samplingRate);
    double phase2 = calcPhase(step, freq * 0.3f, samplingRate);
    return (byte) (128 * (Math.sin(phase + phase2)));
}

From source file:Main.java

private static double transformLon(double x, double y) {
    double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
    ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
    ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
    ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;

    return ret;//from   w  ww  . j a  v a2 s. c  o  m
}

From source file:Main.java

private static double transformLat(double x, double y) {
    double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
    ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
    ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
    ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;

    return ret;/*from   w  w w.  j  av a2 s .  co m*/
}

From source file:Main.java

static public long getCrossWindComponent(double windSpeed, double windDir, double d) {
    return Math.round(windSpeed * Math.sin(Math.toRadians(windDir - d)));
}

From source file:Main.java

public static double transformlng(double lng, double lat) {
    double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
    ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 * Math.sin(2.0 * lng * pi)) * 2.0 / 3.0;
    ret += (20.0 * Math.sin(lng * pi) + 40.0 * Math.sin(lng / 3.0 * pi)) * 2.0 / 3.0;
    ret += (150.0 * Math.sin(lng / 12.0 * pi) + 300.0 * Math.sin(lng / 30.0 * pi)) * 2.0 / 3.0;
    return ret;//w  ww.  j av a 2 s .  c  om
}

From source file:Main.java

public static void transform(double wgLat, double wgLon, double[] latlng) {
    if (outOfChina(wgLat, wgLon)) {
        latlng[0] = wgLat;/*from ww w .j  a v  a2  s.co  m*/
        latlng[1] = wgLon;
        return;
    }
    double dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
    double dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
    double radLat = wgLat / 180.0 * pi;
    double magic = Math.sin(radLat);
    magic = 1 - ee * magic * magic;
    double sqrtMagic = Math.sqrt(magic);
    dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
    dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
    latlng[0] = wgLat + dLat;
    latlng[1] = wgLon + dLon;
}

From source file:Main.java

public static double calculateDistance(double lat1, double lng1, double lat2, double lng2) {
    int MAXITERS = 20;
    // Convert lat/long to radians
    lat1 *= Math.PI / 180.0;// ww  w. j  av  a2 s. co m
    lat2 *= Math.PI / 180.0;
    lng1 *= Math.PI / 180.0;
    lng2 *= Math.PI / 180.0;

    double a = 6378137.0; // WGS84 major axis
    double b = 6356752.3142; // WGS84 semi-major axis
    double f = (a - b) / a;
    double aSqMinusBSqOverBSq = (a * a - b * b) / (b * b);

    double L = lng2 - lng1;
    double A = 0.0;
    double U1 = Math.atan((1.0 - f) * Math.tan(lat1));
    double U2 = Math.atan((1.0 - f) * Math.tan(lat2));

    double cosU1 = Math.cos(U1);
    double cosU2 = Math.cos(U2);
    double sinU1 = Math.sin(U1);
    double sinU2 = Math.sin(U2);
    double cosU1cosU2 = cosU1 * cosU2;
    double sinU1sinU2 = sinU1 * sinU2;

    double sigma = 0.0;
    double deltaSigma = 0.0;
    double cosSqAlpha = 0.0;
    double cos2SM = 0.0;
    double cosSigma = 0.0;
    double sinSigma = 0.0;
    double cosLambda = 0.0;
    double sinLambda = 0.0;

    double lambda = L; // initial guess
    for (int iter = 0; iter < MAXITERS; iter++) {
        double lambdaOrig = lambda;
        cosLambda = Math.cos(lambda);
        sinLambda = Math.sin(lambda);
        double t1 = cosU2 * sinLambda;
        double t2 = cosU1 * sinU2 - sinU1 * cosU2 * cosLambda;
        double sinSqSigma = t1 * t1 + t2 * t2; // (14)
        sinSigma = Math.sqrt(sinSqSigma);
        cosSigma = sinU1sinU2 + cosU1cosU2 * cosLambda; // (15)
        sigma = Math.atan2(sinSigma, cosSigma); // (16)
        double sinAlpha = (sinSigma == 0) ? 0.0 : cosU1cosU2 * sinLambda / sinSigma; // (17)
        cosSqAlpha = 1.0 - sinAlpha * sinAlpha;
        cos2SM = (cosSqAlpha == 0) ? 0.0 : cosSigma - 2.0 * sinU1sinU2 / cosSqAlpha; // (18)

        double uSquared = cosSqAlpha * aSqMinusBSqOverBSq; // defn
        A = 1 + (uSquared / 16384.0) * // (3)
                (4096.0 + uSquared * (-768 + uSquared * (320.0 - 175.0 * uSquared)));
        double B = (uSquared / 1024.0) * // (4)
                (256.0 + uSquared * (-128.0 + uSquared * (74.0 - 47.0 * uSquared)));
        double C = (f / 16.0) * cosSqAlpha * (4.0 + f * (4.0 - 3.0 * cosSqAlpha)); // (10)
        double cos2SMSq = cos2SM * cos2SM;
        deltaSigma = B * sinSigma * // (6)
                (cos2SM + (B / 4.0) * (cosSigma * (-1.0 + 2.0 * cos2SMSq)
                        - (B / 6.0) * cos2SM * (-3.0 + 4.0 * sinSigma * sinSigma) * (-3.0 + 4.0 * cos2SMSq)));

        lambda = L + (1.0 - C) * f * sinAlpha
                * (sigma + C * sinSigma * (cos2SM + C * cosSigma * (-1.0 + 2.0 * cos2SM * cos2SM))); // (11)

        double delta = (lambda - lambdaOrig) / lambda;
        if (Math.abs(delta) < 1.0e-12) {
            break;
        }
    }

    float distance = (float) (b * A * (sigma - deltaSigma));
    return distance;
}

From source file:Main.java

public static double[] bd09togcj02(double bd_lon, double bd_lat) {
    double x = bd_lon - 0.0065;
    double y = bd_lat - 0.006;
    double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
    double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
    double gg_lng = z * Math.cos(theta);
    double gg_lat = z * Math.sin(theta);
    return new double[] { gg_lng, gg_lat };
}