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.seekret.data.flickr.FlickrRequestHandler.java

/**
 * This method generates satelites around a given spot. Attention, using
 * this method for requests to flickr, we can get problems with write/read
 * operations and problems with the spot size ( > 1MB) concerning memcache.
 * /*from   w  ww.ja va2s  .c o  m*/
 * @param spot
 *            given Spot.
 * @param allPoints
 *            Map of Points with spotradius.
 */
@SuppressWarnings("unused")
private void createSatelitesArroundGivenSpot(Spot spot, HashMap<LatLng, Double> allPoints) {
    for (int degree = 0; degree < 316; degree += 45) {
        double d = spot.getSpotRadiusInKm() + (spot.getSpotRadiusInKm() / 2.0);
        System.out.println("Distance = " + d);
        double dist = d / 6371.0;
        double brng = Math.toRadians(degree);
        double lat1 = Math.toRadians(spot.getLatitude());
        double lon1 = Math.toRadians(spot.getLongitude());

        double lat2 = Math
                .asin(Math.sin(lat1) * Math.cos(dist) + Math.cos(lat1) * Math.sin(dist) * Math.cos(brng));
        double a = Math.atan2(Math.sin(brng) * Math.sin(dist) * Math.cos(lat1),
                Math.cos(dist) - Math.sin(lat1) * Math.sin(lat2));
        System.out.println("a = " + a);
        double lon2 = lon1 + a;

        lon2 = (lon2 + 3 * Math.PI) % (2 * Math.PI) - Math.PI;

        double latitude2 = Math.toDegrees(lat2);
        double longitude2 = Math.toDegrees(lon2);
        System.out.println("Latitude = " + latitude2 + "\nLongitude = " + longitude2);

        LatLng origin = new LatLng(spot.getLatitude(), spot.getLongitude());
        LatLng newPoint = new LatLng(latitude2, longitude2);

        log.log(Level.INFO,
                "DISTANCE TO CENTER " + (LatLngTool.distance(origin, newPoint, LengthUnit.KILOMETER)));
        allPoints.put(newPoint, Double.valueOf(spot.getSpotRadiusInKm() / 2.0));
    }
}

From source file:rod_design_compute.ShowPanel.java

private void drawBlock(Rod rod, Point point, Graphics g) {
    int[] x = new int[4];
    int[] y = new int[4];
    int l = lengthBlock;
    double theta = rod.getAngle();

    x[0] = (int) ((2 * Math.cos(theta) + Math.sin(theta)) * l / 4);
    y[0] = (int) ((2 * Math.sin(theta) - Math.cos(theta)) * l / 4);
    x[1] = (int) ((2 * Math.cos(theta) - Math.sin(theta)) * l / 4);
    y[1] = (int) ((2 * Math.sin(theta) + Math.cos(theta)) * l / 4);
    x[2] = -x[0];//from   ww  w.  j a va2 s  .  co m
    y[2] = -y[0];
    x[3] = -x[1];
    y[3] = -y[1];

    Polygon block = new Polygon();
    for (int i = 0; i < 4; i++) {
        x[i] = toScreenX(point.X) + x[i];
        y[i] = toScreenY(point.Y) - y[i];
        block.addPoint(x[i], y[i]);
    }

    g.setColor(Color.white);
    g.fillPolygon(block);
    g.setColor(Color.black);
    g.drawPolygon(block);
}

From source file:gdsc.smlm.model.CompoundMoleculeModel.java

/**
 * Get the rotation matrix for a rotation around an axis
 * /*from w w w.j  av a  2  s . com*/
 * @param axis
 *            axis
 * @param angle
 *            angle (in degrees)
 * @return The rotation matrix
 */
