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

/**
 * Metoda care calculeaza viteza cu care se deplaseaza intre 2 coordonate
 * date(Lat+long) intr-un interval de timp [time_1,time_2]. Calculam
 * distanta dintre cele doua coordonate folosind formula " Great-circle
 * distance" viteza = distanta transformata in m/diferenta dintre cei 2
 * timpi primiti ca parametru// ww  w. j a  v a  2 s  .  c  om
 */
public static double computeSpeed(double lat_1, double long_1, long time_1, double lat_2, double long_2,
        long time_2) {
    double speed; // speed->m/s
    double distanceKm;
    double distanceM;
    long time;
    double r = 6378.137;

    double e = (double) Math.acos(
            Math.sin(lat_1) * Math.sin(lat_2) + Math.cos(lat_1) * Math.cos(lat_2) * Math.cos(long_2 - long_1));
    e = e / 180 * (double) Math.PI;
    distanceKm = e * r;
    distanceM = distanceKm * 1000;
    time = (time_2 - time_1) / 1000;
    speed = distanceM / time;

    return speed;
}

From source file:Main.java

/**
 * Computes the distance in meters between two points on Earth.
 *
 * @param lat1 Latitude of the first point
 * @param lon1 Longitude of the first point
 * @param lat2 Latitude of the second point
 * @param lon2 Longitude of the second point
 * @return Distance between the two points in meters.
 *///from  w w  w  .  j av  a 2 s  .  c o  m
public static double distance(double lat1, double lon1, double lat2, double lon2) {
    double lat1Rad = Math.toRadians(lat1);
    double lat2Rad = Math.toRadians(lat2);
    double deltaLonRad = Math.toRadians(lon2 - lon1);

    return Math.acos(Math.sin(lat1Rad) * Math.sin(lat2Rad)
            + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad)) * EARTH_RADIUS_KM * 1000;
}

From source file:Main.java

static double distanceFromPointOnArc(double dA, double dB, double dAB) {
    // In spherical trinagle ABC
    // a is length of arc BC, that is dB
    // b is length of arc AC, that is dA
    // c is length of arc AB, that is dAB
    // We rename parameters so following formulas are more clear:
    double a = dB;
    double b = dA;
    double c = dAB;

    // First, we calculate angles alpha and beta in spherical triangle ABC
    // and based on them we decide how to calculate the distance:
    if (Math.sin(b) * Math.sin(c) == 0.0 || Math.sin(c) * Math.sin(a) == 0.0) {
        // It probably means that one of distance is n*pi, which gives around 20000km for n = 1,
        // unlikely for Denmark, so we should be fine.
        return -1.0;
    }//from   w w  w . j  a va2s  . c o m

    double alpha = Math.acos((Math.cos(a) - Math.cos(b) * Math.cos(c)) / (Math.sin(b) * Math.sin(c)));
    double beta = Math.acos((Math.cos(b) - Math.cos(c) * Math.cos(a)) / (Math.sin(c) * Math.sin(a)));

    // It is possible that both sinuses are too small so we can get nan when dividing with them
    if (Double.isNaN(alpha) || Double.isNaN(beta)) {
        return -1.0;
    }

    // If alpha or beta are zero or pi, it means that C is on the same circle as arc AB,
    // we just need to figure out if it is between AB:
    if (alpha == 0.0 || beta == 0.0) {
        return (dA + dB > dAB) ? Math.min(dA, dB) : 0.0;
    }

    // If alpha is obtuse and beta is acute angle, then
    // distance is equal to dA:
    if (alpha > Math.PI / 2 && beta < Math.PI / 2)
        return -1;

    // Analogously, if beta is obtuse and alpha is acute angle, then
    // distance is equal to dB:
    if (beta > Math.PI / 2 && alpha < Math.PI / 2)
        return -1;

    // Again, unlikely, since it would render at least pi/2*EARTH_RADIUS_IN_METERS, which is too much.
    if (Math.cos(a) == 0.0)
        return -1;

    double x = Math.atan(-1.0 / Math.tan(c) + (Math.cos(b) / (Math.cos(a) * Math.sin(c))));

    return x;
}

From source file:Main.java

