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:cn.spinsoft.wdq.widget.swipe.MaterialProgressDrawable.java

private float getMinProgressArc(Ring ring) {
    return (float) Math.toRadians(ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius()));
}

From source file:com.example.brendan.learningandroid2.SeekArc.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    final int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
    final int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
    final int min = Math.min(width, height);
    float top = 0;
    float left = 0;
    int arcDiameter = 0;

    mTranslateX = (int) (width * 0.5f);
    mTranslateY = (int) (height * 0.5f);

    arcDiameter = min - getPaddingLeft();
    mArcRadius = arcDiameter / 2;/*from  w  w w  .  j  a  v  a  2 s  .c om*/
    top = height / 2 - (arcDiameter / 2);
    left = width / 2 - (arcDiameter / 2);
    mArcRect.set(left, top, left + arcDiameter, top + arcDiameter);

    int arcStart = (int) mProgressSweep + mStartAngle + mRotation + 90;
    mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(arcStart)));
    mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(arcStart)));

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

From source file:gov.wa.wsdot.android.wsdot.ui.amtrakcascades.AmtrakCascadesSchedulesActivity.java

/**
 * Haversine formula//from w  w  w.j a  va 2 s.c  o  m
 * 
 * Provides great-circle distances between two points on a sphere from their longitudes and latitudes
 * 
 * http://en.wikipedia.org/wiki/Haversine_formula
 * 
 * @param latitude
 * @param longitude
 */
protected void getDistanceFromStation(double latitude, double longitude) {
    for (AmtrakCascadesStationItem station : amtrakStationItems) {
        double earthRadius = 3958.75; // miles
        double dLat = Math.toRadians(station.getLatitude() - latitude);
        double dLng = Math.toRadians(station.getLongitude() - longitude);
        double sindLat = Math.sin(dLat / 2);
        double sindLng = Math.sin(dLng / 2);
        double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(latitude))
                * Math.cos(Math.toRadians(station.getLatitude()));

        double c = 2 * Math.asin(Math.sqrt(a));
        int distance = (int) Math.round(earthRadius * c);

        station.setDistance(distance);
    }

    getFromLocation();
}

From source file:com.bdb.weather.display.preferences.ColorPreferencePanel.java

private void createSeriesData() {
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        XYSeries series = dataset.getSeries(i);
        series.clear();/*from   ww  w.ja  v  a2  s . co m*/
        for (int j = 0; j < 360; j++) {
            series.add(j / 360.0, Math.sin(Math.toRadians(j + (i * (360.0 / dataset.getSeriesCount())))),
                    false);
        }
        series.fireSeriesChanged();
    }
}

From source file:rod_design_compute.ShowPanel.java

private void drawSlider(Rod rod, Point point, Graphics g) {
    int[] x = new int[3];
    int[] y = new int[3];
    int l = lengthSlider;
    double theta = rod.getAngle();

    x[0] = (int) (Math.cos(theta) * l / 2);
    y[0] = (int) (Math.sin(theta) * l / 2);
    x[1] = -x[0];/* w  w w .ja v  a 2  s. c o m*/
    y[1] = -y[0];

    theta += Math.toRadians(45);
    x[2] = (int) (Math.cos(theta) * l / 10);
    y[2] = (int) (Math.sin(theta) * l / 10);

    for (int i = 0; i < 2; i++) {
        x[i] = toScreenX(point.X) + x[i];
        y[i] = toScreenY(point.Y) - y[i];
    }

    g.drawLine(x[0], y[0], x[1], y[1]);
    g.drawLine((int) (0.9 * x[0] + 0.1 * x[1]), (int) (0.9 * y[0] + 0.1 * y[1]),
            (int) (0.9 * x[0] + 0.1 * x[1] + x[2]), (int) (0.9 * y[0] + 0.1 * y[1] + y[2]));
    g.drawLine((int) (0.8 * x[0] + 0.2 * x[1]), (int) (0.8 * y[0] + 0.2 * y[1]),
            (int) (0.8 * x[0] + 0.2 * x[1] + x[2]), (int) (0.8 * y[0] + 0.2 * y[1] + y[2]));
    g.drawLine((int) (0.1 * x[0] + 0.9 * x[1]), (int) (0.1 * y[0] + 0.9 * y[1]),
            (int) (0.1 * x[0] + 0.9 * x[1] + x[2]), (int) (0.1 * y[0] + 0.9 * y[1] + y[2]));
    g.drawLine((int) (0.2 * x[0] + 0.8 * x[1]), (int) (0.2 * y[0] + 0.8 * y[1]),
            (int) (0.2 * x[0] + 0.8 * x[1] + x[2]), (int) (0.2 * y[0] + 0.8 * y[1] + y[2]));
}

From source file:info.wncwaterfalls.app.ResultsActivity.java

public static Location calculatePositionAtRange(Location origin, double range, double bearing) {
    double EarthRadius = 6371000; // m

    double latA = Math.toRadians(origin.getLatitude());
    double lonA = Math.toRadians(origin.getLongitude());
    double angularDistance = range / EarthRadius;
    double trueCourse = Math.toRadians(bearing);

    double lat = Math.asin(Math.sin(latA) * Math.cos(angularDistance)
            + Math.cos(latA) * Math.sin(angularDistance) * Math.cos(trueCourse));

    double dlon = Math.atan2(Math.sin(trueCourse) * Math.sin(angularDistance) * Math.cos(latA),
            Math.cos(angularDistance) - Math.sin(latA) * Math.sin(lat));

    double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI;

    lat = Math.toDegrees(lat);//from   ww w . j  a v  a2 s . c o  m
    lon = Math.toDegrees(lon);

    Location destination = new Location("");
    destination.setLatitude((float) lat);
    destination.setLongitude((float) lon);

    return destination;
}

