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:org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord.java

public double distance(ZipcodeRecord other) {
    if (other.getZipcode().equals(zipcode))
        return 0.0;

    Pair<Double, Double> otherCoords = other.getCoordinates();

    double dist = Math.sin(Math.toRadians(coordinates.getLeft()))
            * Math.sin(Math.toRadians(otherCoords.getLeft()))
            + Math.cos(Math.toRadians(coordinates.getLeft())) * Math.cos(Math.toRadians(otherCoords.getLeft()))
                    * Math.cos(Math.toRadians(coordinates.getRight() - otherCoords.getRight()));
    dist = Math.toDegrees(Math.acos(dist)) * 69.09;

    return dist;//from   w w  w  . j a  va2 s. c o  m
}

From source file:org.apache.bigtop.datagenerators.locations.Location.java

public double distance(Pair<Double, Double> otherCoords) {
    if (Math.abs(coordinates.getLeft() - otherCoords.getLeft()) < 1e-5
            || Math.abs(coordinates.getRight() - otherCoords.getRight()) < 1e-5)
        return 0.0;

    double dist = Math.sin(Math.toRadians(coordinates.getLeft()))
            * Math.sin(Math.toRadians(otherCoords.getLeft()))
            + Math.cos(Math.toRadians(coordinates.getLeft())) * Math.cos(Math.toRadians(otherCoords.getLeft()))
                    * Math.cos(Math.toRadians(coordinates.getRight() - otherCoords.getRight()));
    dist = Math.toDegrees(Math.acos(dist)) * 69.09;

    return dist;//from w  ww  . j  a v a2 s.  c o  m
}

From source file:org.honeybee.coderally.Modelt.java

@Override
public void onTimeStep() {
    if (!gogogogo)
        return;// www.j  av  a  2s. co  m

    Point checkpoint = schewy.getMidPoint(getCar().getCheckpoint());

    double heading = getCar().calculateHeading(checkpoint);
    double rotation;
    if (heading < 1) {
        rotation = -90;
    } else if (heading > 1) {
        rotation = 90;
    } else {
        rotation = 0;
    }

    Point position = getCar().getPosition();
    double radians = getCar().getRotation().getRadians() - Math.PI / 2 + Math.toRadians(rotation);
    Point target = new Point(position.getX() + Math.cos(radians) * 500,
            position.getY() + Math.sin(radians) * 500);
    getCar().setTarget(target);

    slowForTightCorner(getCar());

}

From source file:storybook.ui.chart.jfreechart.ChartUtil.java

public static ItemLabelPosition getNiceItemLabelPosition() {
    ItemLabelAnchor localItemLabelAnchor = ItemLabelAnchor.OUTSIDE6;
    TextAnchor localTextAnchor1 = TextAnchor.BOTTOM_LEFT;
    TextAnchor localTextAnchor2 = TextAnchor.TOP_LEFT;
    double d = Math.toRadians(270.0D);
    return new ItemLabelPosition(localItemLabelAnchor, localTextAnchor1, localTextAnchor2, d);
}

From source file:org.orekit.propagation.events.BackAndForthDetectorTest.java

@Test
public void testBackAndForth() throws OrekitException {

    final TimeScale utc = TimeScalesFactory.getUTC();

    final AbsoluteDate date0 = new AbsoluteDate(2006, 12, 27, 12, 0, 0.0, utc);
    final AbsoluteDate date1 = new AbsoluteDate(2006, 12, 27, 22, 50, 0.0, utc);
    final AbsoluteDate date2 = new AbsoluteDate(2006, 12, 27, 22, 58, 0.0, utc);

    // Orbit//from   www  . j a  v a 2  s . co  m
    final double a = 7274000.;
    final double e = 0.00127;
    final double i = Math.toRadians(90.);
    final double w = Math.toRadians(0.);
    final double raan = Math.toRadians(12.5);
    final double lM = Math.toRadians(60.);
    Orbit iniOrb = new KeplerianOrbit(a, e, i, w, raan, lM, PositionAngle.MEAN, FramesFactory.getEME2000(),
            date0, Constants.WGS84_EARTH_MU);

    // Propagator
    KeplerianPropagator propagator = new KeplerianPropagator(iniOrb);

    // Station
    final GeodeticPoint stationPosition = new GeodeticPoint(Math.toRadians(0.), Math.toRadians(100.), 110.);
    final BodyShape earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
            Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    final TopocentricFrame stationFrame = new TopocentricFrame(earth, stationPosition, "");

    // Detector
    final Visibility visi = new Visibility();
    propagator.addEventDetector(new ElevationDetector(stationFrame)
            .withConstantElevation(FastMath.toRadians(10.)).withHandler(visi));

    // Forward propagation (AOS + LOS)
    propagator.propagate(date1);
    propagator.propagate(date2);
    // Backward propagation (AOS + LOS)
    propagator.propagate(date1);
    propagator.propagate(date0);

    Assert.assertEquals(4, visi.getVisiNb());

}

From source file:RotationAboutCenter.java