private static void findConstants(double[] n_p, double[] n_m, double[] d_p, double[] d_m, double[] bd_p,
        double[] bd_m, double std_dev) {
    double div = Math.sqrt(2 * 3.141593) * std_dev;
    double x0 = -1.783 / std_dev;
    double x1 = -1.723 / std_dev;
    double x2 = 0.6318 / std_dev;
    double x3 = 1.997 / std_dev;
    double x4 = 1.6803 / div;
    double x5 = 3.735 / div;
    double x6 = -0.6803 / div;
    double x7 = -0.2598 / div;
    int i;/*from   w  w  w  .  ja  v a2  s  .co  m*/

    n_p[0] = x4 + x6;
    n_p[1] = (Math.exp(x1) * (x7 * Math.sin(x3) - (x6 + 2 * x4) * Math.cos(x3))
            + Math.exp(x0) * (x5 * Math.sin(x2) - (2 * x6 + x4) * Math.cos(x2)));
    n_p[2] = (2 * Math.exp(x0 + x1) * ((x4 + x6) * Math.cos(x3) * Math.cos(x2)
            - x5 * Math.cos(x3) * Math.sin(x2) - x7 * Math.cos(x2) * Math.sin(x3)) + x6 * Math.exp(2 * x0)
            + x4 * Math.exp(2 * x1));
    n_p[3] = (Math.exp(x1 + 2 * x0) * (x7 * Math.sin(x3) - x6 * Math.cos(x3))
            + Math.exp(x0 + 2 * x1) * (x5 * Math.sin(x2) - x4 * Math.cos(x2)));
    n_p[4] = 0.0;

    d_p[0] = 0.0;
    d_p[1] = -2 * Math.exp(x1) * Math.cos(x3) - 2 * Math.exp(x0) * Math.cos(x2);
    d_p[2] = 4 * Math.cos(x3) * Math.cos(x2) * Math.exp(x0 + x1) + Math.exp(2 * x1) + Math.exp(2 * x0);
    d_p[3] = -2 * Math.cos(x2) * Math.exp(x0 + 2 * x1) - 2 * Math.cos(x3) * Math.exp(x1 + 2 * x0);
    d_p[4] = Math.exp(2 * x0 + 2 * x1);

    for (i = 0; i <= 4; i++) {
        d_m[i] = d_p[i];
    }

    n_m[0] = 0.0;
    for (i = 1; i <= 4; i++) {
        n_m[i] = n_p[i] - d_p[i] * n_p[0];
    }

    double sum_n_p, sum_n_m, sum_d;
    double a, b;

    sum_n_p = 0.0;
    sum_n_m = 0.0;
    sum_d = 0.0;

    for (i = 0; i <= 4; i++) {
        sum_n_p += n_p[i];
        sum_n_m += n_m[i];
        sum_d += d_p[i];
    }

    a = sum_n_p / (1.0 + sum_d);
    b = sum_n_m / (1.0 + sum_d);

    for (i = 0; i <= 4; i++) {
        bd_p[i] = d_p[i] * a;
        bd_m[i] = d_m[i] * b;
    }
}

From source file:Main.java

/**
 * Computes the distance in kilometers between two points on Earth.
 *
 * @param lat1 Latitude of the first point
 * @param lon1 Longitude of the first point
 * @param lat2 Latitude of the second point
 * @param lon2 Longitude of the second point
 * @return Distance between the two points in kilometers.
 *//*  w  w  w  .  j a v a  2s  .  c  o  m*/
public static double distanceKm(double lat1, double lon1, double lat2, double lon2) {
    double lat1Rad = Math.toRadians(lat1);
    double lat2Rad = Math.toRadians(lat2);
    double deltaLonRad = Math.toRadians(lon2 - lon1);

    return Math.acos(Math.sin(lat1Rad) * Math.sin(lat2Rad)
            + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.cos(deltaLonRad)) * EARTH_RADIUS_KM;
}

From source file:Main.java

private static float getY(double angle, double radius) {
    return (float) (Math.sin(angle + Math.PI / 2) * radius);
}

From source file:Main.java

private static byte generateBeep(int step, float freq, int samplingRate) {
    double phase = calcPhase(step, freq, samplingRate);
    return (byte) (128 * (Math.sin(phase) + Math.sin(2 * phase)));
}

From source file:Main.java

private static byte generateSoft(int step, float freq, int samplingRate) {
    double phase = calcPhase(step, freq, samplingRate);
    return (byte) (128 * (Math.sin(phase)));
}

From source file:Main.java

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

From source file:Main.java

public static Point rotatePoint(Point point, Point centerPoint, float rotate) {
    float x = point.x;
    float y = point.y;
    float sinA = (float) Math.sin(Math.toRadians(rotate));
    float cosA = (float) Math.cos(Math.toRadians(rotate));
    float newX = centerPoint.x + (x - centerPoint.x) * cosA - (y - centerPoint.y) * sinA;
    float newY = centerPoint.y + (y - centerPoint.y) * cosA + (x - centerPoint.x) * sinA;
    return new Point((int) newX, (int) newY);
}