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.bolatu.gezkoncsvlogger.GyroOrientation.ImuOKfQuaternion.java

/**
 * Create an angle-axis vector, in this case a unit quaternion, from the
 * provided Euler angle's (presumably from SensorManager.getOrientation()).
 * /*from www  . j a  v a2  s.c  o m*/
 * 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)

    qvOrientationAccelMag[0] = z;
    qvOrientationAccelMag[1] = x;
    qvOrientationAccelMag[2] = y;
    qvOrientationAccelMag[3] = w;

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

From source file:io.github.data4all.handler.TagSuggestionHandler.java

/**
 * Get a bounding box of the location./*from   w  w w. j  ava 2  s.co m*/
 * 
 * @param lat
 *            latitude of the location
 * @param lon
 *            longitude of the location
 * @param radius
 *            distance to bounds from location
 * @return a boundingBox
 */
private static double[] getBoundingBox(double lat, double lon, double radius) {
    final double result[] = new double[4];
    result[0] = lat - Math.toDegrees(radius / (double) EARTH_RADIUS); // s
    result[1] = lon - Math.toDegrees(radius / (double) EARTH_RADIUS / Math.cos(Math.toRadians(lat))); // w
    result[2] = lat + Math.toDegrees(radius / (double) EARTH_RADIUS); // n
    result[3] = lon + Math.toDegrees(radius / (double) EARTH_RADIUS / Math.cos(Math.toRadians(lat))); // e
    return result;
}

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

/**
 * Get a matrix that represents a rotation around the Y axis
 *
 * @param angle The angle of rotation desired (in radians)
 * @return The corresponding rotation matrix
 *//*from   w  w w.java 2s  .c  o  m*/
public static Matrix33 getRotateAboutY(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, 0.0f, -sa);
    mat.basis[1] = new SimpleXYZ(0.0f, 1.0f, 0.0f);
    mat.basis[2] = new SimpleXYZ(sa, 0.0f, ca);

    return mat;
}

From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

/**
 * Render the pie chart with the given height
 * /*from   w  ww . j  a va 2  s .  c  o m*/
 * @param height
 *          The height of the resulting image
 * @return The pie chart rendered as an image
 */
public BufferedImage render(int height) {
    BufferedImage image = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.scale(zoom, zoom);
    // fill background to white
    g2.setColor(Color.WHITE);
    g2.fill(new Rectangle(totalWidth, totalHeight));
    // prepare render hints
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    // draw shadow image
    g2.drawImage(pieShadow.getImage(), 0, 0, pieShadow.getImageObserver());

    double start = 0;
    List<Arc2D> pies = new ArrayList<>();
    // pie segmente erzeugen und fuellen
    if (total == 0) {
        g2.setColor(BRIGHT_GRAY);
        g2.fillOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
        g2.setColor(Color.WHITE);
        g2.drawOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius);
    } else {
        for (Segment s : segments) {
            double portionDegrees = s.getPortion() / total;
            Arc2D pie = paintPieSegment(g2, start, portionDegrees, s.getColor());
            if (withSubSegments) {
                double smallRadius = radius * s.getSubSegmentRatio();
                paintPieSegment(g2, start, portionDegrees, smallRadius, s.getColor().darker());
            }
            start += portionDegrees;
            // portion degree jetzt noch als String (z.B. "17.3%" oder "20%" zusammenbauen)
            String p = String.format(Locale.ENGLISH, "%.1f", Math.rint(portionDegrees * 1000) / 10.0);
            p = removeSuffix(p, ".0"); // evtl. ".0" bei z.B. "25.0" abschneiden (-> "25")
            s.setPercent(p + "%");
            pies.add(pie);
        }
        // weissen Rahmen um die pie segmente zeichen
        g2.setColor(Color.WHITE);
        for (Arc2D pie : pies) {
            g2.draw(pie);
        }
    }
    // Legende zeichnen
    renderLegend(g2);
    // "xx%" Label direkt auf die pie segmente zeichen
    g2.setColor(Color.WHITE);
    float fontSize = 32f;
    g2.setFont(NORMALFONT.deriveFont(fontSize).deriveFont(Font.BOLD));
    start = 0;
    for (Segment s : segments) {
        if (s.getPortion() < 1E-6) {
            continue; // ignore segments with portions that are extremely small
        }
        double portionDegrees = s.getPortion() / total;
        double angle = start + portionDegrees / 2; // genau in der Mitte des Segments
        double xOffsetForCenteredTxt = 8 * s.getPercent().length(); // assume roughly 8px per char
        int x = (int) (centerX + 0.6 * radius * Math.sin(2 * Math.PI * angle) - xOffsetForCenteredTxt);
        int y = (int) (centerY - 0.6 * radius * Math.cos(2 * Math.PI * angle) + fontSize / 2);
        g2.drawString(s.getPercent(), x, y);
        start += portionDegrees;
    }
    return image;
}

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

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

    double d = Math.cos(ry) * Math.sin(rz);
    double e = Math.cos(rx) * Math.cos(rz) + Math.sin(rx) * Math.sin(ry) * Math.sin(rz);
    double f = -Math.sin(rx) * Math.cos(rz) + Math.cos(rx) * Math.sin(ry) * Math.sin(rz);

    return d * tx + e * ty + f * tz;
}