From source file:com.cuelogic.android.WheelIndicatorView.java

private void draw(String tag, WheelIndicatorItem indicatorItem, RectF surfaceRectF, float angle,
        Canvas canvas) {//  w ww .  j  a  va2s .c om
    //        itemArcPaint.setColor(Color.parseColor("#FF9000"));
    itemEndPointsPaint.setColor(indicatorItem.getColor());

    // Draw arc
    //        canvas.drawArc(surfaceRectF, ANGLE_INIT_OFFSET, angle, false, itemArcPaint);

    float cxTop = minDistViewSize / 2;
    float cyTop = 0 + itemsLineWidth;

    // Draw top circle
    //        canvas.drawCircle(cxTop, cyTop, itemsLineWidth, itemEndPointsPaint);
    //        Log.v(tag, "cxTop: "+cxTop + " cyTop: "+cyTop);

    int topPosition = minDistViewSize / 2 - itemsLineWidth;

    float cxEnd = (float) (Math.cos(Math.toRadians(angle + ANGLE_INIT_OFFSET)) * topPosition + topPosition
            + itemsLineWidth);
    float cyEnd = (float) (Math.sin(Math.toRadians((angle + ANGLE_INIT_OFFSET))) * topPosition + topPosition
            + itemsLineWidth);

    // Draw end circle
    canvas.drawCircle(cxEnd, cyEnd, itemsLineWidth, itemEndPointsPaint);
    Log.v(tag, "cxEnd: " + cxEnd + " cyEnd: " + cyEnd);

    int leftRect = (int) cxEnd - itemsLineWidth;
    int topRect = (int) cyEnd - itemsLineWidth;
    int rightRect = (int) cxEnd + itemsLineWidth;
    int bottomRect = (int) cyEnd + itemsLineWidth;

    //        if(null == indicatorItem.getRect()) {
    //
    //        }

    Rect rect = new Rect(leftRect, topRect, rightRect, bottomRect);
    indicatorItem.setRect(rect);

}

From source file:org.rifidi.designer.library.retail.clothingrack.ClothingRack.java

private void prepare() {
    if (clotModel == null) {
        try {//from w ww  .java  2s .com
            URI modelpath = getClass().getClassLoader()
                    .getResource("org/rifidi/designer/library/retail/clothing/cloth0.jme").toURI();
            clotModel = (Node) BinaryImporter.getInstance().load(modelpath.toURL());
        } catch (MalformedURLException e) {
            logger.error("Can't load model: " + e);
        } catch (IOException e) {
            logger.error("Can't load model: " + e);
        } catch (URISyntaxException e) {
            logger.error("Can't load model: " + e);
        }
        Quaternion quat = new Quaternion(new float[] { (float) Math.toRadians(270f), 0f, 0f });
        clotModel.setLocalRotation(quat);
    }
}

From source file:com.triggertrap.seekarc.SeekArc.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
    int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
    int min = Math.min(width, height);

    mTranslateX = min / 2;/*from   w  w w . j  a  v a 2 s  . c  o m*/
    mTranslateY = min / 2;

    int arcDiameter = min - getPaddingLeft() - getPaddingRight();
    mArcRadius = arcDiameter / 2;
    int top = min / 2 - (arcDiameter / 2);
    int left = min / 2 - (arcDiameter / 2);
    mArcRect.set(left, top, left + arcDiameter, top + arcDiameter);

    int arcStart = (int) mProgressSweep + mStartAngle + mRotation - mAngleOffset;
    mThumbXPos = (int) (mArcRadius * Math.cos(Math.toRadians(arcStart)));
    mThumbYPos = (int) (mArcRadius * Math.sin(Math.toRadians(arcStart)));

    setTouchInSide(mTouchInside);
    setMeasuredDimension(min, min);
}

From source file:uk.ac.cam.cl.dtg.util.locations.PostCodeIOLocationResolver.java

/**
 * @param lat1//from   w ww  . j  a v a2  s.  c  om
 *            - latitude 1
 * @param lon1
 *            - longitude 1
 * @param lat2
 *            - latitude 2
 * @param lon2
 *            - longitude 2
 * @return - distance in miles
 */
private double getLatLonDistanceInMiles(final double lat1, final double lon1, final double lat2,
        final double lon2) {
    // borrowed from http://www.movable-type.co.uk/scripts/latlong.html
    int R = 6371000;
    double phi1 = Math.toRadians(lat1);
    double phi2 = Math.toRadians(lat2);
    double deltaPhi = Math.toRadians(lat2 - lat1);
    double deltaLambda = Math.toRadians(lon2 - lon1);

    double a = Math.sin(deltaPhi / 2) * Math.sin(deltaPhi / 2)
            + Math.cos(phi1) * Math.cos(phi2) * Math.sin(deltaLambda / 2) * Math.sin(deltaLambda / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    double d = R * c;

    // convert from metres to miles
    d = (d / 1000) * 0.621371;

    return d;
}