Example usage for java.lang Math toDegrees

List of usage examples for java.lang Math toDegrees

Introduction

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

Prototype

public static double toDegrees(double angrad) 

Source Link

Document

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

Usage

From source file:Main.java

/**
 * Draws a string that is aligned by one anchor point and rotated about
 * another anchor point./*from w  ww  .j  a  v a  2  s  .  c o m*/
 * 
 * @param text
 *            the text.
 * @param g2
 *            the graphics device.
 * @param x
 *            the location of the text anchor.
 * @param y
 *            the location of the text anchor.
 * @param textAnchor
 *            the text anchor.
 * @param rotationX
 *            the x-coordinate for the rotation anchor point.
 * @param rotationY
 *            the y-coordinate for the rotation anchor point.
 * @param angle
 *            the rotation angle.
 */
public static void drawRotatedString(final String text, final Canvas g2, final float x, final float y,
        final Paint paint, float angle) {

    //g2.drawCircle(x, y, 2, paint);
    g2.save();
    if (angle == 0.0)
        g2.drawText(text, x, y, paint);
    else {
        g2.rotate((float) Math.toDegrees(angle), x, y);
        g2.drawText(text, x, y, paint);
    }
    g2.restore();
}

From source file:Satellite.java

public static double[] Convert_To_Lat_Long(Vector3D posVec) {
    double Xcomp = posVec.getX();
    double Ycomp = posVec.getY();
    double Zcomp = posVec.getZ();

    double longitude;
    double latitude;
    double altitude;

    //Done so all cases of longitudes are right
    if (Ycomp > 0) {
        if (Xcomp > 0) {
            longitude = Math.toDegrees(Math.atan(Ycomp / Xcomp));
        } else {// ww  w .  jav a  2 s .  co  m
            longitude = 180 - Math.toDegrees(Math.atan(Math.abs(Ycomp / Xcomp)));
        }
    } else {
        if (Xcomp > 0) {
            longitude = -1 * Math.toDegrees(Math.atan(Math.abs(Ycomp / Xcomp)));
        } else {
            longitude = -1 * (180 - Math.toDegrees(Math.atan(Ycomp / Xcomp)));
        }
    }

    //Calculate latitude
    latitude = Math.toDegrees(Math.atan(Zcomp / Math.sqrt(Xcomp * Xcomp + Ycomp * Ycomp)));

    //Calculate radius and altitude
    double EER = Constants.WGS84_EARTH_EQUATORIAL_RADIUS; //Earth Equator Radius in meters
    double EPR = EER - EER * Constants.WGS84_EARTH_FLATTENING; //Earth Polar Radius in meters

    double earthRadius = Math
            .sqrt((Math.pow(EPR * EPR * Math.cos(latitude), 2) + Math.pow(EER * EER * Math.cos(latitude), 2))
                    / (Math.pow(EPR * Math.cos(latitude), 2) + Math.pow(EER * Math.cos(latitude), 2)));
    double orbitRadius = Math.sqrt(Xcomp * Xcomp + Ycomp * Ycomp + Zcomp * Zcomp);
    altitude = orbitRadius - earthRadius;

    return new double[] { latitude, longitude, altitude };
}

From source file:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java

public static Dataset generateAzimuthalArray(double[] beamCentre, int[] shape, double min) {
    //Number of circles
    int n = (int) Math.floor((min + 180) / 360);
    double minInBase = (min - (360 * n));

    Dataset out = DatasetFactory.zeros(shape, Dataset.FLOAT64);
    PositionIterator iter = out.getPositionIterator();

    int[] pos = iter.getPos();

    //+0.5 for centre of pixel
    while (iter.hasNext()) {
        double val = Math.toDegrees(Math.atan2(pos[0] + 0.5 - beamCentre[1], pos[1] + 0.5 - beamCentre[0]));
        if (val < minInBase)
            val = val + 360;
        out.set(val + 360 * n, pos);
    }/*from  www. j a  v  a2 s .  co  m*/

    return out;

}

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

/**
 * Returns coordinates of position which is given distance and bearing from given point.
 * @param pt1/*  w  w w . j a v  a 2s .  c om*/
 * @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);

}

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

