Example usage for java.lang Math toRadians

List of usage examples for java.lang Math toRadians

Introduction

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

Prototype

public static double toRadians(double angdeg) 

Source Link

Document

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Usage

From source file:de.mfo.jsurf.grid.RotationGrid.java

public static BufferedImage renderAnimGrid(int xAngleMin, int xAngleMax, int xSteps, int yAngleMin,
        int yAngleMax, int ySteps) {
    BufferedImage grid = new BufferedImage(ySteps * size, xSteps * size, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) grid.getGraphics();
    for (int x = 0; x < xSteps; ++x) {
        double xAngle = xAngleMin + (xAngleMax - xAngleMin) * (xSteps == 1 ? 0.5 : (x / (double) (xSteps - 1)));
        Matrix4d matRotX = new Matrix4d();
        matRotX.setIdentity();//  www. java2 s.com
        matRotX.rotX(Math.toRadians(xAngle));
        for (int y = 0; y < ySteps; ++y) {
            double yAngle = yAngleMin
                    + (yAngleMax - yAngleMin) * (ySteps == 1 ? 0.5 : (y / (double) (ySteps - 1)));
            Matrix4d matRotY = new Matrix4d();
            matRotY.setIdentity();
            matRotY.rotY(Math.toRadians(yAngle));
            additional_rotation.mul(matRotY, matRotX);
            BufferedImage bi = createBufferedImageFromRGB(draw(size, size, aam, aap));
            g2.drawImage(bi,
                    new AffineTransformOp(new AffineTransform(), AffineTransformOp.TYPE_NEAREST_NEIGHBOR),
                    (ySteps - 1 - y) * size, x * size);
        }
    }
    return grid;
}

From source file:eu.itesla_project.iidm.ddb.eurostag.model.TransformerModel.java

public StateVariable toSv2(StateVariable sv1) {
    Complex s1 = new Complex(-sv1.p, -sv1.q); // s1=p1+jq1
    Complex u1 = ComplexUtils.polar2Complex(sv1.u, Math.toRadians(sv1.theta));
    Complex v1 = u1.divide(SQUARE_3); // v1=u1/sqrt(3)
    Complex v1p = v1.multiply(ratio); // v1p=v1*rho
    Complex i1 = s1.divide(v1.multiply(3)).conjugate(); // i1=conj(s1/(3*v1))
    Complex i1p = i1.divide(ratio); // i1p=i1/rho
    Complex i2 = i1p.subtract(y.multiply(v1p)).negate(); // i2=-(i1p-y*v1p)
    Complex v2 = v1p.subtract(z.multiply(i2)); // v2=v1p-z*i2
    Complex s2 = v2.multiply(3).multiply(i2.conjugate()); // s2=3*v2*conj(i2)
    Complex u2 = v2.multiply(SQUARE_3);//  w  w w  .j  a v a  2s .com
    return new StateVariable(-s2.getReal(), -s2.getImaginary(), u2.abs(), Math.toDegrees(u2.getArgument()));
}

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

