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:imagingbook.pub.fd.FourierDescriptor.java

/**
 * Returns the spatial point reconstructed from a single
 * DFT coefficient 'Gm' with frequency 'm' at 
 * position 't' in [0,1].//  w ww .j a v a  2 s  .c om
 */
private Complex getReconstructionPoint(Complex Gm, int m, double t) {
    double wm = 2 * Math.PI * m;
    double Am = Gm.re;
    double Bm = Gm.im;
    double cost = Math.cos(wm * t);
    double sint = Math.sin(wm * t);
    double xt = Am * cost - Bm * sint;
    double yt = Bm * cost + Am * sint;
    return new Complex(xt, yt);
}

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

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

    double a = Math.cos(ry) * Math.cos(rz);
    double b = -Math.cos(rx) * Math.sin(rz) + Math.sin(rx) * Math.sin(ry) * Math.cos(rz);
    double c = Math.sin(rx) * Math.sin(rz) + Math.cos(rx) * Math.sin(ry) * Math.cos(rz);

    return a * tx + b * ty + c * tz;
}

From source file:com.georgeme.Act_Circle.java

public double CalculationByDistance(LatLng StartP, LatLng EndP) {
    int Radius = 6371;// radius of earth in Km
    double lat1 = StartP.latitude;
    double lat2 = EndP.latitude;
    double lon1 = StartP.longitude;
    double lon2 = EndP.longitude;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    double c = 2 * Math.asin(Math.sqrt(a));
    return Radius * c * 1000;
}

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()).
 * /*w  w w.  j a  v a 2s . 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:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

/**
 * Render the pie chart with the given height
 * /*  w w w. jav  a  2 s  .co  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: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: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 .  j a va  2s. co 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.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:geogebra.common.kernel.geos.GeoVec2D.java

/**
 * rotate this vector by angle phi/*from  w  ww. java  2  s  . c o m*/
 * 
 * @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;
}