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: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.
 * /*w w  w  . java 2  s. c o  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  ww  w .  java 2  s.co 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.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void cosNinety() {
    try {//from  w ww  .  ja  v  a2s.  c  o  m
        Expression expression = getExpressionWithFunctionContext("cos(90)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.cos(90), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

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:de.avanux.livetracker.statistics.TrackingStatistics.java

/**
 * Distance calculation between 2 Geopoint by Haversine formula
 * /*from w ww  .  j a  v  a  2 s. c om*/
 * 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;
}

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   www  .  ja va2  s .  co m
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: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:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.RotationMatrixBuilder.java

/**
 * Returns a rotation matrix for rotating about the 2D plane defined by
 * the specified axes./*from  www .  j  a v a2 s .  c  o  m*/
 * 
 * @param i the first axis
 * @param j the second axis
 * @param theta the rotation angle in radians
 * @return a rotation matrix for rotating about the 2D plane defined by
 *         the specified axes
 */
private RealMatrix newRotationMatrix(int i, int j, double theta) {
    RealMatrix rotation = newIdentityMatrix();

    rotation.setEntry(i, i, Math.cos(theta));
    rotation.setEntry(i, j, -Math.sin(theta));
    rotation.setEntry(j, i, Math.sin(theta));
    rotation.setEntry(j, j, Math.cos(theta));

    return rotation;
}

From source file:org.jfree.experimental.chart.renderer.xy.VectorRenderer.java

/**
 * Draws the block representing the specified item.
 * //from   w  w w  .  j  a  v a  2s. com
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double dx = 0.0;
    double dy = 0.0;
    if (dataset instanceof VectorXYDataset) {
        dx = ((VectorXYDataset) dataset).getDeltaXValue(series, item);
        dy = ((VectorXYDataset) dataset).getDeltaYValue(series, item);
    }
    double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge());
    Line2D line;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        line = new Line2D.Double(yy0, xx0, yy1, xx1);
    } else {
        line = new Line2D.Double(xx0, yy0, xx1, yy1);
    }
    g2.setPaint(getItemPaint(series, item));
    g2.setStroke(getItemStroke(series, item));
    g2.draw(line);

    // calculate the arrow head and draw it...
    double dxx = (xx1 - xx0);
    double dyy = (yy1 - yy0);
    double bx = xx0 + (1.0 - this.baseLength) * dxx;
    double by = yy0 + (1.0 - this.baseLength) * dyy;

    double cx = xx0 + (1.0 - this.headLength) * dxx;
    double cy = yy0 + (1.0 - this.headLength) * dyy;

    double angle = 0.0;
    if (dxx != 0.0) {
        angle = Math.PI / 2.0 - Math.atan(dyy / dxx);
    }
    double deltaX = 2.0 * Math.cos(angle);
    double deltaY = 2.0 * Math.sin(angle);

    double leftx = cx + deltaX;
    double lefty = cy - deltaY;
    double rightx = cx - deltaX;
    double righty = cy + deltaY;

    GeneralPath p = new GeneralPath();
    p.moveTo((float) xx1, (float) yy1);
    p.lineTo((float) rightx, (float) righty);
    p.lineTo((float) bx, (float) by);
    p.lineTo((float) leftx, (float) lefty);
    p.closePath();
    g2.draw(p);

}