Example usage for java.lang Math tan

List of usage examples for java.lang Math tan

Introduction

In this page you can find the example usage for java.lang Math tan.

Prototype

@HotSpotIntrinsicCandidate
public static double tan(double a) 

Source Link

Document

Returns the trigonometric tangent of an angle.

Usage

From source file:Main.java

public static void main(String[] args) {

    double x = 45;
    double y = -180;

    // convert them in radians
    x = Math.toRadians(x);//  w w  w  .  ja  va2s. c o m
    y = Math.toRadians(y);

    // print the tangent of these doubles
    System.out.println("Math.tan(" + x + ")=" + Math.tan(x));
    System.out.println("Math.tan(" + y + ")=" + Math.tan(y));

}

From source file:TrigFun.java

public static void main(String[] args) {
    double rads, degs, tanA, coTanA;

    // Obtain angle in degrees from user
    degs = 120d;/*w w w .j  av  a 2 s  .  c  o m*/
    // Convert degrees to radian
    rads = Math.toRadians(degs);

    // Calculate tangent
    tanA = Math.tan(rads);
    System.out.println("Tangent = " + tanA);

    // Calculate cotangent
    coTanA = 1.0 / Math.tan(rads);
    System.out.println("Cotangent = " + coTanA);

    // Calculate arc-tangent
    rads = Math.atan(tanA);
    degs = Math.toDegrees(rads);
    System.out.println("Arc tangent: " + degs);

    // Calculate arc-cotangent
    rads = Math.atan(1 / coTanA);
    degs = Math.toDegrees(rads);
    System.out.println("Arc cotangent: " + degs);
}

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  a2s  . com*/
}

From source file:TrigSolv.java

public static void main(String[] args) {

    double a, b, c, angleA, radA;

    // Apllying Pythagoras' Theorem
    // Obtain sides from user
    System.out.println("Side c in terms of sides a and b");
    a = 10d;//  ww w .j a v  a 2s .  c  o  m
    b = 20d;
    c = Math.sqrt((a * a) + (b * b));
    System.out.println("Side c = " + c);

    // Using side/angle formula
    System.out.println("Side c in terms of side b and angle A");
    b = 30d;
    angleA = 20d;
    radA = Math.toRadians(angleA);
    c = b * Math.tan(radA);
    System.out.println("Side c = " + c);
}

From source file:MainClass.java

public static void main(String args[]) {
    System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs(23.7));
    System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs(0.0));
    System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs(-23.7));
    System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil(9.2));
    System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil(-9.8));
    System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos(0.0));
    System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp(1.0));
    System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp(2.0));
    System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor(9.2));
    System.out.printf("Math.floor( -9.8 ) = %f\n", Math.floor(-9.8));
    System.out.printf("Math.log( Math.E ) = %f\n", Math.log(Math.E));
    System.out.printf("Math.log( Math.E * Math.E ) = %f\n", Math.log(Math.E * Math.E));
    System.out.printf("Math.max( 2.3, 12.7 ) = %f\n", Math.max(2.3, 12.7));
    System.out.printf("Math.max( -2.3, -12.7 ) = %f\n", Math.max(-2.3, -12.7));
    System.out.printf("Math.min( 2.3, 12.7 ) = %f\n", Math.min(2.3, 12.7));
    System.out.printf("Math.min( -2.3, -12.7 ) = %f\n", Math.min(-2.3, -12.7));
    System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n", Math.pow(2.0, 7.0));
    System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n", Math.pow(9.0, 0.5));
    System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin(0.0));
    System.out.printf("Math.sqrt( 900.0 ) = %f\n", Math.sqrt(900.0));
    System.out.printf("Math.sqrt( 9.0 ) = %f\n", Math.sqrt(9.0));
    System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan(0.0));
}

From source file:TrigonometricDemo.java

