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:com.eclipsesource.tabris.demos.entrypoints.GeolocationDemo.java

private double distFrom(double lat1, double lon1, double lat2, double lon2) {
    double d2r = Math.PI / 180;
    double dlong = (lon2 - lon1) * d2r;
    double dlat = (lat2 - lat1) * d2r;
    double a = Math.pow(Math.sin(dlat / 2.0), 2)
            + Math.cos(lat1 * d2r) * Math.cos(lat2 * d2r) * Math.pow(Math.sin(dlong / 2.0), 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return 6367 * c;
}

From source file:org.envirocar.app.util.Util.java

/**
 * Returns the distance of two points in kilometers.
 * /*from   w  ww .ja  va2s  . co  m*/
 * @param lat1
 * @param lng1
 * @param lat2
 * @param lng2
 * @return distance in km
 */
public static double getDistance(double lat1, double lng1, double lat2, double lng2) {

    double earthRadius = 6369;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    return dist;

}

From source file:YoungDoubleSlit.YoungDoubleSlit.java

public JFreeChart getResultChart() {
    // XY ?.//from   w w w .  j  a  v a2s.c o m
    XYSeries series = new XYSeries("Histogram of light amplitude");
    Integer radius_size = ((UpperViewPane) upperView).getRadius().size();
    Integer wavelength_value = ((UpperViewPane) upperView).getWavelengths().get(0);
    Double bin_width = 31.0 / bin_size;

    for (int i = 0; i < bin_size; i++) {
        double theta = Math.toRadians(-15.5 + bin_width * i);
        //double alpha = Math.PI* slit_width/wavelength_value*Math.sin(theta);
        //double beta  = Math.PI* slit_distance/wavelength_value*Math.sin(theta);
        double alpha = Math.PI * slit_width * Math.sin(theta);
        double beta = Math.PI * slit_distance * Math.sin(theta);
        double amplitude = Math.cos(beta) * Math.cos(beta) * (Math.sin(alpha) / alpha)
                * (Math.sin(alpha) / alpha);
        // series? (x,y) ? 
        series.add(theta, amplitude);
    }
    // XY Dataset  
    XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("Amplitude of Light", "Angle", "Amp.", data,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setTitle("Amplitude of light"); //  ?
    return chart;

}

From source file:com.docdoku.server.rest.InstanceMessageBodyWriter.java

private double getRelativeTzAfterParentRotation(double rx, double ry, double rz, double tx, double ty,
        double tz) {

    double g = -Math.sin(ry);
    double h = Math.sin(rx) * Math.cos(ry);
    double i = Math.cos(rx) * Math.cos(ry);

    return g * tx + h * ty + i * tz;
}

From source file:gbt.ubt.tool.Orthorectifier.java

private static double[] calculateShift(double latitude, double terrainHeight, double[] azimuthElevation) {
    /* Note this method is taken from the AATSR data processing model for L1B (topographic corrections section 5.16)
    As the ESA CFI target is closed source, we use the azimuth elevation retrieved using the Orekit library with an orbit
    propagated using state vector contained in the L1b product
    *//*from www  .j  a v a2s .  com*/
    double latitudeRadians = latitude * (Math.PI / 180.0);
    double a = Constants.WGS84_EARTH_EQUATORIAL_RADIUS; //semiMajorAxis
    double rf = Constants.WGS84_EARTH_FLATTENING;// reciprocal of flattening
    double b = a * (1 - rf); // semiMinorAxis
    double e1 = Math.pow((1 - (Math.pow(b, 2) / Math.pow(a, 2))), 0.5); //first eccentricity
    double e2sqr = (Math.pow(a, 2) / Math.pow(b, 2) - 1); // secondEccentricitySquared
    double C = 1000.0 * a / Math.pow((1 - Math.pow(e1, 2)), 0.5);
    double N = C / Math.pow((1 + (e2sqr * Math.pow(Math.cos(latitudeRadians), 2))), 0.5);
    double R = N / (1 + (e2sqr * Math.pow(Math.cos(latitudeRadians), 2)));
    double dY = terrainHeight * (1 / Math.tan(azimuthElevation[1])) * Math.cos(azimuthElevation[0]);
    double dX = terrainHeight * (1 / Math.tan(azimuthElevation[1])) * Math.sin(azimuthElevation[0]);
    double[] latLonCorr = new double[2];
    latLonCorr[0] = dY * (180.0 / Math.PI) / R;
    latLonCorr[1] = (dX / Math.cos(latitudeRadians)) * (180.0 / Math.PI) / N;
    return latLonCorr;
}

From source file:com.cohesionforce.dis.ConvertCSV.java

private Vector3Double getLocation(double lat, double lon) {
    Vector3Double output = new Vector3Double();
    double phi = PI_OVER_2 - lat;
    double theta = lon;
    double rho = EARTH_RADIUS;
    /* Subvalue for optimization */
    double rho_sin_phi = rho * Math.sin(phi);

    output.setX(rho_sin_phi * Math.cos(theta));
    output.setY(rho_sin_phi * Math.sin(theta));
    output.setY(rho * Math.cos(phi));

    return output;

}

From source file:com.net2plan.libraries.GraphUtils.java

/** Computes the Haversine distance between two points, that is, the shortest distance over the Earth's surface.
 * // www .j  a v  a  2  s.  c  o  m
 * <p><b>Important</b>: It is assumed an Earth's radius equal to {@link com.net2plan.utils.Constants#EARTH_RADIUS_IN_KM Constants.EARTH_RADIUS_IN_KM }</p>
 * 
 * <p><b>Important</b>: Coordinates are assumed to be given in degress, conversions to radians are made internally.</p>
 * 
 * @param point1 Point 1 (x-coord is equal to longitude, y-coord is equal to latitude)
 * @param point2 Point 2 (x-coord is equal to longitude, y-coord is equal to latitude)
 * @return Haversine distance between two points
 * @see <a href="http://www.movable-type.co.uk/scripts/latlong.html">Calculate distance, bearing and more between Latitude/Longitude points</a> */
public static double computeHaversineDistanceInKm(Point2D point1, Point2D point2) {
    double lon1 = point1.getX();
    double lat1 = point1.getY();
    double lon2 = point2.getX();
    double lat2 = point2.getY();

    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    double sindLat = Math.sin(dLat / 2);
    double sindLon = Math.sin(dLon / 2);
    double a = Math.pow(sindLat, 2)
            + Math.pow(sindLon, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return Constants.EARTH_RADIUS_IN_KM * c;
}

From source file:com.alvermont.terraj.fracplanet.geom.Matrix33.java

/**
 * Get a matrix that represents a rotation around the Z axis
 *
 * @param angle The angle of rotation desired (in radians)
 * @return The corresponding rotation matrix
 *//*from w ww.  j av  a2 s . c  om*/
public static Matrix33 getRotateAboutZ(float angle) {
    final Matrix33 mat = new Matrix33();

    final float ca = (float) Math.cos(angle);
    final float sa = (float) Math.sin(angle);

    mat.basis[0] = new SimpleXYZ(ca, sa, 0.0f);
    mat.basis[1] = new SimpleXYZ(-sa, ca, 0.0f);
    mat.basis[2] = new SimpleXYZ(0.0f, 0.0f, 1.0f);

    return mat;
}

From source file:Quaternion.java

/**
 * Return an interpolated quaternion, based on this quaternion, the given quaternion q2, and the
 * parameter t. //from www .  j a va2s  .c  o m
 * @param q2 quaternion to interpolate against
 * @param t interpolation parameter in [0,1]
 * @return
 */
public final Quaternion interpolate(Quaternion q2, double t) {
    //seems to be slerp interpolation of quaterions [02 03 2008]
    Quaternion qa = this;
    Quaternion qb = q2;
    //      qa sin((1-t) theta) + qb sin( t theta )
    //qm = ---------------------------------------  0<t<1 
    //                    sin theta
    //       
    //  theta = arccos( qa dot qb )
    double theta = Math.acos(qa.dot(qb));

    if (Math.abs(theta) < 1e-7) {
        return this;
    }

    return qa.multiply(Math.sin((1 - t) * theta)).add(qb.multiply(Math.sin(t * theta)))
            .multiply(1 / Math.sin(theta));
}

From source file:de.avanux.livetracker.statistics.TrackingStatistics.java

/**
 * Distance calculation between 2 Geopoint by Haversine formula
 * /*  ww  w.ja v  a  2s.  com*/
 * Origin:
 * http://www.anddev.org/distance_calculation_between_2_geopoint_by_haversine_formula-t3062.html
 * 
 * @param lat_a
 * @param lon_a
 * @param lat_b
 * @param lon_b
 * @return distance in meters
 */
private double calculateDistance(float lat_a, float lon_a, float lat_b, float lon_b) {
    float pk = (float) (180 / 3.14169);

    float a1 = lat_a / pk;
    float a2 = lon_a / pk;
    float b1 = lat_b / pk;
    float b2 = lon_b / pk;

    double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2);
    double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2);
    double t3 = Math.sin(a1) * Math.sin(b1);
    double tt = Math.acos(t1 + t2 + t3);

    return 6366000 * tt;
}