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:Hexagon.java

public Hexagon(Point2D center, int size) {
    super();/*from   www  .ja  v a  2  s .c  om*/
    this.center = center;
    this.size = size;

    /**
      * MATH:
      *   With the hexagon points={TOP, UPPER-RIGHT, LOWER-RIGHT, BOTTOM, LOWER-LEFT, UPPER-RIGHT}
      *   size = length of each actual segment of the hexagon
      *   width = bounding rectangle width
      *   height = bounding rectangle height
      *   each inner angle is 120 degrees
      *   outside angles are 30-60-90 triangles with 30 near TOP and BOTTOM and 60 near sides
      *   hOffset = height difference between 'size' edge and bounding rectangle corners
      *   wOffset = width difference between TOP/BOTTOM points and bounding rectangle corners
      */

    double thirtyDegrees = Math.toRadians(30);
    hOffset = Math.sin(thirtyDegrees) * size;
    wOffset = Math.cos(thirtyDegrees) * size;

    height = (2 * hOffset) + size;
    width = (2 * wOffset);

    double left = center.getX() - (width / 2);
    double right = center.getX() + (width / 2);
    double top = center.getY() - (height / 2);
    double bottom = center.getY() + (height / 2);
    boundingBox = new Rectangle2D.Double(left, top, width, height);

    boundingCorners = new HashMap<BoundingCorner, Point2D>();
    boundingCorners.put(BoundingCorner.TopRight, new Point2D.Double(right, top));
    boundingCorners.put(BoundingCorner.TopLeft, new Point2D.Double(left, top));
    boundingCorners.put(BoundingCorner.BottomRight, new Point2D.Double(right, bottom));
    boundingCorners.put(BoundingCorner.BottomLeft, new Point2D.Double(left, bottom));

    corners = new HashMap<Corner, Point2D>();
    corners.put(Corner.Top, new Point2D.Double(center.getX(), top));
    corners.put(Corner.UpperRight, new Point2D.Double(right, (top + hOffset)));
    corners.put(Corner.LowerRight, new Point2D.Double(right, (bottom - hOffset)));
    corners.put(Corner.Bottom, new Point2D.Double(center.getX(), bottom));
    corners.put(Corner.LowerLeft, new Point2D.Double(left, (bottom - hOffset)));
    corners.put(Corner.UpperLeft, new Point2D.Double(left, (top + hOffset)));

    for (Corner corner : Corner.values()) {
        Point2D p2d = corners.get(corner);
        addPoint((int) p2d.getX(), (int) p2d.getY());
    }
}

From source file:org.openhab.core.library.types.PointType.java

public DecimalType getGravity() {
    double latRad = Math.toRadians(latitude.doubleValue());
    double deltaG = -2000.0 * (altitude.doubleValue() / 1000) * EARTH_GRAVITATIONAL_CONSTANT
            / (Math.pow(WGS84_a, 3.0));
    double sin2lat = Math.sin(latRad) * Math.sin(latRad);
    double sin22lat = Math.sin(2.0 * latRad) * Math.sin(2.0 * latRad);
    double result = (9.780327 * (1.0 + 5.3024e-3 * sin2lat - 5.8e-6 * sin22lat) + deltaG);
    return new DecimalType(result);
}

From source file:org.opentripplanner.common.geometry.SphericalDistanceLibrary.java

@Override
public final double fastLength(LineString lineString) {
    // Warn: do not use LineString.getCentroid() as it is broken
    // for degenerated geometry (same first/last point).
    Coordinate[] coordinates = lineString.getCoordinates();
    double middleY = (coordinates[0].y + coordinates[coordinates.length - 1].y) / 2.0;
    double cosLat = FastMath.cos(Math.toRadians(middleY));
    return equirectangularProject(lineString, cosLat).getLength() * RADIUS_OF_EARTH_IN_M;
}

From source file:BufferedImageThread.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Dimension d = getSize();//from w ww  .  j  ava 2 s  . c  om

    bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bi.createGraphics();

    step(d.width, d.height);

    AffineTransform at = new AffineTransform();
    at.setToIdentity();
    at.translate(x, y);
    at.rotate(Math.toRadians(rotate));
    at.scale(scale, scale);
    big.drawImage(image, at, this);

    Graphics2D g2D = (Graphics2D) g;
    g2D.drawImage(bi, 0, 0, null);

    big.dispose();
}

From source file:com.cyrilmottier.android.polaris2demo.CircleDemoActivity.java

/** Generate LatLng of radius marker */
private static LatLng toRadiusLatLng(LatLng center, double radius) {
    double radiusAngle = Math.toDegrees(radius / RADIUS_OF_EARTH_METERS)
            / Math.cos(Math.toRadians(center.latitude));
    return new LatLng(center.latitude, center.longitude + radiusAngle);
}

From source file:org.opensextant.util.GeodeticUtility.java