public void test() throws Exception {
    final double wl = 525.0;
    final double nSample = 1.33;

    // Phase difference
    double phaseDiff = SaimCalc.PhaseDiff(wl, Math.toRadians(0.0), nSample, 0.0);
    System.out.println("Phase difference: " + phaseDiff);
    assertEquals(0.0, phaseDiff, 0.00000000001);
    phaseDiff = SaimCalc.PhaseDiff(wl, Math.toRadians(0.0), nSample, 100.0);
    assertEquals(3.1834805556376575, phaseDiff, 0.00000000001);
    System.out.println("Phase difference: " + phaseDiff);
    phaseDiff = SaimCalc.PhaseDiff(wl, Math.toRadians(0.0), nSample, 200.0);
    System.out.println("Phase difference: " + phaseDiff);
    assertEquals(6.366961111275315, phaseDiff, 0.00000000001);

    // Snell's law calculations
    // air to water at 30 degrees
    double angle = Math.toDegrees(SaimCalc.snell2(Math.toRadians(30.0), 1.0, 1.33));
    System.out.println("Angle found was " + angle + " degrees");
    assertEquals(22.082413194472252, angle, 0.0000001);

    // angular wavenumber calculation
    // wavenumber in oil for 488nm light
    double k = SaimCalc.k(488.0, 1.55);
    System.out.println("Wavenumber in oil at 488nm: " + k);
    assertEquals(0.019956838578131884, k, 0.0000001);

    // TODO: check that these Fresnel Coefficients are actually correct!
    Complex fc1 = SaimCalc.fresnelTE(wl, Math.toRadians(0.0), wl, nSample);
    System.out.println("Fresnel Coeficient: " + fc1.toString());
    assertEquals(-0.46513448826603965, fc1.getReal(), 0.00000000001);
    assertEquals(0.2175327339364143, fc1.getImaginary(), 0.00000000001);
    fc1 = SaimCalc.fresnelTE(wl, Math.toRadians(10.0), wl, nSample);
    System.out.println("Fresnel Coeficient: " + fc1.toString());
    assertEquals(-0.410993277015784, fc1.getReal(), 0.00000000001);
    assertEquals(0.30908357106454865, fc1.getImaginary(), 0.00000000001);
}

From source file:IK.G.java

public static double radians(double in) {
    return Math.toRadians(in);
}

From source file:net.ymate.framework.commons.GeoUtils.java

/**
 * @param point    ??//  w w w. j a va  2 s  .com
 * @param distance ?()
 * @return ???
 */
public static Bounds rectangle(Point point, long distance) {
    if (point == null || distance <= 0) {
        return new Bounds();
    }
    float _delta = 111000;
    if (point.getLatitude() != 0 && point.getLongitude() != 0) {
        double lng1 = point.getLongitude()
                - distance / Math.abs(Math.cos(Math.toRadians(point.getLatitude())) * _delta);
        double lng2 = point.getLongitude()
                + distance / Math.abs(Math.cos(Math.toRadians(point.getLatitude())) * _delta);
        double lat1 = point.getLatitude() - (distance / _delta);
        double lat2 = point.getLatitude() + (distance / _delta);
        return new Bounds(new Point(lng1, lat1), new Point(lng2, lat2));
    } else {
        double lng1 = point.getLongitude() - distance / _delta;
        double lng2 = point.getLongitude() + distance / _delta;
        double lat1 = point.getLatitude() - (distance / _delta);
        double lat2 = point.getLatitude() + (distance / _delta);
        return new Bounds(new Point(lng1, lat1), new Point(lng2, lat2));
    }
}

From source file:GraphicsUtil.java

public static void drawString(Graphics g, String text, RectangularShape bounds, Align align, double angle) {
    Graphics2D g2 = (Graphics2D) g;
    Font font = g2.getFont();/* ww w. j  a  v  a 2 s .  co m*/
    if (angle != 0)
        g2.setFont(font.deriveFont(AffineTransform.getRotateInstance(Math.toRadians(angle))));

    Rectangle2D sSize = g2.getFontMetrics().getStringBounds(text, g2);
    Point2D pos = getPoint(bounds, align);
    double x = pos.getX();
    double y = pos.getY() + sSize.getHeight();

    switch (align) {
    case North:
    case South:
    case Center:
        x -= (sSize.getWidth() / 2);
        break;
    case NorthEast:
    case East:
    case SouthEast:
        x -= (sSize.getWidth());
        break;
    case SouthWest:
    case West:
    case NorthWest:
        break;
    }

    g2.drawString(text, (float) x, (float) y);
    g2.setFont(font);
}

From source file:org.apache.hadoop.hive.ql.udf.UDFRadians.java

public DoubleWritable evaluate(DoubleWritable i) {
    if (i == null) {
        return null;
    } else {/*from w  ww.j  av  a2s. co  m*/
        result.set(Math.toRadians(i.get()));
        return result;
    }
}

From source file:controller.JsonController.java

