Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine of an angle.

Usage

From source file:jtrace.scenes.OneCubeAnimate.java

public static void main(String[] args) throws IOException {

    Scene scene = new Scene();

    scene.addLightSource(new LightSource(new Vector3D(-3, 3, -3), 4));
    scene.addLightSource(new LightSource(new Vector3D(6, 6, -3), 4));

    FlatTexture cubeTexture = (new FlatTexture(new SolidPigment(new Colour(0, 0, 1))));
    cubeTexture.addFinish(new DiffuseFinish(1.0));
    cubeTexture.addFinish(new AmbientFinish(0.1));
    cubeTexture.addFinish(new MirrorFinish(0.2));

    Cube cube = new Cube(new Vector3D(0, 0, 0), 0.5);
    cube.addTexture(cubeTexture);/*  w w w.  ja  v a  2 s.co  m*/
    scene.addObject(cube);

    //        FlatTexture floorTexture = new FlatTexture(new CheckeredPigment(
    //                new Colour(.5,.5,.5), new Colour(1,1,1), 1));
    FlatTexture floorTexture = new FlatTexture(new ImagePigment(new File("wood.jpg"), 1.0));
    floorTexture.addFinish(new DiffuseFinish(1.0));

    Plane plane = new Plane(new Vector3D(0, -0.25, 0), Vector3D.PLUS_J, Vector3D.PLUS_K);
    plane.addTexture(floorTexture);
    scene.addObject(plane);

    Vector3D pointAt = new Vector3D(0, 0, 0);

    int steps = 100;
    for (int i = 0; i < steps; i++) {
        double R = 2.0;
        double x = R * Math.sin(i * 2 * Math.PI / steps);
        double z = -R * Math.cos(i * 2 * Math.PI / steps);
        Camera camera = new Camera(new Vector3D(x, 1, z), pointAt, Vector3D.PLUS_J, 1.0, 800.0 / 600.0);
        scene.setCamera(camera);
        BufferedImage image = scene.render(800, 600, 10);
        ImageIO.write(image, "PNG", new File(String.format("out_%02d.png", i)));
    }
}

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

public static void main(String[] args) {
    final Display display = new Display();

    final Image image = new Image(display, 110, 60);
    GC gc = new GC(image);
    Font font = new Font(display, "Times", 30, SWT.BOLD);
    gc.setFont(font);/*from  www  .  j a v a  2  s  .c  o m*/
    gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
    gc.fillRectangle(0, 0, 110, 60);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gc.drawText("SWT", 10, 10, true);
    font.dispose();
    gc.dispose();

    final Rectangle rect = image.getBounds();
    Shell shell = new Shell(display);
    shell.setText("Matrix Tranformations");
    shell.setLayout(new FillLayout());
    final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED);
    canvas.addPaintListener(e -> {
        GC gc1 = e.gc;
        gc1.setAdvanced(true);
        if (!gc1.getAdvanced()) {
            gc1.drawText("Advanced graphics not supported", 30, 30, true);
            return;
        }

        // Original image
        int x = 30, y = 30;
        gc1.drawImage(image, x, y);
        x += rect.width + 30;

        Transform transform = new Transform(display);

        // Note that the tranform is applied to the whole GC therefore
        // the coordinates need to be adjusted too.

        // Reflect around the y axis.
        transform.setElements(-1, 0, 0, 1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, -1 * x - rect.width, y);

        x = 30;
        y += rect.height + 30;

        // Reflect around the x axis.
        transform.setElements(1, 0, 0, -1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, x, -1 * y - rect.height);

        x += rect.width + 30;

        // Reflect around the x and y axes
        transform.setElements(-1, 0, 0, -1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, -1 * x - rect.width, -1 * y - rect.height);

        x = 30;
        y += rect.height + 30;

        // Shear in the x-direction
        transform.setElements(1, 0, -1, 1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, 300, y);

        // Shear in y-direction
        transform.setElements(1, -1, 0, 1, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, 150, 475);

        // Rotate by 45 degrees
        float cos45 = (float) Math.cos(Math.PI / 4);
        float sin45 = (float) Math.sin(Math.PI / 4);
        transform.setElements(cos45, sin45, -sin45, cos45, 0, 0);
        gc1.setTransform(transform);
        gc1.drawImage(image, 400, 60);

        transform.dispose();
    });

    shell.setSize(350, 550);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    image.dispose();
    display.dispose();
}

From source file:Main.java

public static float cos(double degree) {
    return (float) Math.cos(Math.toRadians(degree));
}

From source file:Main.java

public static float[] rotate2d(float x0, float y0, float th) {
    float cos = (float) Math.cos(th);
    float sin = (float) Math.sin(th);
    float x = x0 * cos - y0 * sin;//x' = x*cos b - y*sin b
    float y = x0 * sin + y0 * cos;//y' = x*sin b + y*cos b
    return new float[] { x, y };
}

From source file:Main.java

public static double computeX(int centerX, int radius, double angle) {
    return centerX + radius * Math.cos(angle * Math.PI / 180);
}

From source file:Main.java

public static double[] zRotate(double angle, double[] gVector) {
    double[][] matrix = { { Math.cos(angle), Math.sin(angle), 0, 0 },
            { -Math.sin(angle), Math.cos(angle), 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } };
    double[] tempDot = { gVector[0], gVector[1], gVector[2], gVector[3], };
    for (int j = 0; j < tempDot.length; j++) {
        gVector[j] = (tempDot[0] * matrix[0][j] + tempDot[1] * matrix[1][j] + tempDot[2] * matrix[2][j]
                + tempDot[3] * matrix[3][j]);
    }//w w w  .ja v a  2s.c o  m
    return gVector;
}

From source file:Main.java

private static void multTwiddleFactor(int index, float[] real, float[] img, int pos, int sum) {

    float cosArg = (float) Math.cos(-2.0f * Math.PI * pos / (float) sum);
    float sinArg = (float) Math.sin(-2.0f * Math.PI * pos / (float) sum);

    float r = real[index] * cosArg - img[index] * sinArg;
    float i = real[index] * sinArg + img[index] * cosArg;

    real[index] = r;/*w  ww.j  a  v a2  s. co m*/
    img[index] = i;
}

From source file:Main.java

public static float getAngleToCoordinates(double _direction, float _startX, float _startY, char _type) {
    if (_type == 'x') {
        return _startX + (float) Math.cos((_direction * Math.PI) / 180);
    } else {/*from   w  w w . j a v  a  2  s.c om*/
        return _startY + (float) Math.sin((_direction * Math.PI) / 180);
    }
}

From source file:Main.java

/**
 * Calculate sec(x)./*from w ww  .j a v a  2 s . c o  m*/
 * 
 * @param x
 *          x
 * @return sec(x)
 * @since 1.0
 */
protected static double sec(double x) {
    return 1.0 / Math.cos(x);
}

From source file:Main.java

public static float getRadiusCosineCoefficient(final float valuePositionInDegrees) {
    final double valuePositionInRadians = Math.toRadians((double) valuePositionInDegrees);
    return (float) Math.cos(valuePositionInRadians);
}