public static void main(String[] args) {
    double degrees = 45.0;
    double radians = Math.toRadians(degrees);

    System.out.format("The value of pi is %.4f%n", Math.PI);
    System.out.format("The sine of %.1f degrees is %.4f%n", degrees, Math.sin(radians));
    System.out.format("The cosine of %.1f degrees is %.4f%n", degrees, Math.cos(radians));
    System.out.format("The tangent of %.1f degrees is %.4f%n", degrees, Math.tan(radians));
    System.out.format("The arcsine of %.4f is %.4f degrees %n", Math.sin(radians),
            Math.toDegrees(Math.asin(Math.sin(radians))));
    System.out.format("The arccosine of %.4f is %.4f degrees %n", Math.cos(radians),
            Math.toDegrees(Math.acos(Math.cos(radians))));
    System.out.format("The arctangent of %.4f is %.4f degrees %n", Math.tan(radians),
            Math.toDegrees(Math.atan(Math.tan(radians))));

}

From source file:TrigonometricDemo.java

public static void main(String[] args) {
    double degrees = 45.0;
    double radians = Math.toRadians(degrees);

    System.out.println("The value of pi is " + Math.PI);
    System.out.println("The sine of " + degrees + " is " + Math.sin(radians));
    System.out.println("The cosine of " + degrees + " is " + Math.cos(radians));
    System.out.println("The tangent of " + degrees + " is " + Math.tan(radians));
    System.out.println("The arc sine of " + Math.sin(radians) + " is "
            + Math.toDegrees(Math.asin(Math.sin(radians))) + " degrees");
    System.out.println("The arc cosine of " + Math.cos(radians) + " is "
            + Math.toDegrees(Math.acos(Math.cos(radians))) + " degrees");
    System.out.println("The arc tangent of " + Math.tan(radians) + " is "
            + Math.toDegrees(Math.atan(Math.tan(radians))) + " degrees");
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;//from w w w. j av  a  2s. c o m
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    GL.createCapabilities();

    canvas.addListener(SWT.Resize, event -> {
        Rectangle bounds = canvas.getBounds();
        float fAspect = (float) bounds.width / (float) bounds.height;
        canvas.setCurrent();
        GL.createCapabilities();
        GL11.glViewport(0, 0, bounds.width, bounds.height);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        float near = 0.5f;
        float bottom = -near * (float) Math.tan(45.f / 2);
        float left = fAspect * bottom;
        GL11.glFrustum(left, -left, bottom, -bottom, near, 400.f);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();
    });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    shell.setText("SWT/LWJGL Example");
    shell.setSize(640, 480);
    shell.open();

    final Runnable run = new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                GL.createCapabilities();
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    };
    canvas.addListener(SWT.Paint, event -> run.run());
    display.asyncExec(run);

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

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

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FormLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;/*from w  w w.j a  v  a2 s .com*/
    final GLCanvas canvas = new GLCanvas(shell, SWT.NONE, data);

    canvas.setCurrent();
    GL.createCapabilities();

    canvas.addListener(SWT.Resize, event -> {
        Rectangle bounds = canvas.getBounds();
        float fAspect = (float) bounds.width / (float) bounds.height;
        canvas.setCurrent();
        GL.createCapabilities();
        GL11.glViewport(0, 0, bounds.width, bounds.height);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        float near = 0.5f;
        float bottom = -near * (float) Math.tan(45.f / 2);
        float left = fAspect * bottom;
        GL11.glFrustum(left, -left, bottom, -bottom, near, 400.f);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();
    });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.addListener(SWT.Selection, event -> capture(canvas));

    FormData formData = new FormData(640, 480);
    formData.top = new FormAttachment(0, 0);
    formData.left = new FormAttachment(0, 0);
    formData.bottom = new FormAttachment(button, 0);
    formData.right = new FormAttachment(100, 0);
    canvas.setLayoutData(formData);
    formData = new FormData();
    formData.left = new FormAttachment(0, 0);
    formData.bottom = new FormAttachment(100, 0);
    formData.right = new FormAttachment(100, 0);
    button.setLayoutData(formData);

    shell.pack();
    shell.open();

    display.asyncExec(new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                GL.createCapabilities();
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    });

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:Main.java

public static float coTangent(float f) {
    return 1.0f / (float) Math.tan(f);
}