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 void main(String[] args) {
    LongToDoubleFunction i = (l) -> Math.sin(l);

    System.out.println(i.applyAsDouble(Long.MAX_VALUE));
}

From source file:Main.java

public static void main(String[] args) {
    ToDoubleFunction<Integer> i = (x) -> Math.sin(x);

    System.out.println(i.applyAsDouble(Integer.MAX_VALUE));
}

From source file:Main.java

public static void main(String[] args) {
    ToDoubleBiFunction<Integer, Long> i = (x, y) -> Math.sin(x) + Math.sin(y);

    System.out.println(i.applyAsDouble(Integer.MAX_VALUE, Long.MAX_VALUE));
}

From source file:Main.java

public static void main(String[] args) {
    IntToDoubleFunction i = (x) -> {
        return Math.sin(x);
    };/* w ww . ja va  2  s.com*/
    System.out.println(i.applyAsDouble(2));
}

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);

    b.mapToDouble(n -> Math.sin(n)).forEach(System.out::println);
}

From source file:MainClass.java

public static void main(String args[]) {
    double radians = 0.45 * Math.PI / 180;
    System.out.println("sin = " + Math.sin(radians));

}

From source file:MathTest.java

public static void main(String args[]) {
    int angles[] = { 0, 30, 45, 60, 90, 180 };
    for (int i = 0, n = angles.length; i < n; i++) {
        double rad = Math.toRadians(angles[i]);
        System.out.println("Angle: " + angles[i]);
        System.out.println(" Sine  : " + Math.sin(rad));
        System.out.println(" Cosine : " + Math.cos(rad));
        System.out.println(" Tangent: " + Math.tan(rad));
    }/*from   w w w .  j av  a2  s  . c  o m*/
}

From source file:Main.java

public static void main(String[] args) {

    double x = 45;
    double y = -180;

    // convert them to radians
    x = Math.toRadians(x);//from  w w  w. java  2  s.  c o m
    y = Math.toRadians(y);

    // print the trigonometric sine for these doubles
    System.out.println("Math.sin(" + x + ")=" + Math.sin(x));
    System.out.println("Math.sin(" + y + ")=" + Math.sin(y));

}

From source file:Main.java

public static void main(String[] args) {
    final int width = 512;
    final int height = 512;
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics g = img.getGraphics();
    g.setColor(Color.black);/*  ww w  . ja va 2s .  c o  m*/
    g.fillRect(0, 0, width, height);
    g.setColor(Color.white);
    final double A = 8;
    final double B = 0.5;
    final double N = 4;
    final double scale = 128;
    final double zoom = 50;
    final double step = 1 / scale;
    Point last = null;
    final Point origin = new Point(width / 2, height / 2);

    for (double t = 0; t <= 2 * Math.PI; t += step) {
        final double r = zoom * polarFunction(t, A, B, N);
        final int x = (int) Math.round(r * Math.cos(t));
        final int y = (int) Math.round(r * Math.sin(t));
        Point next = new Point(x, y);
        if (last != null) {
            g.drawLine(origin.x + last.x, origin.y + last.y, origin.x + next.x, origin.y + next.y);
        }
        last = next;
    }

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new JLabel(new ImageIcon(img)));
    frame.pack();
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) {
    StopWatch clock = new StopWatch();
    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  .ja va2  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());

}