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:fr.amap.lidar.amapvox.commons.LeafAngleDistribution.java

/**
 * Get the density probability from angle
 * @param angle must be in radians from in [0,2pi]
 * @return pdf function//from w  w  w.  j  a  v  a2s  .  co  m
 */
public double getDensityProbability(double angle) {

    double density = 0;

    double tmp = Math.PI / 2.0;
    if (angle == tmp) {
        angle = tmp - 0.000001;
    }

    //angle = Math.PI/2.0 - angle; ??inversion des coefficients

    switch (type) {

    //warning : in wang paper there is an inversion between planophile, and erectophile
    case PLANOPHILE:
        density = (2.0 / Math.PI) * (1 + Math.cos(2 * angle));
        break;
    case ERECTOPHILE:
        density = (2.0 / Math.PI) * (1 - Math.cos(2 * angle));
        break;
    case PLAGIOPHILE:
        density = (2.0 / Math.PI) * (1 - Math.cos(4 * angle));
        break;
    case EXTREMOPHILE:
        density = (2.0 / Math.PI) * (1 + Math.cos(4 * angle));
        break;
    case SPHERIC:
        density = Math.sin(angle);
        break;
    case UNIFORM:
        density = 2.0 / Math.PI;
        break;
    case HORIZONTAL:
        break;
    case VERTICAL:
        break;
    case ELLIPTICAL:
        break;
    case ELLIPSOIDAL:

        double res;

        if (x == 1) {
            res = Math.sin(angle);
        } else {

            double eps, lambda = 0;

            if (x < 1) {
                eps = Math.sqrt(1 - (x * x));
                lambda = x + (Math.asin(eps) / eps);
            }
            if (x > 1) {
                eps = Math.sqrt(1 - Math.pow(x, -2));
                lambda = x + Math.log((1 + eps) / (1 + eps)) / (2 * eps * x);
            }

            res = (2 * Math.pow(x, 3) * Math.sin(angle)) / (lambda
                    * Math.pow((Math.pow(Math.cos(angle), 2)) + (x * x * Math.pow(Math.sin(angle), 2)), 2));
        }

        return res;

    case TWO_PARAMETER_BETA:

        //angle = Math.PI/2.0 - angle;
        double te = 2 * angle / Math.PI;
        te = Double.max(te, 1E-09);
        te = Double.min(te, 1 - 1E-09);

        density = distribution.density(te) / (Math.PI / 2.0);

        break;
    }

    return density;
}

From source file:ActualizadorLocal.Clientes.ClienteNodos.java

