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

/**
 * Given two angles in degrees, determine the smallest angle between them.
 *
 * For example, given angles 90 and 170, the smallest angle difference would be 80
 * and the larger angle difference would be 280.
 *
 * @param firstAngleDeg//ww w .ja v a2  s  .c om
 * @param secondAngleDeg
 * @return smallest angle
 */
public static double smallestAngularDifferenceDegrees(double firstAngleDeg, double secondAngleDeg) {
    double rawDiffDeg = firstAngleDeg - secondAngleDeg;
    double rawDiffRad = rawDiffDeg * Math.PI / 180;
    double wrappedDiffRad = Math.atan2(Math.sin(rawDiffRad), Math.cos(rawDiffRad));
    double wrappedDiffDeg = wrappedDiffRad * 180 / Math.PI;

    return wrappedDiffDeg;
}

From source file:com.discursive.jccook.lang.StopWatchExample.java

private void start() {
    NumberFormat format = NumberFormat.getInstance();

    System.out.println("How long does it take to take the sin of 0.34 ten million times?");
    clock.start();// w w  w. j av  a  2 s .  c  o m
    for (int i = 0; i < 100000000; i++) {
        Math.sin(0.34);
    }
    clock.stop();

    System.out.println("It takes " + clock.getTime() + " milliseconds");

    System.out.println("How long does it take to multiply 2 doubles one billion times?");
    clock.reset();
    clock.start();
    for (int i = 0; i < 1000000000; i++) {
        double result = 3423.2234 * 23e-4;
    }
    clock.stop();
    System.out.println("It takes " + clock.getTime() + " milliseconds.");

    System.out.println("How long does it take to add 2 ints one billion times?");
    clock.reset();
    clock.start();
    for (int i = 0; i < 1000000000; i++) {
        int result = 293842923 + 33382922;
    }
    clock.stop();
    System.out.println("It takes " + clock.getTime() + " milliseconds.");

    System.out.println("Testing the split() method.");
    clock.reset();
    clock.start();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    clock.split();
    System.out.println("Split Time after 1 sec: " + clock.getTime());
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    System.out.println("Split Time after 2 sec: " + clock.getTime());
    clock.unsplit();
    try {
        Thread.sleep(1000);
    } catch (Exception e) {
    }
    System.out.println("Time after 3 sec: " + clock.getTime());

}

From source file:com.deicos.lince.components.SinChartComponent.java

public SinChartComponent() {
    NumberAxis xAxis = new NumberAxis();
    xAxis.setLabel("x");
    NumberAxis yAxis = new NumberAxis();
    yAxis.setLabel("y");
    XYChart.Series<Number, Number> series = new XYChart.Series<>();
    series.setName("Sine");
    ObservableList<XYChart.Data<Number, Number>> data = series.getData();
    for (double x = -Math.PI; x < Math.PI; x += 0.5) {
        data.add(new XYChart.Data<Number, Number>(x, 10 * Math.sin(x)));
    }/*from   w w  w .j  a v a  2s . com*/
    LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
    lineChart.setTitle("Sine function");
    lineChart.getData().add(series);

    getChildren().add(lineChart);
}

From source file:demo.components.SinChartComponent.java

public SinChartComponent() {

    NumberAxis xAxis = new NumberAxis();
    xAxis.setLabel("x");

    NumberAxis yAxis = new NumberAxis();
    yAxis.setLabel("y");

    XYChart.Series<Number, Number> series = new XYChart.Series<>();
    series.setName("Sine");

    ObservableList<XYChart.Data<Number, Number>> data = series.getData();

    for (double x = -Math.PI; x < Math.PI; x += 0.5) {
        data.add(new XYChart.Data<Number, Number>(x, 10 * Math.sin(x)));
    }/*from  w w w .ja va  2s . c o  m*/

    LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
    lineChart.setTitle("Sine function");
    lineChart.getData().add(series);

    getChildren().add(lineChart);
}

From source file:com.golemgame.util.SinFunction.java

public double value(double x) {
    return Math.sin((float) x / lambda + phase) * amplitude;
}

From source file:Main.java

private static float transformAngle(Matrix m, float angleRadians) {
    // Construct and transform a vector oriented at the specified clockwise
    // angle from vertical.  Coordinate system: down is increasing Y, right is
    // increasing X.
    float[] v = new float[2];
    v[0] = (float) Math.sin(angleRadians);
    v[1] = (float) -Math.cos(angleRadians);
    m.mapVectors(v);/*from w  w w.  j a  v  a  2 s. c o  m*/

    // Derive the transformed vector's clockwise angle from vertical.
    float result = (float) Math.atan2(v[0], -v[1]);
    if (result < -Math.PI / 2) {
        result += Math.PI;
    } else if (result > Math.PI / 2) {
        result -= Math.PI;
    }
    return result;
}

