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:Main.java

public static BufferedImage create(BufferedImage image, double angle, GraphicsConfiguration gc) {
    double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
    int w = image.getWidth(), h = image.getHeight();
    int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin);
    int transparency = image.getColorModel().getTransparency();
    BufferedImage result = gc.createCompatibleImage(neww, newh, transparency);
    Graphics2D g = result.createGraphics();
    g.translate((neww - w) / 2, (newh - h) / 2);
    g.rotate(angle, w / 2, h / 2);//w ww .j a v a 2  s  .c  om
    g.drawRenderedImage(image, null);
    return result;
}

From source file:FillPolyPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    int radius = 40;
    int centerX = 50;
    int centerY = 100;
    int angle = 30;

    int dx = (int) (radius * Math.cos(angle * Math.PI / 180));
    int dy = (int) (radius * Math.sin(angle * Math.PI / 180));

    g.fillArc(centerX - radius, centerY - radius, 2 * radius, 2 * radius, angle, 360 - 2 * angle);

    Polygon p = new Polygon();
    centerX = 150;//from   www  . java2 s  .  co m
    for (int i = 0; i < 5; i++)
        p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)),
                (int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5)));

    g.fillPolygon(p);

    p = new Polygon();
    centerX = 250;
    for (int i = 0; i < 360; i++) {
        double t = i / 360.0;
        p.addPoint((int) (centerX + radius * t * Math.cos(8 * t * Math.PI)),
                (int) (centerY + radius * t * Math.sin(8 * t * Math.PI)));
    }
    g.fillPolygon(p);
}

From source file:org.eclipse.swt.snippets.Snippet209.java

static void drawTorus(GL2 gl, float r, float R, int nsides, int rings) {
    float ringDelta = 2.0f * (float) Math.PI / rings;
    float sideDelta = 2.0f * (float) Math.PI / nsides;
    float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f;
    for (int i = rings - 1; i >= 0; i--) {
        float theta1 = theta + ringDelta;
        float cosTheta1 = (float) Math.cos(theta1);
        float sinTheta1 = (float) Math.sin(theta1);
        gl.glBegin(GL2.GL_QUAD_STRIP);/*from   w w  w  . j a v  a2s.com*/
        float phi = 0.0f;
        for (int j = nsides; j >= 0; j--) {
            phi += sideDelta;
            float cosPhi = (float) Math.cos(phi);
            float sinPhi = (float) Math.sin(phi);
            float dist = R + r * cosPhi;
            gl.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
            gl.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
            gl.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
            gl.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
        }
        gl.glEnd();
        theta = theta1;
        cosTheta = cosTheta1;
        sinTheta = sinTheta1;
    }
}

From source file:Main.java

/**
 * Gets the relative bearing from one geographical coordinate to another.
 *
 * @param latitude1 the latitude of the source point
 * @param longitude1 the longitude of the source point
 * @param latitude2 the latitude of the destination point
 * @param longitude2 the longitude of the destination point
 * @return the relative bearing from point 1 to point 2, in degrees. The result is guaranteed
 *         to fall in the range 0-360// w w w .  j  a v a 2 s.co m
 */
public static float getBearing(double latitude1, double longitude1, double latitude2, double longitude2) {
    latitude1 = Math.toRadians(latitude1);
    longitude1 = Math.toRadians(longitude1);
    latitude2 = Math.toRadians(latitude2);
    longitude2 = Math.toRadians(longitude2);

    double dLon = longitude2 - longitude1;

    double y = Math.sin(dLon) * Math.cos(latitude2);
    double x = Math.cos(latitude1) * Math.sin(latitude2)
            - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(dLon);

    double bearing = Math.atan2(y, x);
    return mod((float) Math.toDegrees(bearing), 360.0f);
}

From source file:Main.java

double f(double x) {
    return Math.sin(x);
}

From source file:com.jennifer.ui.util.MathUtil.java

public static double rotateY(double x, double y, double radian) {
    return x * Math.sin(radian) + y * Math.cos(radian);
}

From source file:LisajousApp.Draw.java

private static XYDataset createDataset() {

    XYSeries s1 = new XYSeries("");

    for (double t = 0; t <= 2 * Math.PI; t = t + 0.0005) {
        double x = Main.a * Math.sin(Main.n * t + Main.c);
        double y = Main.b * Math.sin(t);
        s1.add(x, y);//from   ww w.  j av  a 2 s  .co m
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(s1);
    return dataset;
}

From source file:Main.java

/**
 * <p>This routine calculates the distance between two points (given the
 * latitude/longitude of those points). It is being used to calculate
 * the distance between two locations.</p>
 * <p/>/*from   w ww. j a  v a  2s  .  c o  m*/
 * <p>Definitions: South latitudes are negative, east longitudes are positive</p>
 * <p/>
 * <p>Passed to function:
 * <ul>
 * <li>lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees)</li>
 * <li>lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees)</li>
 * <li>unit = the unit you desire for results
 * <ul>
 * <li>where: 'M' is statute miles</li>
 * <li>'K' is kilometers (default) </li>
 * <li>'N' is nautical miles</li>
 * </ul>
 * </li>
 * </ul>
 * Worldwide cities and other features databases with latitude longitude
 * are available at http://www.geodatasource.com</p>
 * <p/>
 * <p>For enquiries, please contact sales@geodatasource.com</p>
 * <p>Official Web site: http://www.geodatasource.com</p>
 * <p>GeoDataSource.com (C) All Rights Reserved 2013</p>
 *
 * @param lat1 - latitude point 1
 * @param lon1 - longitude point 1
 * @param lat2 - latitude point 2
 * @param lon2 - longitude point 2
 * @param unit - unit of measure (M, K, N)
 * @return the distance between the two points
 */
public static final double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
    double theta = lon1 - lon2;
    double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
            + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
    dist = Math.acos(dist);
    dist = rad2deg(dist);
    dist = dist * 60 * 1.1515;

    if (unit == 'K') {
        dist = dist * 1.609344;
    } else if (unit == 'N') {
        dist = dist * 0.8684;
    }

    return (dist);
}

From source file:org.eclipse.swt.snippets.Snippet195.java

static void drawTorus(float r, float R, int nsides, int rings) {
    float ringDelta = 2.0f * (float) Math.PI / rings;
    float sideDelta = 2.0f * (float) Math.PI / nsides;
    float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f;
    for (int i = rings - 1; i >= 0; i--) {
        float theta1 = theta + ringDelta;
        float cosTheta1 = (float) Math.cos(theta1);
        float sinTheta1 = (float) Math.sin(theta1);
        GL11.glBegin(GL11.GL_QUAD_STRIP);
        float phi = 0.0f;
        for (int j = nsides; j >= 0; j--) {
            phi += sideDelta;//from  www  .jav  a 2s  .c o m
            float cosPhi = (float) Math.cos(phi);
            float sinPhi = (float) Math.sin(phi);
            float dist = R + r * cosPhi;
            GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
            GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
            GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
            GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
        }
        GL11.glEnd();
        theta = theta1;
        cosTheta = cosTheta1;
        sinTheta = sinTheta1;
    }
}

From source file:fsm.series.Series_SS.java

@Override
public double getFunctionValue(double y, int m) {

    return Math.sin(m * Math.PI * y / a);
}