public void procesarDatos(String datos) throws SQLException {
    //Preprocesamos los datos, para darle un nombre al array:

    datos = "{\"nodos\":" + datos + "}";

    JSONParser parser = new JSONParser();

    try {/* w  w w  .  ja v  a 2 s  .com*/
        JSONObject obj = (JSONObject) parser.parse(datos);
        JSONArray lista = (JSONArray) obj.get("nodos");

        for (int i = 0; i < lista.size(); i++) {
            long a0 = (long) ((JSONObject) lista.get(i)).get("idNodo");
            String a1 = (String) ((JSONObject) lista.get(i)).get("nombre");
            double a2 = (double) ((JSONObject) lista.get(i)).get("latitud");
            double a3 = (double) ((JSONObject) lista.get(i)).get("longitud");

            nodos.add(a0);

            //Tenemos que calcular el polgono para la visualizacin de los datos mediante GOOGLE FUSION TABLES:

            double lat = Math.toRadians(new Double(a2));
            double lon = Math.toRadians(new Double(a3));

            double radio = 50.0 / 6378137.0;

            String cadena_poligono = "<Polygon><outerBoundaryIs><LinearRing><coordinates>";

            for (int j = 0; j <= 360; j = j + 15) {
                double r = Math.toRadians(j);
                double lat_rad = Math
                        .asin(Math.sin(lat) * Math.cos(radio) + Math.cos(lat) * Math.sin(radio) * Math.cos(r));
                double lon_rad = Math.atan2(Math.sin(r) * Math.sin(radio) * Math.cos(lat),
                        Math.cos(radio) - Math.sin(lat) * Math.sin(lat_rad));
                double lon_rad_f = ((lon + lon_rad + Math.PI) % (2 * Math.PI)) - Math.PI;

                cadena_poligono = cadena_poligono + Math.toDegrees(lon_rad_f) + "," + Math.toDegrees(lat_rad)
                        + ",0.0 ";
            }

            cadena_poligono = cadena_poligono + "</coordinates></LinearRing></outerBoundaryIs></Polygon>";

            this.InsertarDatos("\"" + (String) Long.toString(a0) + "\",\"" + a1 + "\",\"" + Double.toString(a2)
                    + "\",\"" + Double.toString(a3) + "\",\"" + cadena_poligono + "\"");

        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }

    syncDB();

}

From source file:edu.ucsf.valelab.saim.calculations.SaimCalc.java

/**
 * Calculates the angle of incidence for light traveling through a medium
 * with known refractive index and angle of incidence into a medium with 
 * another known refractive index using Snell's law: sin(1)/sin(2) = n2/n1
 * See: https://en.wikipedia.org/wiki/Snell%27s_law
 * // w w  w .  j  a v  a  2s  . c o  m
 * @param angle1 angle with respect to the normal in radiance in medium 1
 * @param ri1 Refractive index of medium 1
 * @param ri2 Refractive index of medium 2
 * @return angle of incidence in medium 2 in radiance
 */
public static double snell2(double angle1, double ri1, double ri2) {
    double sinAngle2 = ri1 * Math.sin(angle1) / ri2;
    return Math.asin(sinAngle2);
}

From source file:com.ebay.pulsar.collector.simulator.Simulator.java

private long trafficVolume(int baseVolume, double peakTimes, int sec) {
    if (baseVolume < 0)
        throw new IllegalArgumentException("baseVolume should be >= 0!");
    if (peakTimes <= 0)
        throw new IllegalArgumentException("peakTimes should be > 0!");
    return (long) (baseVolume + (baseVolume * (peakTimes - 1)) * Math.sin(sec * Math.PI / 60));
}

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

@Test
public void sinNull() {
    try {/*from   w ww  . ja va 2s  .co m*/
        getExpressionWithFunctionContext("sin(0)");
        Expression expression = getExpressionWithFunctionContext("sin(0)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.sin(0), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

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

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

From source file:org.jfree.eastwood.GXYPlot.java

/**
 * Draws the background for the plot./*www.  j a  v a  2 s. c o m*/
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
public void drawBackground(Graphics2D g2, Rectangle2D area) {
    Paint p = getBackgroundPaint();
    if (p instanceof GradientPaint) {
        // do the transformation directly
        GradientPaint gp = (GradientPaint) p;
        double r = (this.f1 - this.f0) * area.getWidth();
        Point2D p0 = new Point2D.Double(area.getMinX() + this.f0 * area.getWidth(), area.getMaxY());
        Point2D p1 = new Point2D.Double(p0.getX() + r * Math.cos(this.angle),
                p0.getY() - r * Math.sin(this.angle));
        p = new GradientPaint(p0, gp.getColor1(), p1, gp.getColor2());
    }
    g2.setPaint(p);
    g2.fill(area);
}

From source file:com.esri.geoevent.solutions.processor.geometry.RangeFanProcessor.java

private Geometry constructRangeFan(double x, double y, double range, String unit, double bearing,
        double traversal) throws GeometryException {
    Polygon fan = new Polygon();
    Point center = new Point();
    center.setX(x);//from   ww w  .ja  va2 s  . com
    center.setY(y);
    // SpatialReference srIn = SpatialReference.create(wkidin);
    // SpatialReference srBuffer = SpatialReference.create(wkidbuffer);
    // SpatialReference srOut = SpatialReference.create(wkidout);
    Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer);

    double centerX = centerProj.getX();
    double centerY = centerProj.getY();
    bearing = GeometryUtility.Geo2Arithmetic(bearing);
    double leftAngle = bearing - (traversal / 2);
    double rightAngle = bearing + (traversal / 2);
    int count = (int) Math.round(Math.abs(leftAngle - rightAngle));
    fan.startPath(centerProj);
    UnitConverter uc = new UnitConverter();
    range = uc.Convert(range, unit, srBuffer);
    for (int i = 0; i < count; ++i) {
        double d = Math.toRadians(leftAngle + i);
        double arcX = centerX + (range * Math.cos(d));
        double arcY = centerY + (range * Math.sin(d));
        Point arcPt = new Point(arcX, arcY);
        // arcPt = (Point) GeometryEngine.project(arcPt, srBuffer, srOut);
        fan.lineTo(arcPt);
    }
    fan.closeAllPaths();
    return fan;
}

From source file:NettyServerHandler.java

public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    HttpRequest request = this.request = (HttpRequest) e.getMessage();

    if (is100ContinueExpected(request)) {
        send100Continue(e);//from   w w w . j av a  2  s  .  co  m
    }

    buf.setLength(0);
    buf.append("Netty Test\r\n");

    Future<String> get = m_async.get("user_data_java");

    m_async.awaitAll(get);
    String raw = get.get();
    //raw = decompress(raw);
    //ObjectMapper m = new ObjectMapper();
    //JsonNode tree = m.readTree(raw);
    //JsonNode currVal = (JsonNode)tree.path("TWIDDLE");
    //ValueNode newVal = new ValueNode();
    //buf.append("Curr Val: " + currVal.longValue());
    ///Random rn = new Random();
    //ValueNode val = new ValueNode();

    //((ObjectNode)tree.set("TWIDDLE", rn.nextInt(30000));
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            double k = Math.sin(i) * Math.sin(j);
        }
    }

    //String jsonEncoded = m.writeValueAsString(tree);
    //String compressed = compress(jsonEncoded);
    Future<String> set = m_async.set("user_data_java", raw);
    m_async.awaitAll(set);
    //buf.append("jsonEncoded:" + jsonEncoded);
    //buf.append("compressed:" + compressed);
    buf.append("\r\n");

    writeResponse(e);

}

From source file:geogebra.common.kernel.geos.GeoVec2D.java

/**
 * @param r//w  w w .  ja v  a  2 s  .co m
 *            radius
 * @param phi
 *            phase
 */
public void setPolarCoords(double r, double phi) {
    x = r * Math.cos(phi);
    y = r * Math.sin(phi);
}