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:com.bdb.weather.display.windplot.WindItemRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device./*from   w ww .  ja v  a2s  . co m*/
 * @param rendererState  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState rendererState, Rectangle2D dataArea,
        PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, int item, CrosshairState crosshairState, int pass) {
    //
    // Let the base class handle drawing the line and the shapes (passes 0 and 1). This class will handle drawing the
    // wind direction lines.
    //
    if (pass < 2)
        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);
    else {
        if (!(dataset instanceof TimeSeriesCollection) || !showWindDirectionLines)
            return;

        if (item == 0)
            state.resetLastDirection();

        RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

        TimeSeriesCollection collection = (TimeSeriesCollection) dataset;
        TimeSeries timeSeries = collection.getSeries(series);

        if (!(timeSeries instanceof WindSeries))
            return;

        WindSeries windSeries = (WindSeries) timeSeries;
        WindSeriesDataItem windItem = windSeries.getWindDataItem(item);
        double speed = windItem.getWindSpeed().doubleValue();
        double time = dataset.getXValue(series, item);
        double dir = windItem.getWindDirection().doubleValue();

        if (speed > 0.0 && dir != state.getLastDirection()) {
            state.setLastDirection(dir);
            double radians = Math.toRadians(dir - 90.0);
            double dirXOffset = directionLineLength * Math.cos(radians);
            double dirYOffset = directionLineLength * Math.sin(radians);

            double transTime = domainAxis.valueToJava2D(time, dataArea, xAxisLocation);
            double transSpeed = rangeAxis.valueToJava2D(speed, dataArea, yAxisLocation);
            double dirX = transTime + dirXOffset;
            double dirY = transSpeed + dirYOffset;

            // update path to reflect latest point
            if (!Double.isNaN(transTime) && !Double.isNaN(transSpeed)) {
                int x1 = (int) transTime;
                int y1 = (int) transSpeed;
                int x2 = (int) dirX;
                int y2 = (int) dirY;
                PlotOrientation orientation = plot.getOrientation();
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x1 = (int) transSpeed;
                    y1 = (int) transTime;
                    x2 = (int) dirY;
                    y2 = (int) dirX;
                }
                g2.setPaint(windDirectionPaint);
                g2.setStroke(windDirectionStroke);
                g2.drawLine(x1, y1, x2, y2);
            }
        }
    }
}

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static Number funcCos(MutableNumber out, Number x) {
    return out.set(Math.cos(x.r()) * Math.cosh(x.i()), -Math.sin(x.r()) * Math.sinh(x.i()));
}

From source file:graph.GraphExplorer.java

/**
 * create an instance of a simple graph with popup controls to
 * create a graph.//ww w.j a  va  2s .  c o m
 * 
 */
