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:io.github.malapert.jwcs.coordsystem.FK4.java

/**
 * Compute the E-terms (elliptic terms of aberration) for a given epoch.
 * //from   ww  w  .  j  a v  a  2s . co m
 * Reference:
 * ----------
 * Seidelman, P.K.,  1992.  Explanatory Supplement to the Astronomical
 * Almanac.  University Science Books, Mill Valley
 *
 * Notes:     
 * -------
 * The method is described on page 170/171 of the ES.
 * One needs to process the e-terms for the appropriate
 * epoch This routine returns the e-term vector for arbitrary epoch.
 * 
 * @param epoch A Besselian epoch
 * @return A tuple containing the e-terms vector (DeltaD,DeltaC,DeltaC.tan(e0))
 */
public final static RealMatrix getEterms(float epoch) {
    //Julian centuries since B1950
    double T = (epoch - 1950.0d) * 1.00002135903d / 100.0d;
    //Eccentricity of the Earth's orbit
    double ec = 0.01673011d - (0.00004193d + 0.000000126d * T) * T;
    //Mean obliquity of the ecliptic. Method is different compared to 
    //functions for the obliquity defined earlier. This function depends
    //on time wrt. epoch 1950 not epoch 2000.
    double ob = (84404.836d - (46.8495d + (0.00319d + 0.00181d * T) * T) * T);
    ob = Math.toRadians(ob / 3600.0d);
    //Mean longitude of perihelion of the solar orbit
    double p = (1015489.951d + (6190.67d + (1.65d + 0.012d * T) * T) * T);
    p = Math.toRadians(p / 3600.0d);
    //Calculate the E-terms vector
    double ek = ec * Math.toRadians(20.49522d / 3600.0d); // 20.49552 is constant of aberration at J2000
    double cp = Math.cos(p);
    //       -DeltaD        DeltaC            DeltaC.tan(e0)
    double[][] array = { { ek * Math.sin(p), -1 * ek * cp * Math.cos(ob), -1 * ek * cp * Math.sin(ob) } };
    return MatrixUtils.createRealMatrix(array);
}

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

@Test
public void sinInt() {
    try {/*from w w  w.j  av  a 2  s . com*/
        Expression expression = getExpressionWithFunctionContext("sin(16)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.sin(16), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:org.jfree.chart.demo.XYBlockChartDemo1.java

private static XYZDataset createDataset() {
    return new XYZDataset() {

        public int getSeriesCount() {
            return 1;
        }//from   w w w  .  java  2  s  .  c o  m

        public int getItemCount(int i) {
            return 10000;
        }

        public Number getX(int i, int j) {
            return new Double(getXValue(i, j));
        }

        public double getXValue(int i, int j) {
            return (double) (j / 100 - 50);
        }

        public Number getY(int i, int j) {
            return new Double(getYValue(i, j));
        }

        public double getYValue(int i, int j) {
            return (double) (j - (j / 100) * 100 - 50);
        }

        public Number getZ(int i, int j) {
            return new Double(getZValue(i, j));
        }

        public double getZValue(int i, int j) {
            double d = getXValue(i, j);
            double d1 = getYValue(i, j);
            return Math.sin(Math.sqrt(d * d + d1 * d1) / 5D);
        }

        public void addChangeListener(DatasetChangeListener datasetchangelistener) {
        }

        public void removeChangeListener(DatasetChangeListener datasetchangelistener) {
        }

        public DatasetGroup getGroup() {
            return null;
        }

        public void setGroup(DatasetGroup datasetgroup) {
        }

        @SuppressWarnings("rawtypes")
        public Comparable getSeriesKey(int i) {
            return "sin(sqrt(x + y))";
        }

        @SuppressWarnings("rawtypes")
        public int indexOf(Comparable comparable) {
            return 0;
        }

        public DomainOrder getDomainOrder() {
            return DomainOrder.ASCENDING;
        }

    };
}

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

public static ComplexNumber sin(final ComplexNumber z) {
    Validate.notNull(z, "z");
    final double x = z.getReal();
    final double y = z.getImaginary();
    return new ComplexNumber(Math.sin(x) * Math.cosh(y), Math.cos(x) * Math.sinh(y));
}

From source file:Clock.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Color colorRetainer = g.getColor();

    g.setColor(getBackground());/*from  ww w . j a va  2  s  . c om*/
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    calendar.setTime(new Date()); // get current time
    int hrs = calendar.get(Calendar.HOUR_OF_DAY);
    int min = calendar.get(Calendar.MINUTE);

    g.setColor(getForeground());
    if (isDigital) {
        String time = "" + hrs + ":" + min;
        g.setFont(getFont());
        FontMetrics fm = g.getFontMetrics();
        int y = (getHeight() + fm.getAscent()) / 2;
        int x = (getWidth() - fm.stringWidth(time)) / 2;
        g.drawString(time, x, y);
    } else {
        int x = getWidth() / 2;
        int y = getHeight() / 2;
        int rh = getHeight() / 4;
        int rm = getHeight() / 3;

        double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI;
        double am = min / 30.0 * Math.PI;

        g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah)));
        g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am)));
    }

    g.setColor(colorRetainer);
}