From source file:eu.hansolo.tilesfx.tools.Location.java

public double calcDistanceInMeter(final double LAT_1, final double LON_1, final double LAT_2,
        final double LON_2) {
    final double EARTH_RADIUS = 6_371_000; // m
    final double LAT_1_RADIANS = Math.toRadians(LAT_1);
    final double LAT_2_RADIANS = Math.toRadians(LAT_2);
    final double DELTA_LAT_RADIANS = Math.toRadians(LAT_2 - LAT_1);
    final double DELTA_LON_RADIANS = Math.toRadians(LON_2 - LON_1);

    final double A = Math.sin(DELTA_LAT_RADIANS * 0.5) * Math.sin(DELTA_LAT_RADIANS * 0.5)
            + Math.cos(LAT_1_RADIANS) * Math.cos(LAT_2_RADIANS) * Math.sin(DELTA_LON_RADIANS * 0.5)
                    * Math.sin(DELTA_LON_RADIANS * 0.5);
    final double C = 2 * Math.atan2(Math.sqrt(A), Math.sqrt(1 - A));

    final double DISTANCE = EARTH_RADIUS * C;

    return DISTANCE;
}

From source file:geogebra.common.kernel.geos.GeoVec2D.java

/**
 * rotate this vector by angle phi//from w  w  w .j a v  a2 s.  c  om
 * 
 * @param phi
 *            angle
 */
final public void rotate(double phi) {
    double cos = Math.cos(phi);
    double sin = Math.sin(phi);

    double x0 = x * cos - y * sin;
    y = x * sin + y * cos;
    x = x0;
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void cosNull() {
    try {//from w w  w.  j a  v a2 s .  c  om
        getExpressionWithFunctionContext("cos(0)");
        Expression expression = getExpressionWithFunctionContext("cos(0)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.cos(0), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:es.udc.gii.common.eaf.benchmark.real_param.cec2005.CEC2005ObjectiveFunction.java

public double F8F2(double[] x) {
    double temp = 0.0d;
    double res = 0.0d;
    double a, b;//from w  ww .  j av  a 2 s.  c  o  m
    for (int i = 0; i < x.length - 1; i++) {
        a = x[i] * x[i] - x[i + 1];
        b = x[i] - 1.0;
        temp = 100 * a * a + b * b;
        res += (temp * temp) / 4000 - Math.cos(temp) + 1.0;
    }
    a = x[x.length - 1] * x[x.length - 1] - x[0];
    b = x[x.length - 1] - 1.0;
    temp = 100 * a * a + b * b;
    res += (temp * temp) / 4000 - Math.cos(temp) + 1.0;

    return res;
}

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 ava  2 s. co  m*/
    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;
}