public GraphExplorer(Synset synset) {

    // create a simple graph for the demo
    //        graph = new SparseMultigraph<Gnode,String>();
    map = new HashMap<Synset, Gnode>();
    Graph<Gnode, Gedge> ig = Graphs
            .<Gnode, Gedge>synchronizedDirectedGraph(new DirectedSparseMultigraph<Gnode, Gedge>());

    ObservableGraph<Gnode, Gedge> og = new ObservableGraph<Gnode, Gedge>(ig);
    graph = og;
    this.layout = new SpringLayout<Gnode, Gedge>(graph, new ConstantTransformer(EDGE_LENGTH));
    Dimension d = new Dimension(HEIGHT, WIDTH);
    layout.setSize(d);
    vv = new VisualizationViewer<Gnode, Gedge>(layout);
    vv.setBackground(Color.white);
    GraphMouse gm = new DefaultModalGraphMouse<Gnode, String>();
    vv.setGraphMouse(gm);
    GraphMouseListener<Gnode> gml = new GraphMouseListener<Gnode>() {
        @Override
        public void graphClicked(Gnode gnode, java.awt.event.MouseEvent me) {
            System.out.println(gnode.synset.toString());
            if (!gnode.extended) {
                layout.lock(true);
                Relaxer relaxer = vv.getModel().getRelaxer();
                relaxer.pause();
                gnode.extended = true;
                double x = layout.getX(gnode);
                double y = layout.getY(gnode);
                SynsetPointer[] sp = gnode.synset.getPointers();
                for (int i = 0; i < sp.length; ++i) {
                    Synset synset_ = DataManager.getSingleton().getSynset(sp[i].getSynsetOffset(),
                            sp[i].getPartOfSpeech());
                    if (map.get(synset_) == null)
                        map.put(synset_, new Gnode(synset_));
                    graph.addEdge(new Gedge(sp[i].getPointerSymbol().getDescription()), gnode,
                            map.get(synset_));
                    layout.setLocation(map.get(synset_),
                            x + 0.5 * EDGE_LENGTH * Math.cos(Math.PI * 2 / sp.length * i),
                            y + 0.5 * EDGE_LENGTH * Math.sin(Math.PI * 2 / sp.length * i));
                }
                layout.initialize();
                relaxer.resume();
                layout.lock(false);
            }
        }

        @Override
        public void graphPressed(Gnode arg0, java.awt.event.MouseEvent arg1) {
        }

        @Override
        public void graphReleased(Gnode arg0, java.awt.event.MouseEvent arg1) {
        }
    };
    vv.addGraphMouseListener(gml);
    Transformer<Gnode, Paint> vertexPaint = new Transformer<Gnode, Paint>() {
        public Paint transform(Gnode i) {
            coloring.Color color = ColorManager.getSingleton().getColor(i.synset);
            return new Color(color.getR(), color.getG(), color.getB());
        }
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    /*        Transformer<Gnode,Font> vertexFont = new Transformer<Gnode,Font>() {
               public Font transform(Gnode i) {
      Map<java.awt.font.TextAttribute,Paint> map= new HashMap<java.awt.font.TextAttribute,Paint>();
      map.put(java.awt.font.TextAttribute.BACKGROUND, new Color(255,255,255));
      return new Font(map);
               }
            };
            vv.getRenderContext().setVertexFontTransformer(vertexFont);*/
    Transformer<Gnode, Shape> vertexShape = new Transformer<Gnode, Shape>() {
        public Shape transform(Gnode i) {
            float len = (float) (Math.log(i.synset.getWordCount()) * 10 + 50);
            return new Ellipse2D.Float(-len / 2, -len / 2, len, len);
        }
    };
    vv.getRenderContext().setVertexShapeTransformer(vertexShape);
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Gnode>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Gedge>());
    Container content = getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);

    Relaxer relaxer = vv.getModel().getRelaxer();
    relaxer.pause();
    if (map.get(synset) == null)
        map.put(synset, new Gnode(synset));
    graph.addVertex(map.get(synset));
    System.out.println(map.get(synset).synset.toString());
    map.get(synset).extended = true;
    layout.setLocation(map.get(synset), HEIGHT / 2, WIDTH / 2);
    SynsetPointer[] sp = synset.getPointers();
    for (int i = 0; i < sp.length; ++i) {
        Synset synset_ = DataManager.getSingleton().getSynset(sp[i].getSynsetOffset(), sp[i].getPartOfSpeech());
        if (map.get(synset_) == null)
            map.put(synset_, new Gnode(synset_));
        graph.addEdge(new Gedge(sp[i].getPointerSymbol().getDescription()), map.get(synset), map.get(synset_));
        layout.setLocation(map.get(synset_), HEIGHT / 2 + EDGE_LENGTH * Math.cos(Math.PI * 2 / sp.length * i),
                WIDTH / 2 + Math.sin(Math.PI * 2 / sp.length * i));
    }
    layout.initialize();
    relaxer.resume();
    getContentPane().add(vv);
}

From source file:de.romankreisel.faktotum.beans.BundesbruderBean.java