protected void paintComponent(Graphics g) {
    Graphics2D g2d;/*from   www .j  ava  2s .c  o  m*/
    g2d = (Graphics2D) g.create();

    // Erase background to white
    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, getWidth(), getHeight());

    // base rectangle
    g2d.setColor(Color.GRAY.brighter());
    g2d.fillRect(50, 50, 50, 50);

    // rotated 45 degrees around origin
    g2d.rotate(Math.toRadians(45));
    g2d.setColor(Color.GRAY.darker());
    g2d.fillRect(50, 50, 50, 50);

    // rotated 45 degrees about center of rect
    g2d = (Graphics2D) g.create();
    g2d.rotate(Math.toRadians(45), 75, 75);
    g2d.setColor(Color.BLACK);
    g2d.fillRect(50, 50, 50, 50);

    // done with g2d, dispose it
    g2d.dispose();
}

From source file:org.apache.bigtop.bigpetstore.datagenerator.generators.locations.Location.java

public double distance(Pair<Double, Double> otherCoords) {
    double eps = 1e-3;
    if (Math.abs(coordinates.getLeft() - otherCoords.getLeft()) < eps
            && Math.abs(coordinates.getRight() - otherCoords.getRight()) < eps)
        return 0.0;

    double dist = Math.sin(Math.toRadians(coordinates.getLeft()))
            * Math.sin(Math.toRadians(otherCoords.getLeft()))
            + Math.cos(Math.toRadians(coordinates.getLeft())) * Math.cos(Math.toRadians(otherCoords.getLeft()))
                    * Math.cos(Math.toRadians(coordinates.getRight() - otherCoords.getRight()));
    dist = Math.toDegrees(Math.acos(dist)) * 69.09;

    return dist;//from  w ww . ja v  a  2  s.  c o  m
}

From source file:net.sf.mcf2pdf.mcfelements.util.ImageUtil.java

public static BufferedImage readImage(File imageFile) throws IOException {
    int rotation = getImageRotation(imageFile);
    BufferedImage img = ImageIO.read(imageFile);

    if (rotation == 0) {
        return img;
    }/*from  w  ww  .ja v a 2s  .  c o  m*/

    boolean swapXY = rotation != 180;

    BufferedImage rotated = new BufferedImage(swapXY ? img.getHeight() : img.getWidth(),
            swapXY ? img.getWidth() : img.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = rotated.createGraphics();
    g2d.translate((rotated.getWidth() - img.getWidth()) / 2, (rotated.getHeight() - img.getHeight()) / 2);
    g2d.rotate(Math.toRadians(rotation), img.getWidth() / 2, img.getHeight() / 2);

    g2d.drawImage(img, 0, 0, null);
    g2d.dispose();

    return rotated;
}

From source file:magma.agent.agentmodel.impl.GyroRate.java

public void setGyro(Vector3D gyro) {
    this.gyro = gyro;

    double x, y, z;

    x = Math.toRadians(gyro.getX() * 0.02);
    y = Math.toRadians(gyro.getY() * 0.02);
    z = Math.toRadians(gyro.getZ() * 0.02);

    double[] rotationValues = new double[9];

    rotationValues[0] = cos(y) * cos(z) + sin(x) * sin(y) * sin(z);
    rotationValues[1] = sin(z) * cos(x);
    rotationValues[2] = -sin(y) * cos(z) + sin(x) * cos(y) * sin(z);
    rotationValues[3] = -cos(y) * sin(z) + sin(x) * sin(y) * cos(z);
    rotationValues[4] = cos(x) * cos(z);
    rotationValues[5] = sin(z) * sin(z) + sin(x) * cos(y) * cos(z);
    rotationValues[6] = cos(x) * sin(y);
    rotationValues[7] = -sin(x);//w  ww .j  a  v a  2s .c o  m
    rotationValues[8] = cos(x) * cos(y);

    Matrix3d M = new Matrix3d(rotationValues);

    M.mul(identity);

    // Error correction
    // N = M / sqrt(MT x M)
    // N - closest rotation result without errors
    // M - with errors
    // MT - transpose of M
    // sqrt of matrix - done by Cholesky Algorithm in MatrixUtil.java

    Matrix3d MT = new Matrix3d(M.m00, M.m10, M.m20, M.m01, M.m11, M.m21, M.m02, M.m12, M.m22);

    MT.mul(M);

    // call cholesky for sqrt(matrix)
    Matrix3d sqrt = MatrixUtil.cholesky(MT);

    sqrt.invert();
    M.mul(sqrt);

    // setting identity as result of error correction
    identity = M;

    logger.log(Level.FINER, "gyro update: ({0}, {1}, {2})",
            new Object[] { identity.m02, identity.m12, identity.m22 });
}

From source file:frk.gpssimulator.support.NavUtils.java

/**
 * Returns coordinates of position which is given distance and bearing from given point.
 * @param pt1//from   w w w  .ja  v  a  2  s .com
 * @param dist
 * @param brg
 * @return
 */
public static Point getPosition(Point pt1, double d, double brg) {
    if (Double.doubleToRawLongBits(d) == 0) {
        return pt1;
    }

    double lat1 = Math.toRadians(pt1.getLatitude());
    double lon1 = Math.toRadians(pt1.getLongitude());
    double brgAsRadians = Math.toRadians(brg);

    double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / EARTH_RADIUS_IN_METERS)
            + Math.cos(lat1) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(brgAsRadians));
    double x = Math.sin(brgAsRadians) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(lat1);
    double y = Math.cos(d / EARTH_RADIUS_IN_METERS) - Math.sin(lat1) * Math.sin(lat2);
    double lon2 = lon1 + Math.atan2(x, y);

    return new Point(Math.toDegrees(lat2), Math.toDegrees(lon2), null);

}