private double[] getRotationMatrix(double[] axis, double angle) {
    /* Set to unit length */
    double length = 0;
    for (int i = 0; i < 3; i++) {
        length += axis[i] * axis[i];
    }
    if (length == 0 || Double.isNaN(length))
        return I;
    length = Math.sqrt(length);
    for (int i = 0; i < 3; i++) {
        axis[i] /= length;
    }
    //System.out.printf("Angle = %.1f, Axis = %.3f, %.3f, %.3f\n", angle, axis[0], axis[1], axis[2]);

    /* Store the components and their squares */
    final double u = axis[0];
    final double u2 = u * u;
    final double v = axis[1];
    final double v2 = v * v;
    final double w = axis[2];
    final double w2 = w * w;
    final double uv = u * v;
    final double uw = u * w;
    final double vw = v * w;

    angle /= DEGREES_TO_RADIANS;
    final double cost = Math.cos(angle);
    final double sint = Math.sin(angle);

    final double[] r = new double[9];
    /* Set the rotation matrix */
    r[0] = u2 + ((v2 + w2) * cost);
    r[1] = uv - uv * cost - w * sint;
    r[2] = uw - uw * cost + v * sint;
    r[3] = uv - uv * cost + w * sint;
    r[4] = v2 + ((u2 + w2) * cost);
    r[5] = vw - vw * cost - u * sint;
    r[6] = -1.0 * (uw * (-1.0 + cost)) - v * sint;
    r[7] = -1.0 * (vw * (-1.0 + cost)) + u * sint;
    r[8] = w2 + ((u2 + v2) * cost);
    /*
     * r[0] = u2 + ((v2 + w2)*cost);
     * r[3] = uv - uv*cost - w*sint;
     * r[6] = uw - uw*cost + v*sint;
     * r[1] = uv - uv*cost + w*sint;
     * r[4] = v2 + ((u2 + w2)*cost);
     * r[7] = vw - vw*cost - u*sint;
     * r[2] = -1.0*(uw*(-1.0 + cost)) - v*sint;
     * r[5] = -1.0*(vw*(-1.0 + cost)) + u*sint;
     * r[8] = w2 + ((u2 + v2)*cost);
     */
    return r;
}

From source file:io.github.malapert.jwcs.JWcs.java

/**
 * Computes CD matrix from CDELT[] and CROTA.
 *
 *
 * The computation is realized as follows:
 * <pre>/*from   w  w w  .j  a v a  2 s  .  c o  m*/
 *   cos0 = cos(crota)
 *   sin0 = sin(crota)
 *   cd11 = cdelt1 * cos0
 *   cd12 = abs(cdelt2) * signum(cdelt1) * sin0
 *   cd21 = -abs(cdelt1) * signum(cdelt2) * sin0;
 *   cd22 = cdelt2 * cos0;
 * </pre>
 *
 * @param cdelt increment of position
 * @param crota rotation
 * @return the cd matrix as array
 */