public void rotateProfilePictureClockwise(BundesbruderEntity bundesbruder, double angle) throws IOException {
    BufferedImage image = this.getImageFromByteArray(bundesbruder.getPictureOriginal());
    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);
    GraphicsConfiguration gc = image.createGraphics().getDeviceConfiguration();
    BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
    Graphics2D g = result.createGraphics();
    g.translate((neww - w) / 2, (newh - h) / 2);
    g.rotate(angle, w / 2, h / 2);//from  w w  w.  ja  va2 s  . com
    g.drawRenderedImage(image, null);
    g.dispose();
    this.setProfilePicture(bundesbruder, this.storeImageToByteArray(image));
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void sinNinety() {
    try {/*from   ww w . j  a v  a2  s .  c  o m*/
        Expression expression = getExpressionWithFunctionContext("sin(90)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.sin(90), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.opengamma.analytics.math.ComplexMathUtils.java

public static ComplexNumber pow(final ComplexNumber z1, final ComplexNumber z2) {
    ArgumentChecker.notNull(z1, "z1");
    ArgumentChecker.notNull(z2, "z2");
    final double mod = mod(z1);
    final double arg = arg(z1);
    final double mult = Math.pow(mod, z2.getReal()) * Math.exp(-z2.getImaginary() * arg);
    final double theta = z2.getReal() * arg + z2.getImaginary() * Math.log(mod);
    return new ComplexNumber(mult * Math.cos(theta), mult * Math.sin(theta));
}

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static Number funcTan(MutableNumber out, Number x) {
    double d = Math.pow(Math.cos(x.r()), 2) + Math.pow(Math.sinh(x.i()), 2);
    return out.set((Math.sin(x.r()) * Math.cos(x.r())) / d, (Math.sinh(x.i()) * Math.cosh(x.i())) / d);
}

From source file:ExtendedGeneralPath.java

/**
 * This constructs an unrotated Arc2D from the SVG specification of an
 * Elliptical arc.  To get the final arc you need to apply a rotation
 * transform such as://from www .j av a  2 s.  co  m
 *
 * AffineTransform.getRotateInstance
 *     (angle, arc.getX()+arc.getWidth()/2, arc.getY()+arc.getHeight()/2);
 */
public static Arc2D computeArc(double x0, double y0, double rx, double ry, double angle, boolean largeArcFlag,
        boolean sweepFlag, double x, double y) {
    //
    // Elliptical arc implementation based on the SVG specification notes
    //

    // Compute the half distance between the current and the final point
    double dx2 = (x0 - x) / 2.0;
    double dy2 = (y0 - y) / 2.0;
    // Convert angle from degrees to radians
    angle = Math.toRadians(angle % 360.0);
    double cosAngle = Math.cos(angle);
    double sinAngle = Math.sin(angle);

    //
    // Step 1 : Compute (x1, y1)
    //
    double x1 = (cosAngle * dx2 + sinAngle * dy2);
    double y1 = (-sinAngle * dx2 + cosAngle * dy2);
    // Ensure radii are large enough
    rx = Math.abs(rx);
    ry = Math.abs(ry);
    double Prx = rx * rx;
    double Pry = ry * ry;
    double Px1 = x1 * x1;
    double Py1 = y1 * y1;
    // check that radii are large enough
    double radiiCheck = Px1 / Prx + Py1 / Pry;
    if (radiiCheck > 1) {
        rx = Math.sqrt(radiiCheck) * rx;
        ry = Math.sqrt(radiiCheck) * ry;
        Prx = rx * rx;
        Pry = ry * ry;
    }

    //
    // Step 2 : Compute (cx1, cy1)
    //
    double sign = (largeArcFlag == sweepFlag) ? -1 : 1;
    double sq = ((Prx * Pry) - (Prx * Py1) - (Pry * Px1)) / ((Prx * Py1) + (Pry * Px1));
    sq = (sq < 0) ? 0 : sq;
    double coef = (sign * Math.sqrt(sq));
    double cx1 = coef * ((rx * y1) / ry);
    double cy1 = coef * -((ry * x1) / rx);

    //
    // Step 3 : Compute (cx, cy) from (cx1, cy1)
    //
    double sx2 = (x0 + x) / 2.0;
    double sy2 = (y0 + y) / 2.0;
    double cx = sx2 + (cosAngle * cx1 - sinAngle * cy1);
    double cy = sy2 + (sinAngle * cx1 + cosAngle * cy1);

    //
    // Step 4 : Compute the angleStart (angle1) and the angleExtent (dangle)
    //
    double ux = (x1 - cx1) / rx;
    double uy = (y1 - cy1) / ry;
    double vx = (-x1 - cx1) / rx;
    double vy = (-y1 - cy1) / ry;
    double p, n;
    // Compute the angle start
    n = Math.sqrt((ux * ux) + (uy * uy));
    p = ux; // (1 * ux) + (0 * uy)
    sign = (uy < 0) ? -1.0 : 1.0;
    double angleStart = Math.toDegrees(sign * Math.acos(p / n));

    // Compute the angle extent
    n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
    p = ux * vx + uy * vy;
    sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
    double angleExtent = Math.toDegrees(sign * Math.acos(p / n));
    if (!sweepFlag && angleExtent > 0) {
        angleExtent -= 360f;
    } else if (sweepFlag && angleExtent < 0) {
        angleExtent += 360f;
    }
    angleExtent %= 360f;
    angleStart %= 360f;

    //
    // We can now build the resulting Arc2D in double precision
    //
    Arc2D.Double arc = new Arc2D.Double();
    arc.x = cx - rx;
    arc.y = cy - ry;
    arc.width = rx * 2.0;
    arc.height = ry * 2.0;
    arc.start = -angleStart;
    arc.extent = -angleExtent;

    return arc;
}

From source file:com.inc.playground.playground.utils.NetworkUtilities.java

public static Double calculateDistance(double lon1, double lat1, double lon2, double lat2) {
    //calculate air distance
    double R = 6371; // Radius of the earth in km
    double dLat = deg2rad(lat2 - lat1); // deg2rad below
    double dLon = deg2rad(lon2 - lon1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = R * c; // Distance in km
    return Math.round(d * 10d) / 10d; //round 1 point after digit
}

From source file:com.alvermont.terraj.planet.project.SinusoidProjection.java

/**
 * Carry out the projection//from   w  w  w  . j  ava2  s . c o  m
 */
public void project() {
    setcolours();

    final int width = getParameters().getProjectionParameters().getWidth();
    final int height = getParameters().getProjectionParameters().getHeight();

    final double lat = getParameters().getProjectionParameters().getLatitudeRadians();
    final double lon = getParameters().getProjectionParameters().getLongitudeRadians();

    final double scale = getParameters().getProjectionParameters().getScale();

    final double hgrid = getParameters().getProjectionParameters().getHgrid();
    final double vgrid = getParameters().getProjectionParameters().getVgrid();

    final boolean doShade = getParameters().getProjectionParameters().isDoShade();

    cacheParameters();

    colours = new short[width][height];
    shades = new short[width][height];

    double y;
    double theta1;
    double theta2;
    double cos2;
    double l1;
    double i1;
    double scale1;
    int k;
    int i;
    int j;
    int l;
    int c;

    k = (int) ((lat * width * scale) / Math.PI);

    progress.progressStart(height, "Generating Terrain");

    for (j = 0; j < height; ++j) {
        progress.progressStep(j);

        y = ((2.0 * (j - k)) - height) / width / scale * Math.PI;

        if (Math.abs(y) >= (0.5 * Math.PI)) {
            for (i = 0; i < width; ++i) {
                colours[i][j] = backgroundColour;

                if (doShade) {
                    shades[i][j] = 255;
                }
            }
        } else {
            cos2 = Math.cos(y);

            if (cos2 > 0.0) {
                scale1 = (scale * width) / height / cos2 / Math.PI;

                depth = (3 * ((int) (log2(scale1 * height)))) + 3;

                for (i = 0; i < width; ++i) {
                    l = (i * 12) / width;
                    l1 = (l * width) / 12.0;
                    i1 = i - l1;

                    theta2 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * l1) - width)) / width / scale);
                    theta1 = ((Math.PI * ((2.0 * i1) - (width / 12))) / width / scale) / cos2;

                    if (Math.abs(theta1) > (Math.PI / 12.0)) {
                        colours[i][j] = backgroundColour;

                        if (doShade) {
                            shades[i][j] = 255;
                        }
                    } else {
                        colours[i][j] = (short) planet0(Math.cos(theta1 + theta2) * cos2, Math.sin(y),
                                -Math.sin(theta1 + theta2) * cos2);

                        if (doShade) {
                            shades[i][j] = shade;
                        }
                    }
                }
            }
        }
    }

    progress.progressComplete("Terrain Generated");

    if (hgrid != 0.0) {
        /* draw horizontal gridlines */
        for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid)
            ;

        for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) {
            y = Math.toRadians(theta1);

            cos2 = Math.cos(y);

            j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k;

            if ((j >= 0) && (j < height)) {
                for (i = 0; i < width; ++i) {
                    l = (i * 12) / width;
                    l1 = (l * width) / 12.0;
                    i1 = i - l1;

                    theta2 = ((Math.PI * ((2.0 * i1) - (width / 12))) / width / scale) / cos2;

                    if (Math.abs(theta2) <= (Math.PI / 12.0)) {
                        colours[i][j] = BLACK;
                    }
                }
            }
        }
    }

    if (vgrid != 0.0) {
        /* draw vertical gridlines */
        for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid)
            ;

        for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) {
            i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI)));

            if ((i >= 0) && (i < width)) {
                for (j = Math.max(0,
                        (height / 2) - (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); j < Math.min(
                                height,
                                (height / 2) + (int) ((0.25 * Math.PI * width * scale) / Math.PI) + k); ++j) {
                    y = ((2.0 * (j - k)) - height) / width / scale * Math.PI;
                    cos2 = Math.cos(y);

                    l = (i * 12) / width;
                    l1 = ((l * width) / 12.0) + (width / 24.0);
                    i1 = i - l1;
                    c = (int) (l1 + (i1 * cos2));

                    if ((c >= 0) && (c < width)) {
                        colours[c][j] = BLACK;
                    }
                }
            }
        }
    }

    if (doShade) {
        smoothshades();
    }

    doOutlining();
}