From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.BeginInlineImage.java

/**
 * process : BI : begin inline image.//from   www. java  2 s  .  co m
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws java.io.IOException If there is an error displaying the inline image.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context;

    PDPage page = drawer.getPage();
    //begin inline image object
    ImageParameters params = operator.getImageParameters();
    PDInlinedImage image = new PDInlinedImage();
    image.setImageParameters(params);
    image.setImageData(operator.getImageData());
    BufferedImage awtImage = image.createImage(context.getColorSpaces());

    if (awtImage == null) {
        log.warn("BeginInlineImage.process(): createImage returned NULL");
        return;
    }
    int imageWidth = awtImage.getWidth();
    int imageHeight = awtImage.getHeight();
    double pageHeight = drawer.getPageSize().getHeight();

    Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
    int pageRotation = page.findRotation();

    AffineTransform ctmAT = ctm.createAffineTransform();
    ctmAT.scale(1f / imageWidth, 1f / imageHeight);
    Matrix rotationMatrix = new Matrix();
    rotationMatrix.setFromAffineTransform(ctmAT);
    // calculate the inverse rotation angle
    // scaleX = m00 = cos
    // shearX = m01 = -sin
    // tan = sin/cos
    double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX());
    Matrix translationMatrix = null;
    if (pageRotation == 0 || pageRotation == 180) {
        translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()),
                (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale()));
    } else if (pageRotation == 90 || pageRotation == 270) {
        translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()),
                (float) (pageHeight - 2 * ctm.getYPosition()));
    }
    rotationMatrix = rotationMatrix.multiply(translationMatrix);
    rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1));
    rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0));
    AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1),
            rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0),
            rotationMatrix.getValue(2, 1));
    drawer.drawImage(awtImage, at);
}

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.NCauer.java

public NCauer(double Rp, double Rs, int n) {

    // Cutoff frequency = 1:
    double wp = 1;

    // Stop band edge ws:
    double ws = __ellip_ws(n, Rp, Rs);

    double k = wp / ws;
    double k1 = Math.sqrt(1.0 - Math.pow(k, 2));
    double q0 = (1.0 / 2.0) * ((1.0 - Math.sqrt(k1)) / (1 + Math.sqrt(k1)));
    double q = q0 + 2.0 * Math.pow(q0, 5) + 15.0 * Math.pow(q0, 9) + 150.0 * Math.pow(q0, 13); //%(....)
    double D = (Math.pow(10, 0.1 * Rs) - 1.0) / (Math.pow(10, (0.1 * Rp)) - 1.0);

    //Filter order maybe this, but not used now:
    //n=ceil(log10(16*D)/log10(1/q))

    double l = (1.0 / (2.0 * n)) * Math.log((Math.pow(10, 0.05 * Rp) + 1.0) / (Math.pow(10, 0.05 * Rp) - 1.0));
    double sig01 = 0;
    double sig02 = 0;
    for (int m = 0; m <= 30; m++) {
        sig01 = sig01 + Math.pow((-1), m) * Math.pow(q, (m * (m + 1))) * Math.sinh((2 * m + 1) * l);
    }// w  w  w.  j a  va  2  s .  c  o m
    for (int m = 1; m <= 30; m++) {
        sig02 = sig02 + Math.pow(-1.0, m) * Math.pow(q, (Math.pow(m, 2))) * Math.cosh(2 * m * l);
    }
    double sig0 = Math.abs((2.0 * Math.pow(q, (1.0 / 4.0)) * sig01) / (1.0 + 2.0 * sig02));

    double w = Math.sqrt((1.0 + k * Math.pow(sig0, 2)) * (1.0 + Math.pow(sig0, 2) / k));

    int r;
    if (n % 2 != 0) {
        r = (n - 1) / 2;
    } else {
        r = n / 2;
    }

    double[] wi = new double[r];
    for (int ii = 1; ii <= r; ii++) {
        double mu;
        if (n % 2 != 0) {
            mu = ii;
        } else {
            mu = (double) ii - 0.5;
        }
        double soma1 = 0;
        for (int m = 0; m <= 30; m++) {
            soma1 = soma1 + 2.0 * Math.pow(q, (1.0 / 4.0)) * (Math.pow(-1.0, m) * Math.pow(q, (m * (m + 1)))
                    * Math.sin(((2.0 * m + 1.0) * Math.PI * mu) / n));
        }
        double soma2 = 0;
        for (int m = 1; m <= 30; m++) {
            soma2 = soma2 + 2.0 * (Math.pow(-1.0, m) * Math.pow(q, (Math.pow(m, 2)))
                    * Math.cos((2.0 * m * Math.PI * mu) / n));
        }
        wi[ii - 1] = (soma1 / (1.0 + soma2));
    }

    double[] Vi = new double[wi.length];
    for (int i = 0; i < wi.length; i++) {
        Vi[i] = Math.sqrt((1.0 - (k * (Math.pow(wi[i], 2)))) * (1.0 - (Math.pow(wi[i], 2)) / k));
    }
    double[] A0i = new double[wi.length];
    for (int i = 0; i < wi.length; i++) {
        A0i[i] = 1.0 / (Math.pow(wi[i], 2));
    }
    double[] sqrA0i = new double[wi.length];
    for (int i = 0; i < wi.length; i++) {
        sqrA0i[i] = 1.0 / wi[i];
    }

    double[] B0i = new double[wi.length];
    for (int i = 0; i < wi.length; i++) {
        B0i[i] = (Math.pow((sig0 * Vi[i]), 2) + Math.pow((w * wi[i]), 2))
                / Math.pow((1.0 + Math.pow(sig0, 2) * Math.pow(wi[i], 2)), 2);
    }

    double C01;
    if (wi.length == 0) {
        C01 = 1.0;
    } else {
        C01 = B0i[0] / A0i[0];
        for (int i = 1; i < wi.length; i++) {
            C01 *= B0i[i] / A0i[i];
        }
    }

    //Gain T0:
    if (n % 2 != 0) {
        T0 = sig0 * C01 * Math.sqrt(ws);
    } else {
        T0 = Math.pow(10, (-0.05 * Rp)) * C01;
    }

    //zeros:
    zer = new Complex[sqrA0i.length * 2];
    for (int i = 0; i < sqrA0i.length; i++) {
        zer[i] = Complex.valueOf(0.0, sqrA0i[i]);
        zer[i + sqrA0i.length] = Complex.valueOf(0.0, -sqrA0i[i]);
    }

    //poles:
    pol = new Complex[Vi.length * 2];
    for (int i = 0; i < Vi.length; i++) {
        pol[i] = new Complex(-2.0 * sig0 * Vi[i], 2.0 * wi[i] * w)
                .divide(2.0 * (1 + Math.pow(sig0, 2) * Math.pow(wi[i], 2)));
        pol[i + Vi.length] = new Complex(-2.0 * sig0 * Vi[i], -2.0 * wi[i] * w)
                .divide(2.0 * (1 + Math.pow(sig0, 2) * Math.pow(wi[i], 2)));
    }

    //If n odd, there is a real pole  -sig0:
    if (n % 2 != 0) {
        pol = Arrays.copyOf(pol, pol.length + 1);
        pol[pol.length - 1] = new Complex(-sig0);
    }

    for (int i = 0; i < pol.length; i++) {
        pol[i] = pol[i].multiply(Math.sqrt(ws));
    }
    for (int i = 0; i < zer.length; i++) {
        zer[i] = zer[i].multiply(Math.sqrt(ws));
    }

}

From source file:com.day.cq.wcm.foundation.TableTest.java

@org.junit.Test
public void testDoubleDataTable() throws IOException {
    Table table = new Table();
    // fill table
    for (int r = 0; r < 25; r++) {
        for (int c = 0; c < 25; c++) {
            double v = Math.sin(r * 2.0 * Math.PI / 25.0) + Math.cos(c * 2.0 * Math.PI / 25.0);
            table.getCell(r, c, true).setText(String.valueOf(v));
        }/* www  .  j  a va  2  s  .co m*/
    }
    // check entire table
    double[][] data = table.getDoubleData();
    for (int y = 0; y < data.length; y++) {
        for (int x = 0; x < data[y].length; x++) {
            double d = data[y][x];
            double v = Math.sin(y * 2.0 * Math.PI / 25.0) + Math.cos(x * 2.0 * Math.PI / 25.0);
            assertEquals(d, v, 0.0);
        }
    }
}

