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:es.emergya.geo.util.Lambert.java

private LatLon Clark2GRS80(LatLon lambert) {
    double lat = lambert.lat(); // in radian
    double lon = lambert.lon();
    // Lambert geographic => Lambert cartesian
    double N = Ellipsoid.clarke.a / (Math.sqrt(1.0 - Ellipsoid.clarke.e2 * Math.sin(lat) * Math.sin(lat)));
    double X = (N/* +height */) * Math.cos(lat) * Math.cos(lon);
    double Y = (N/* +height */) * Math.cos(lat) * Math.sin(lon);
    double Z = (N * (1.0 - Ellipsoid.clarke.e2)/* + height */) * Math.sin(lat);
    // Lambert => WGS84 ellipsoide similarity
    X += -168.0;// ww w  .j  a va2  s  . c o m
    Y += -60.0;
    Z += 320.0;
    // WGS84 cartesian => WGS84 geographic
    return Geographic(X, Y, Z, Ellipsoid.GRS80);
}

From source file:com.example.gps_project.Places.java

public static double D_jw(double wd1, double jd1, double wd2, double jd2) {
    double x, y, out;
    double PI = 3.14159265;
    double R = 6.371229 * 1e6;

    x = (jd2 - jd1) * PI * R * Math.cos(((wd1 + wd2) / 2) * PI / 180) / 180;
    y = (wd2 - wd1) * PI * R / 180;/*  www .  j  av  a 2 s .  co m*/
    out = Math.hypot(x, y);
    return out / 1000;
}

From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.ImuOCfQuaternion.java

/**
 * Create an angle-axis vector, in this case a unit quaternion, from the
 * provided Euler angle's (presumably from SensorManager.getOrientation()).
 * //from  w ww . ja va 2s  .c om
 * Equation from
 * http://www.euclideanspace.com/maths/geometry/rotations/conversions
 * /eulerToQuaternion/
 * 
 * @param orientation
 */
private void getRotationVectorFromAccelMag(float[] orientation) {
    // Assuming the angles are in radians.

    // getOrientation() values:
    // values[0]: azimuth, rotation around the Z axis.
    // values[1]: pitch, rotation around the X axis.
    // values[2]: roll, rotation around the Y axis.

    // Heading, Azimuth, Yaw
    double c1 = Math.cos(-orientation[0] / 2);
    double s1 = Math.sin(-orientation[0] / 2);

    // Pitch, Attitude
    // The equation assumes the pitch is pointed in the opposite direction
    // of the orientation vector provided by Android, so we invert it.
    double c2 = Math.cos(-orientation[1] / 2);
    double s2 = Math.sin(-orientation[1] / 2);

    // Roll, Bank
    double c3 = Math.cos(orientation[2] / 2);
    double s3 = Math.sin(orientation[2] / 2);

    double c1c2 = c1 * c2;
    double s1s2 = s1 * s2;

    double w = c1c2 * c3 - s1s2 * s3;
    double x = c1c2 * s3 + s1s2 * c3;
    double y = s1 * c2 * c3 + c1 * s2 * s3;
    double z = c1 * s2 * c3 - s1 * c2 * s3;

    // The quaternion in the equation does not share the same coordinate
    // system as the Android gyroscope quaternion we are using. We reorder
    // it here.

    // Android X (pitch) = Equation Z (pitch)
    // Android Y (roll) = Equation X (roll)
    // Android Z (azimuth) = Equation Y (azimuth)

    quatAccelMag = new Quaternion(w, z, x, y);
}

From source file:com.kircherelectronics.accelerationexplorer.filter.ImuLaCfQuaternion.java

/**
 * Create an angle-axis vector, in this case a unit quaternion, from the
 * provided Euler angle's (presumably from SensorManager.getOrientation()).
 * //  ww  w  .j av  a  2  s.c  om
 * Equation from
 * http://www.euclideanspace.com/maths/geometry/rotations/conversions
 * /eulerToQuaternion/
 * 
 * @param orientation
 */