/** Haversine distance using LL1 to LL2;
 *
 * @param p1  geodesy API LatLon/*from w w w.  java 2  s.  co  m*/
 * @param p2  geodesy API LatLon
 * @return distance in meters.
 */
public final static long distanceMeters(LatLon p1, LatLon p2) {
    double lat1 = p1.getLatitude();
    double lon1 = p1.getLongitude();
    double lat2 = p2.getLatitude();
    double lon2 = p2.getLongitude();

    /* Courtesy of http://rosettacode.org/wiki/Haversine_formula#Java */
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    lat1 = Math.toRadians(lat1);
    lat2 = Math.toRadians(lat2);

    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.asin(Math.sqrt(a));
    return (long) (EARTH_RADIUS * c);
}

From source file:io.github.malapert.jwcs.coordsystem.Utility.java

/**
 * Calculates the matrix that represents a 3d rotation around the Y axis.
 *
 * Reference:  //from  w w  w.j av  a2 s  .  co  m
 * ----------
 * Diebel, J. 2006, Stanford University, Representing Attitude:
 * Euler angles, Unit Quaternions and Rotation Vectors. 
 * http://ai.stanford.edu/~diebel/attitude.html
 * 
 * Notes:
 * ------
 * Return the rotation matrix for a rotation around the X axis.
 * This is a rotation in the YZ plane. Note that we construct
 * a new vector with: xnew = R1.x
 * In the literature, this rotation is usually called R1
 * 
 * @param angle Rotation angle in degrees
 * @return A 3x3 matrix representing the rotation about angle around Y axis.
 */
public final static RealMatrix rotY(double angle) {
    double angleRadians = Math.toRadians(angle);
    double[][] array = { { Math.cos(angleRadians), 0.d, -1 * Math.sin(angleRadians) }, { 0.d, 1.d, 0.d },
            { Math.sin(angleRadians), 0.d, Math.cos(angleRadians) } };
    return MatrixUtils.createRealMatrix(array);
}

From source file:de.quist.app.maps.example.CircleDemoActivity.java

/** Generate LatLng of radius marker */
private static LatLng toRadiusLatLng(LatLng center, double radius) {
    double radiusAngle = Math.toDegrees(radius / RADIUS_OF_EARTH_METERS)
            / Math.cos(Math.toRadians(center.latitude()));
    return BuildConfig.MAP_BINDING.newLatLng(center.latitude(), center.longitude() + radiusAngle);
}

From source file:com.crs4.roodin.moduletester.CustomView.java

/**
 * @param canvas//from  w w w .  ja v  a 2s  .  c  om
 */
private void drawRadar(Canvas canvas) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.RED);
    paint.setAlpha(100);

    float rotation = currentRotation; //gRotationZ_deg + initialMapRotation;

    for (int i = -35; i < 35; i = i + 2) {
        float arrowX1 = (float) (translateX - Math.sin(Math.toRadians(rotation + i)) * 45);
        float arrowY1 = (float) (translateY - Math.cos(Math.toRadians(rotation + i)) * 45);
        canvas.drawLine(translateX, translateY, arrowX1, arrowY1, paint);

    }

    paint.setAlpha(100);
    paint.setColor(Color.RED);
    canvas.drawCircle(translateX, translateY, 7, paint);

    paint.setColor(Color.YELLOW);
    canvas.drawCircle(translateX, translateY, 6, paint);

    paint.setColor(Color.RED);
    canvas.drawCircle(translateX, translateY, 1, paint);
}

From source file:de.openali.odysseus.chart.framework.util.img.GenericChartLabelRenderer.java

private Rectangle calcSize(final GC gc, final int degree) {
    if (m_titleBean == null)
        return new Rectangle(0, 0, 0, 0);

    final Point textSize = calcTextSize(gc, m_titleBean.getText());
    final int border = isDrawBorder() ? m_borderStyle.getStroke().getWidth() : 0;
    final Point overAllSize = new Point(
            textSize.x + border * 2 + m_titleBean.getInsets().left + m_titleBean.getInsets().right,
            textSize.y + border * 2 + m_titleBean.getInsets().top + m_titleBean.getInsets().bottom);

    final Rectangle textRect = getTextRect(m_titleBean.getTextAnchorX(), m_titleBean.getTextAnchorY(),
            overAllSize);/* www. j a v a  2s . co m*/
    final double radian = Math.toRadians(degree);
    final double cosi = Math.cos(radian);
    final double sinu = Math.sin(radian);
    final double rotX = cosi * textRect.x + sinu * textRect.y;
    final double rotY = sinu * textRect.x + cosi * textRect.y;
    final double rotWidth = Math.abs(cosi * textRect.width) + Math.abs(sinu * textRect.height);
    final double rotHeight = Math.abs(sinu * textRect.width) + Math.abs(cosi * textRect.height);

    return new Rectangle((int) Math.round(rotX), (int) Math.round(rotY), (int) Math.round(rotWidth),
            (int) Math.round(rotHeight));
}