From source file:beans.BL.java

public void test(TPVObject tpv) {
    /**/*from   w w  w.  j a  va2  s. co m*/
     * Neue Idee alles zu speichern
     */
    /*Umwandlung von Double in LDT Problem das es zu ungenau ist
     Double test = (tpv.getTimestamp());
     long int_timestamp = test.longValue();
     LocalDateTime ldt = LocalDateTime.ofEpochSecond(int_timestamp, 0, ZoneOffset.UTC);
     */

    System.out.println(
            tpv.getTimestamp() + " Longitude: " + tpv.getLatitude() + " Latitude: " + tpv.getLongitude());
    //TODO:
    /**
     * Algorithmus um die gefahrenen Km zu messen
     */

    if (tpv.getSpeed() > 2.77) {
        if (latOld == -1 && lonOld == -1) {
            latNew = tpv.getLatitude();
            lonNew = tpv.getLongitude();
        }
        latOld = latNew;
        lonOld = lonNew;
        latNew = tpv.getLatitude();
        lonNew = tpv.getLongitude();

        double R = 6371000; // metres

        double dLat = Math.toRadians(latNew - latOld);
        double dLon = Math.toRadians(lonNew - lonOld);
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(latOld))
                * Math.cos(Math.toRadians(latNew)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        d = d + (R * c);
        System.out.println("Distance:" + d + "Speed:" + tpv.getSpeed());
    }
    Point point = new Point(LocalDateTime.now(), tpv.getLatitude(), tpv.getLongitude(), d, tpv.getSpeed(),
            track);

    try {
        points.put(point);
    } catch (InterruptedException ex) {
        Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex);
    }

    try {
        System.out.println("points size:" + points.size());
        System.out.println("traks size:" + tracks.size());
        for (Track track1 : tracks) {
            System.out.println("track: " + track1.getId());
        }
        data_manager.writeFile(points);
    } catch (ParseException ex) {
        Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:net.ostis.scpdev.scg.geometry.GraphLayout.java

private void calculateForces() {
    int n = nodes.size();

    RealVector[] forces = new RealVector[n];
    for (int i = 0; i < n; ++i)
        forces[i] = new ArrayRealVector(new double[] { 0, 0 });

    Map<IFigure, Integer> obj_f = new HashMap<IFigure, Integer>();
    Point[] o_pos = new Point[n];

    ///* ww  w  . j a v a2s.c  o  m*/
    // Calculation repulsion forces.
    //
    for (int idx = 0; idx < n; ++idx) {
        obj_f.put(nodes.get(idx), idx);

        Point p1 = nodes.get(idx).getBounds().getLocation();

        RealVector p1v = new ArrayRealVector(2);
        p1v.setEntry(0, p1.x);
        p1v.setEntry(0, p1.y);

        double l = nullVector.getDistance(p1v);

        RealVector f = p1v.mapMultiply(gravity * (l - 3.0));

        forces[idx].subtract(f);

        for (int jdx = idx + 1; jdx < n; ++jdx) {
            Point p2 = nodes.get(idx).getBounds().getLocation();

            RealVector p2v = new ArrayRealVector(2);
            p2v.setEntry(0, p2.x);
            p2v.setEntry(0, p2.y);

            l = p1v.getDistance(p2v);

            if (l > max_rep_length)
                continue;

            if (l > 0.5) {
                f = p1v.subtract(p2v).mapMultiply(repulsion / l / l);
            } else {
                f = new ArrayRealVector(new double[] { Math.cos(0.17 * idx) * length * 7,
                        Math.sin(0.17 * (idx + 1)) * length * 7 });
            }

            forces[idx].add(f);
            forces[jdx].subtract(f);
        }
    }

    for (int idx = 0; idx < n; ++idx) {
        RealVector f = forces[idx];
        f.mapMultiply(stepSize);
        nodes.get(idx).setLocation(new Point(f.getEntry(0), f.getEntry(1)));
    }
}