From source file:com.mapr.synth.drive.GeoPoint.java

public GeoPoint(double latitude, double longitude) {
    double c = Math.cos(latitude);
    r = new Vector3D(Math.cos(longitude) * c, Math.sin(longitude) * c, Math.sin(latitude));
}

From source file:com.offbynull.peernetic.debug.visualizer.VisualizerUtils.java

/**
 * Creates point on a circle./*from   ww  w.ja va2 s . c o m*/
 * @param radius radius of circle
 * @param percentage 0 to 1 percentage of where point is on circle -- 0.0 indicates that the point is at the top middle
 * @return new point on circle specified by {@code radius} and {@code percentage}
 * @throws IllegalArgumentException if {@code radius} is negative or a special double value (e.g. NaN/infinite/etc..), or if
 * {@code percentage} isn't between {@code 0.0 - 1.0}
 */
public static Point pointOnCircle(double radius, double percentage) {
    Validate.inclusiveBetween(0.0, Double.MAX_VALUE, radius);
    Validate.inclusiveBetween(0.0, 1.0, percentage);
    double angle = percentage * Math.PI * 2.0;
    angle -= Math.PI / 2.0; // adjust so that percentage 0.0 is at top middle, if not it'ld be at middle right

    double y = (Math.sin(angle) * radius) + radius; // NOPMD
    double x = (Math.cos(angle) * radius) + radius; // NOPMD

    return new Point((int) x, (int) y);
}

From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.MichalewiczFunction.java

@Override
public double map(RealVector v) {
    double[] x = v.toArray();
    double sum = 0.0;
    for (int i = 0; i < x.length; i++) {
        sum += Math.sin(x[i]) * Math.pow(Math.sin((i + 1) * x[i] * x[i] / Math.PI), 2 * m);
    }/*from   ww w . j  a v  a2 s . co m*/
    return -sum;
}

From source file:Clock.java

public void paint(Graphics g) {
    int xhour, yhour, xminute, yminute, xsecond, ysecond, second, minute, hour;
    drawStructure(g);/*  w ww .  j  a  va2  s.c  o m*/

    currentDate = new Date();

    formatter.applyPattern("s");
    second = Integer.parseInt(formatter.format(currentDate));
    formatter.applyPattern("m");
    minute = Integer.parseInt(formatter.format(currentDate));

    formatter.applyPattern("h");
    hour = Integer.parseInt(formatter.format(currentDate));

    xsecond = (int) (Math.cos(second * 3.14f / 30 - 3.14f / 2) * 45 + xcenter);
    ysecond = (int) (Math.sin(second * 3.14f / 30 - 3.14f / 2) * 45 + ycenter);
    xminute = (int) (Math.cos(minute * 3.14f / 30 - 3.14f / 2) * 40 + xcenter);
    yminute = (int) (Math.sin(minute * 3.14f / 30 - 3.14f / 2) * 40 + ycenter);
    xhour = (int) (Math.cos((hour * 30 + minute / 2) * 3.14f / 180 - 3.14f / 2) * 30 + xcenter);
    yhour = (int) (Math.sin((hour * 30 + minute / 2) * 3.14f / 180 - 3.14f / 2) * 30 + ycenter);

    // Erase if necessary, and redraw
    g.setColor(Color.lightGray);
    if (xsecond != lastxs || ysecond != lastys) {
        g.drawLine(xcenter, ycenter, lastxs, lastys);
    }
    if (xminute != lastxm || yminute != lastym) {
        g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
        g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
    }
    if (xhour != lastxh || yhour != lastyh) {
        g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
        g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
    }

    g.setColor(Color.darkGray);
    g.drawLine(xcenter, ycenter, xsecond, ysecond);

    g.setColor(Color.red);
    g.drawLine(xcenter, ycenter - 1, xminute, yminute);
    g.drawLine(xcenter - 1, ycenter, xminute, yminute);
    g.drawLine(xcenter, ycenter - 1, xhour, yhour);
    g.drawLine(xcenter - 1, ycenter, xhour, yhour);
    lastxs = xsecond;
    lastys = ysecond;
    lastxm = xminute;
    lastym = yminute;
    lastxh = xhour;
    lastyh = yhour;
}