public ArrayList<JsonModel> ReadJsonCalc() throws FileNotFoundException, IOException, ParseException {

    FileInputStream fstream = new FileInputStream("gistfile1.txt");
    BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
    String strLine;//www .  j av a  2  s . c o m
    ArrayList<JsonModel> result = new ArrayList<>();
    JsonModel model;

    double L1, G1, L2, G2;

    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
        model = new JsonModel();
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(strLine);
        JSONObject jsonObject = (JSONObject) obj;

        model.setLatitude((double) Double.parseDouble((String) jsonObject.get("latitude")));
        model.setLongitude((double) Double.parseDouble((String) jsonObject.get("longitude")));
        model.setUserIid((int) Integer.parseInt((String) jsonObject.get("user_id").toString()));
        model.setName(((String) jsonObject.get("name")));

        L1 = Math.toRadians(model.getLatitudeDefault());
        G1 = Math.toRadians(model.getLongitudeDefault());
        L2 = Math.toRadians(model.getLatitude());
        G2 = Math.toRadians(model.getLongitude());

        // do the spherical trig calculation
        double angle = Math.acos(Math.sin(L1) * Math.sin(L2) + Math.cos(L1) * Math.cos(L2) * Math.cos(G1 - G2));
        // convert back to degrees
        angle = Math.toDegrees(angle);

        // each degree on a great circle of Earth is 69.1105 miles
        double distance = (69.1105 * angle) * 1.609344;

        if (distance <= 100)
            result.add(model);
    }
    Collections.sort(result);

    return result;
}

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

/**
 * Compares two methods to calculate the Saim function
 * The implementation not using Complex numbers appears to be at least
 * 10 times faster/*from   w  ww  .  j  av  a  2s .c o  m*/
 * @throws Exception 
 */
public void test() throws Exception {

    long nrRuns = 100000000;

    double wavelength = 488.0;
    double nSample = 1.36;
    double dOx = 500.0;
    double h = 16.0;

    double angle = Math.toRadians(0.0);
    SaimFunction sf = new SaimFunction(wavelength, dOx, nSample, false);
    Complex rTE = sf.getFresnelTE(0);
    double f = 4.0 * Math.PI * nSample * Math.cos(angle) / wavelength;
    double phaseDiff = f * h;

    // method 1
    long startTime = System.nanoTime();
    double c = rTE.getReal();
    double d = rTE.getImaginary();
    for (int i = 0; i < nrRuns; i++) {
        double val = 1 + 2 * c * Math.cos(phaseDiff) - 2 * d * Math.sin(phaseDiff) + c * c + d * d;
    }
    long endTime = System.nanoTime();
    long took = endTime - startTime;
    System.out.println("First method: " + nrRuns + " runs took: " + took / 1000000 + " milliseconds");

    // method 2
    startTime = System.nanoTime();
    for (int i = 0; i < nrRuns; i++) {
        Complex tmp = new Complex(Math.cos(phaseDiff), Math.sin(phaseDiff));
        Complex fieldStrength = rTE.multiply(tmp);
        fieldStrength = fieldStrength.add(1.0);
        // square of absolute 
        double val = fieldStrength.getReal() * fieldStrength.getReal()
                + fieldStrength.getImaginary() * fieldStrength.getImaginary();
    }
    endTime = System.nanoTime();
    took = endTime - startTime;
    System.out.println("Second method: " + nrRuns + " runs took: " + took / 1000000 + " milliseconds");

}

From source file:org.surmon.pattern.visualization.d3.camera.SphericalCamera.java

@Override
public void drag(Point start, Point end) {
    if (start != null && end != null) {

        int dx = start.x - end.x;
        int dy = start.y - end.y;

        if (dx != 0 || dy != 0) {

            double theta = eye.getTheta() + Math.toRadians(dx);
            double phi = eye.getPhi() + Math.toRadians(dy);

            // top lock
            if (dy < 0 && phi < 0) {
                phi = Math.toRadians(0.000000001);
            }// w ww  .  ja  v a  2 s. com

            // bottom lock
            if (phi > Math.PI) {
                phi = Math.toRadians(179.999999999);
            }

            eye = new GLSphericalCoordinates(eye.getR(), theta, phi);
        }
    }

    updateView();
}