private void slowForTightCorner(Car mCar) {

    double turn = 0, distance = 0;
    CheckPoint cp = mCar.getCheckpoint();

    Point target = schewy.getMidPoint(cp);

    turn = Math.abs(mCar.calculateHeading(target));
    distance = mCar.getPosition().getDistance(target);
    double ratio = 0;

    double degreesPerSecond = mCar.calculateMaximumTurning(mCar.getAccelerationPercent());
    double maxAngularVelocity = Double.MIN_VALUE;
    for (int i = 0; i < 15; i++) {
        CheckPoint nextCp = getTrack().getNextCheckpoint(cp);
        double angle = Math.toDegrees(schewy.getAngle(cp));
        Point point = schewy.getMidPoint(cp);
        Point nextPoint = schewy.getMidPoint(nextCp);
        Vec2 distance2 = new Vec2((float) nextPoint.getX() - (float) point.getX(),
                (float) nextPoint.getY() - (float) point.getY());
        distance = distance + (double) distance2.length();

        turn = turn + Math.abs(angle);
        double seconds = distance / (mCar.getVelocity().length());

        double tempRatio = turn / (seconds * degreesPerSecond);
        if (tempRatio > ratio)
            ratio = tempRatio;/*from w  ww  . j ava2s . co  m*/

        double seconds2 = distance2.length() / mCar.getVelocity().length();
        double angularVelocity = angle / seconds2;

        if (angularVelocity > maxAngularVelocity)
            maxAngularVelocity = angularVelocity;
        cp = nextCp;
        if (seconds > 1)
            break;

    }
    System.out.println("Velocity:" + getCar().getVelocity().length());
    System.out.println("MaxAv:" + maxAngularVelocity);

    System.out.println("Ratio:" + ratio + "," + maxRatio);

    if (ratio > maxRatio)
        maxRatio = ratio;

    if (ratio > 15) {
        mCar.setBrakePercent(100);
        mCar.setAccelerationPercent(0);
    } else if (ratio > 12) {
        mCar.setBrakePercent(50);
        mCar.setAccelerationPercent(0);
    } else if (ratio > 12) {
        mCar.setBrakePercent(0);
        mCar.setAccelerationPercent(0);
    } else {
        mCar.setBrakePercent(0);
        mCar.setAccelerationPercent(100);
    }

    if (maxAngularVelocity > 360) {
        System.out.println("MAXAV BRAKING!");
        mCar.setBrakePercent(100);
        mCar.setAccelerationPercent(0);
    }

}

From source file:org.mapfish.print.map.readers.WMSCMapReader.java

public void render(Transformer transformer, ParallelMapTileLoader parallelMapTileLoader, String srs,
        boolean first) {
    PJsonObject customParams = params.optJSONObject("customParams");

    // store the rotation to not change for other layers
    double oldAngle = transformer.getRotation();

    // native WMS rotation - only works in singleTile mode
    if (customParams != null && customParams.optString("angle") != null) { // For GeoServer
        transformer.setRotation(0);// w w w .  j  av a  2 s.c  om
    }
    if (params.optBool("useNativeAngle", false)) {
        String angle = String.valueOf(-Math.toDegrees(transformer.getRotation()));
        try {
            if (customParams != null) {
                customParams.getInternalObj().put("angle", angle); // For GeoServer
                customParams.getInternalObj().put("map_angle", angle); // For MapServer
            } else {
                Map customMap = new HashMap();
                customMap.put("angle", angle); // For GeoServer
                customMap.put("map_angle", angle); // For MapServer
                params.getInternalObj().put("customParams", customMap);
            }
            transformer.setRotation(0);
        } catch (org.json.JSONException e) {
            LOGGER.error("Unable to set angle: " + e.getClass().getName() + " - " + e.getMessage());
        }
    }
    super.render(transformer, parallelMapTileLoader, srs, first);
    // restore the rotation for other layers
    transformer.setRotation(oldAngle);
}

From source file:demo.support.NavUtils.java

/**
 * Returns coordinates of position which is given distance and bearing from given point.
 * @param pt1/*  ww  w  .  j a  v a 2s. c om*/
 * @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));

}

From source file:com.l2jfree.gameserver.util.Util.java

/** Return degree value of object 2 to the horizontal line with object 1 being the origin */
public final static double calculateAngleFrom(int obj1X, int obj1Y, int obj2X, int obj2Y) {
    double angleTarget = Math.toDegrees(Math.atan2(obj2Y - obj1Y, obj2X - obj1X));

    return getValidDegree(angleTarget);
}

From source file:org.gearvrf.keyboard.util.Util.java

public static float getYRotationAngle(Vector3D rotatingVector, Vector3D targetObject) {
    return (float) Math.toDegrees(Math.atan2(targetObject.getX() - rotatingVector.getX(),
            targetObject.getZ() - rotatingVector.getZ()));
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.HubLocationProvider.java

@Subscribe
public void on(Announce announce) {
    if (announce.getLat() != 0 || announce.getLon() != 0) {
        AssetPosition pos = new AssetPosition(announce.getSysName(), Math.toDegrees(announce.getLat()),
                Math.toDegrees(announce.getLon()));
        positionsToSend.put(announce.getSrc(), pos);
    }/* ww w.  j  a  va  2  s  .c om*/
}