private void getRotationVectorFromAccelMag(float[] orientation) {
    // Assuming the angles are in radians.

    // getOrientation() values:
    // values[0]: azimuth, rotation around the Z axis.
    // values[1]: pitch, rotation around the X axis.
    // values[2]: roll, rotation around the Y axis.

    // Heading, Azimuth, Yaw
    double c1 = Math.cos(orientation[0] / 2);
    double s1 = Math.sin(orientation[0] / 2);

    // Pitch, Attitude
    // The equation assumes the pitch is pointed in the opposite direction
    // of the orientation vector provided by Android, so we invert it.
    double c2 = Math.cos(-orientation[1] / 2);
    double s2 = Math.sin(-orientation[1] / 2);

    // Roll, Bank
    double c3 = Math.cos(orientation[2] / 2);
    double s3 = Math.sin(orientation[2] / 2);

    double c1c2 = c1 * c2;
    double s1s2 = s1 * s2;

    double w = c1c2 * c3 - s1s2 * s3;
    double x = c1c2 * s3 + s1s2 * c3;
    double y = s1 * c2 * c3 + c1 * s2 * s3;
    double z = c1 * s2 * c3 - s1 * c2 * s3;

    // The quaternion in the equation does not share the same coordinate
    // system as the Android gyroscope quaternion we are using. We reorder
    // it here.

    // Android X (pitch) = Equation Z (pitch)
    // Android Y (roll) = Equation X (roll)
    // Android Z (azimuth) = Equation Y (azimuth)

    quatAccelMag = new Quaternion(w, z, x, y);
}

From source file:MyJava3D.java

public void setViewAngle(Vector3d angle) {
    this.viewAngle = angle;
    // System.out.println( "ViewAngle: " + viewAngle );

    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);

    view.x = (float) (-CP * ST);
    view.y = (float) (-CP * CT);
    view.z = (float) SP;

    if (lightRelativeToView != false) {
        lightAngle.x = viewAngle.x + lightAngleOffset.x;
        lightAngle.y = viewAngle.y + lightAngleOffset.y;
        lightAngle.z = viewAngle.z + lightAngleOffset.z;
        setLightAngle(lightAngle);/*from ww  w .  j ava2  s  .  c  o  m*/
    }
}

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.
 * //  w  ww  .  j  a  v a2s.c om
 * @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];/*  w  w  w. j  a va2s.  c o 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
 * // w w w.ja  v  a2  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 ww . j  a  v a 2s  . com*/
 *   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:gui.GraphsPanel.java

/** detectWeakEdges().
 * //from w w  w  . java2 s .c  o  m
 */
public void detectWeakEdges(TreeNode root, float sensitivity) {
    Color customColor = Color.WHITE;

    // TV get a snapshot of original colors for each node with singleton
    Color prevColor = null;

    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> en = ((DefaultMutableTreeNode) root).breadthFirstEnumeration();
    while (en.hasMoreElements()) {
        DefaultMutableTreeNode node = en.nextElement();
        DenNode dNode = (DenNode) node.getUserObject();
        Integer level = node.getLevel();

        if (prevColor == null) {
            prevColor = dNode.getColor();
        }

        if (level == 0) {
            dNode.setColor(customColor);
        } else if (level != 0) {
            DenNode pdNode = (DenNode) ((DefaultMutableTreeNode) (node.getParent())).getUserObject();
            if ((dNode.getSimilarity() > this.getThreshold()) && (pdNode.getColor().equals(Color.WHITE))) {
                dNode.setColor(
                        Color.getHSBColor((float) (Math.cos(dNode.getSimilarity() * 90) * 360), 0.8f, 0.8f));
            } else {
                dNode.setColor(pdNode.getColor());
            }
            dNode.resetEdgeColor();
            if (((dNode.getSimilarity() - pdNode.getSimilarity()) > sensitivity)) {
                dNode.setEdgeColor(Color.RED);
            }
        }
    }
}