protected static final double[][] computeCdFromCdelt(double[] cdelt, double crota) {
    final double cos0 = Math.cos(Math.toRadians(crota));
    final double sin0 = Math.sin(Math.toRadians(crota));
    double cd11 = cdelt[0] * cos0;
    double cd12 = Math.abs(cdelt[1]) * Math.signum(cdelt[0]) * sin0;
    double cd21 = -Math.abs(cdelt[0]) * Math.signum(cdelt[1]) * sin0;
    double cd22 = cdelt[1] * cos0;
    double[][] array = { { cd11, cd12 }, { cd21, cd22 } };
    return array;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the trigonometric sine of the number.
 * //from   w  w w. j a  v  a2 s  .  co  m
 * @param a the number
 * @return the trigonometric sine of the number
 * @see Math#sin(double)
 */
public static Number sin(Number a) {
    return Math.sin(a.doubleValue());
}

From source file:MyJava3D.java

public void setLightAngle(Vector3d angle) {
    this.lightAngle = angle;
    //System.out.println( "LightAngle: " + lightAngle );

    CT = Math.cos(DEG_TO_RAD * viewAngle.x);
    ST = Math.sin(DEG_TO_RAD * viewAngle.x);
    CP = Math.cos(DEG_TO_RAD * viewAngle.y);
    SP = Math.sin(DEG_TO_RAD * viewAngle.y);

    light.x = (float) (Math.sin(DEG_TO_RAD * lightAngle.y) * Math.cos(DEG_TO_RAD * lightAngle.x));
    light.y = (float) (Math.sin(DEG_TO_RAD * lightAngle.y) * Math.sin(DEG_TO_RAD * lightAngle.x));
    light.z = (float) (Math.cos(DEG_TO_RAD * lightAngle.y));
}

From source file:chat.client.agent.ChatClientAgent.java

public static float distance(float lat1, float lng1, float lat2, float lng2) {
    double earthRadius = 3958.75;
    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;

    int meterConversion = 1609;

    return new Float(dist * meterConversion).floatValue();
}

From source file:es.emergya.geo.util.Lambert.java

/**
 * initializes from cartesian coordinates
 *
 * @param X/*  www  .  j  a v a2 s  .  c  o m*/
 *            1st coordinate in meters
 * @param Y
 *            2nd coordinate in meters
 * @param Z
 *            3rd coordinate in meters
 * @param ell
 *            reference ellipsoid
 */
private LatLon Geographic(double X, double Y, double Z, Ellipsoid ell) {
    double norm = Math.sqrt(X * X + Y * Y);
    double lg = 2.0 * Math.atan(Y / (X + norm));
    double lt = Math.atan(Z / (norm * (1.0 - (ell.a * ell.e2 / Math.sqrt(X * X + Y * Y + Z * Z)))));
    double delta = 1.0;
    while (delta > epsilon) {
        double s2 = Math.sin(lt);
        s2 *= s2;
        double l = Math.atan(
                (Z / norm) / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2)))));
        delta = Math.abs(l - lt);
        lt = l;
    }
    double s2 = Math.sin(lt);
    s2 *= s2;
    // h = norm / Math.cos(lt) - ell.a / Math.sqrt(1.0 - ell.e2 * s2);
    return new LatLon(lt, lg);
}

From source file:com.irsa.OnTheGoActivity.java

private double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
    double radLat1 = (lat_a * Math.PI / 180.0);
    double radLat2 = (lat_b * Math.PI / 180.0);
    double a = radLat1 - radLat2;
    double b = (lng_a - lng_b) * Math.PI / 180.0;
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;//from   w  ww  .ja va  2s . co m
    s = Math.round(s * 10000) / 10000;
    return s;

}

From source file:HiResCoordTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    Transform3D t3dTilt = new Transform3D();
    t3dTilt.rotX(0.3);/*ww  w  . j ava 2 s. c o m*/

    TransformGroup objTrans = new TransformGroup(t3dTilt);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    TransformGroup objTransPlanets = new TransformGroup();
    objTransPlanets.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTransPlanets, yAxis, 0.0f,
            (float) Math.PI * 2.0f);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), m_TranslateSunZ);
    rotator.setSchedulingBounds(bounds);
    objTransPlanets.addChild(rotator);

    // create the sun
    TransformGroup sunTg = createSun();

    // create Earth
    Transform3D t3dEarth = new Transform3D();
    t3dEarth.setScale(m_EarthRadius);
    t3dEarth.setTranslation(new Vector3d(m_EarthOrbit, 0, 0));
    objTransPlanets.addChild(createPlanet("Earth", new Color3f(0, 0.1f, 1.0f), t3dEarth, null));

    // create Mars
    Transform3D t3dMars = new Transform3D();
    t3dMars.setTranslation(
            new Vector3d(Math.sin(Math.PI * 1.5) * m_MarsOrbit, 0, Math.cos(Math.PI * 0.5) * m_MarsOrbit));
    t3dMars.setScale(m_MarsRadius);
    objTransPlanets.addChild(createPlanet("Mars", new Color3f(1, 0, 0), t3dMars, null));

    // create Mercury
    Transform3D t3dMercury = new Transform3D();
    t3dMercury.setTranslation(
            new Vector3d(Math.sin(Math.PI) * m_MercuryOrbit, 0, Math.cos(Math.PI) * m_MercuryOrbit));
    t3dMercury.setScale(m_MercuryRadius);
    objTransPlanets.addChild(createPlanet("Mercury", new Color3f(0.5f, 0.5f, 0.5f), t3dMercury, null));

    sunTg.addChild(objTransPlanets);
    objTrans.addChild(sunTg);
    objRoot.addChild(objTrans);

    return objRoot;
}