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:com.cuelogic.android.WheelIndicatorView.java

private void drawOnlyArc(WheelIndicatorItem indicatorItem, RectF surfaceRectF, float angle, float repeatAngle,
        Canvas canvas) {//  www.  ja va2 s . co  m
    itemArcPaint.setColor(Color.parseColor("#FF9000"));
    itemEndPointsPaint.setColor(Color.parseColor("#FF9000"));

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

    //        // Draw top circle
    canvas.drawCircle(minDistViewSize / 2, 0 + itemsLineWidth, itemsLineWidth, itemEndPointsPaint);
    int topPosition = minDistViewSize / 2 - itemsLineWidth;

    // Draw end circle
    canvas.drawCircle(
            (float) (Math.cos(Math.toRadians(angle + ANGLE_INIT_OFFSET)) * topPosition + topPosition
                    + itemsLineWidth),
            (float) (Math.sin(Math.toRadians((angle + ANGLE_INIT_OFFSET))) * topPosition + topPosition
                    + itemsLineWidth),
            itemsLineWidth, itemEndPointsPaint);

    //        draw(indicatorItem, wheelBoundsRectF, repeatAngle, canvas);
}

From source file:com.android.fastergallery.ui.TileImageView.java

private void getRange(Rect out, int cX, int cY, int level, float scale, int rotation) {

    double radians = Math.toRadians(-rotation);
    double w = getWidth();
    double h = getHeight();

    double cos = Math.cos(radians);
    double sin = Math.sin(radians);
    int width = (int) Math.ceil(Math.max(Math.abs(cos * w - sin * h), Math.abs(cos * w + sin * h)));
    int height = (int) Math.ceil(Math.max(Math.abs(sin * w + cos * h), Math.abs(sin * w - cos * h)));

    int left = (int) FloatMath.floor(cX - width / (2f * scale));
    int top = (int) FloatMath.floor(cY - height / (2f * scale));
    int right = (int) FloatMath.ceil(left + width / scale);
    int bottom = (int) FloatMath.ceil(top + height / scale);

    // align the rectangle to tile boundary
    int size = sTileSize << level;
    left = Math.max(0, size * (left / size));
    top = Math.max(0, size * (top / size));
    right = Math.min(mImageWidth, right);
    bottom = Math.min(mImageHeight, bottom);

    out.set(left, top, right, bottom);/*w  w w .  ja va 2  s . com*/
}

From source file:com.android.gallery3d.ui.TileImageView.java

private void getRange(Rect out, int cX, int cY, int level, float scale, int rotation) {

    double radians = Math.toRadians(-rotation);
    double w = getWidth();
    double h = getHeight();

    double cos = Math.cos(radians);
    double sin = Math.sin(radians);
    int width = (int) Math.ceil(Math.max(Math.abs(cos * w - sin * h), Math.abs(cos * w + sin * h)));
    int height = (int) Math.ceil(Math.max(Math.abs(sin * w + cos * h), Math.abs(sin * w - cos * h)));

    int left = (int) Math.floor(cX - width / (2f * scale));
    int top = (int) Math.floor(cY - height / (2f * scale));
    int right = (int) Math.ceil(left + width / scale);
    int bottom = (int) Math.ceil(top + height / scale);

    // align the rectangle to tile boundary
    int size = sTileSize << level;
    left = Math.max(0, size * (left / size));
    top = Math.max(0, size * (top / size));
    right = Math.min(mImageWidth, right);
    bottom = Math.min(mImageHeight, bottom);

    out.set(left, top, right, bottom);/*from ww  w  .  ja v a2 s. co m*/
}

From source file:chat.client.agent.ChatClientAgent.java

public static float distance(float lat1, float lng1, float lat2, float lng2) {
    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    int meterConversion = 1609;

    return new Float(dist * meterConversion).floatValue();
}

From source file:Human1.java

public void setRShoulderRot(int rotation) {
    rShoulderRot = rotation;/*w w  w  .jav a  2s. com*/
    rShoulderAA.angle = (float) Math.toRadians(rShoulderRot);
    Human_r_shoulder.getTransform(tmpTrans);
    tmpTrans.setRotation(rShoulderAA);
    Human_r_shoulder.setTransform(tmpTrans);
}

From source file:com.ex.wakemeup.MainActivity.java

public Double getDistanceInMeters(double latitude, double longitude, double latval, double lonval) {
    Double dlon = Math.toRadians(lonval) - Math.toRadians(longitude);
    Double dlat = Math.toRadians(latval) - Math.toRadians(latitude);

    Double a = (sin(dlat / 2)) * (sin(dlat / 2))
            + cos(latval) * cos(latitude) * (sin(dlon / 2)) * (sin(dlon / 2));
    Double c = 2 * atan2(sqrt(a), sqrt(1 - a));
    Double dist = 6373 * c * 1000; // Radius of earth is 6373 kms
    return dist;/*from w w  w.  j av a  2s.c om*/

}

From source file:Human1.java

public void setRElbowRot(int rotation) {
    float angle = (float) Math.toRadians(rotation);
    rElbowRot = rotation;//from w  w w.j a  v  a 2  s  .  c  om
    rElbowAA.angle = (float) Math.toRadians(rElbowRot);
    Human_r_elbow.getTransform(tmpTrans);
    tmpTrans.setRotation(rElbowAA);
    Human_r_elbow.setTransform(tmpTrans);
}

From source file:nz.co.fortytwo.signalk.handler.NMEAHandler.java

/**
 * Adds NMEA sentence listeners to process NMEA to simple output
 * // www  .  ja v a 2s .  com
 * @param processor
 */
private void setNmeaListeners() {

    addSentenceListener(new SentenceListener() {

        private boolean startLat = true;
        private boolean startLon = true;
        double previousLat = 0;
        double previousLon = 0;
        double previousSpeed = 0;
        static final double ALPHA = 1 - 1.0 / 6;

        public void sentenceRead(SentenceEvent evt) {
            SignalKModel sk = (SignalKModel) evt.getSource();
            String now = (String) sk.get(vessels_dot_self_dot + "sources.nmea.0183" + dot
                    + evt.getSentence().getSentenceId() + dot + timestamp);
            try {

                if (evt.getSentence() instanceof PositionSentence) {
                    PositionSentence sen = (PositionSentence) evt.getSentence();

                    if (startLat) {
                        previousLat = sen.getPosition().getLatitude();
                        startLat = false;
                    }
                    previousLat = Util.movingAverage(ALPHA, previousLat, sen.getPosition().getLatitude());
                    if (logger.isDebugEnabled())
                        logger.debug("lat position:" + sen.getPosition().getLatitude() + ", hemi="
                                + sen.getPosition().getLatitudeHemisphere());
                    sk.put(vessels_dot_self_dot + nav_position_latitude, previousLat);

                    if (startLon) {
                        previousLon = sen.getPosition().getLongitude();
                        startLon = false;
                    }
                    previousLon = Util.movingAverage(ALPHA, previousLon, sen.getPosition().getLongitude());
                    sk.put(vessels_dot_self_dot + nav_position_longitude, previousLon);
                    sk.put(vessels_dot_self_dot + nav_position + dot + source,
                            vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId());
                    sk.put(vessels_dot_self_dot + nav_position + dot + timestamp, now);
                }

                if (evt.getSentence() instanceof HeadingSentence) {

                    if (!(evt.getSentence() instanceof VHWSentence)) {

                        HeadingSentence sen = (HeadingSentence) evt.getSentence();

                        if (sen.isTrue()) {
                            try {
                                sk.put(vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId()
                                        + dot + source + dot + "src", sen.toSentence());
                                sk.put(vessels_dot_self_dot + nav_courseOverGroundTrue,
                                        Math.toRadians(sen.getHeading()),
                                        vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(),
                                        now);
                            } catch (Exception e) {
                                logger.error(e.getMessage());
                            }
                        } else {
                            sk.put(vessels_dot_self_dot + nav_courseOverGroundMagnetic,
                                    Math.toRadians(sen.getHeading()),
                                    vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(),
                                    now);
                        }
                    }
                }

                if (evt.getSentence() instanceof RMCSentence) {
                    RMCSentence sen = (RMCSentence) evt.getSentence();
                    if (rmcClock)
                        Util.checkTime(sen);
                    previousSpeed = Util.movingAverage(ALPHA, previousSpeed, Util.kntToMs(sen.getSpeed()));
                    sk.put(vessels_dot_self_dot + nav_speedOverGround, previousSpeed,
                            vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(), now);
                }
                if (evt.getSentence() instanceof VHWSentence) {
                    VHWSentence sen = (VHWSentence) evt.getSentence();
                    //VHW sentence types have both, but true can be empty
                    try {
                        sk.put(vessels_dot_self_dot + nav_courseOverGroundMagnetic,
                                Math.toRadians(sen.getMagneticHeading()),
                                vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(), now);
                        sk.put(vessels_dot_self_dot + nav_courseOverGroundTrue,
                                Math.toRadians(sen.getHeading()),
                                vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(), now);

                    } catch (DataNotAvailableException e) {
                        logger.error(e.getMessage());
                    }
                    previousSpeed = Util.movingAverage(ALPHA, previousSpeed, Util.kntToMs(sen.getSpeedKnots()));
                    sk.put(vessels_dot_self_dot + nav_speedOverGround, previousSpeed,
                            vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(), now);
                }

                // MWV wind
                // Mega sends $IIMVW with 0-360d clockwise from bow, (relative to bow)
                // Mega value is int+'.0'
                if (evt.getSentence() instanceof MWVSentence) {
                    MWVSentence sen = (MWVSentence) evt.getSentence();
                    //TODO: check relative to bow or compass + sen.getSpeedUnit()
                    // relative to bow
                    double angle = sen.getAngle();
                    sk.put(vessels_dot_self_dot + env_wind_angleApparent, Math.toRadians(angle),
                            vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(), now);
                    sk.put(vessels_dot_self_dot + env_wind_speedApparent, Util.kntToMs(sen.getSpeed()),
                            vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(), now);
                    //sk.put(vessels_dot_self_dot + env_wind+dot+source,vessels_dot_self_dot+"sources.nmea.0183"+dot+sen.getSentenceId());
                    //sk.put(vessels_dot_self_dot + env_wind + dot+timestamp , now);
                }

                // Cruzpro BVE sentence
                // TODO: how to deal with multiple engines??
                /*if (evt.getSentence() instanceof BVESentence) {
                   BVESentence sen = (BVESentence) evt.getSentence();
                   if (sen.isFuelGuage()) {
                      sk.put(json, tanks_id_level , sen.getFuelRemaining(), "output");
                      sk.put(json, propulsion_id_fuelUsageRate , sen.getFuelUseRateUnitsPerHour(), "output");
                              
                      // map.put(Constants.FUEL_USED, sen.getFuelUsedOnTrip());
                      // sk.put(tempSignalKConstants.selfNode, SignalKConstants.tank_level, sen.getFuelRemaining(), "output");
                   }
                   if (sen.isEngineRpm()) {
                      sk.put(json, propulsion_id_rpm , sen.getEngineRpm(), "output");
                      // map.put(Constants.ENGINE_HOURS, sen.getEngineHours());
                      //sk.put(tempSignalKConstants.selfNode, SignalKConstants.propulsion_hours, sen.getEngineHours(), "output");
                      // map.put(Constants.ENGINE_MINUTES, sen.getEngineMinutes());
                      //sk.put(tempSignalKConstants.selfNode, SignalKConstants.propulsion_minutes, sen.getEngineMinutes(), "output");
                        
                   }
                   if (sen.isTempGuage()) {
                      sk.put(json, propulsion_id_engineTemperature , sen.getEngineTemp(), "output");
                      // map.put(Constants.ENGINE_VOLTS, sen.getVoltage());
                      //sk.put(tempSignalKConstants.selfNode, SignalKConstants.propulsion_engineVolts, sen.getVoltage(), "output");
                      // map.put(Constants.ENGINE_TEMP_HIGH_ALARM, sen.getHighTempAlarmValue());
                      // map.put(Constants.ENGINE_TEMP_LOW_ALARM, sen.getLowTempAlarmValue());
                        
                   }
                   if (sen.isPressureGuage()) {
                      sk.put(json, propulsion_id_oilPressure , sen.getPressure(), "output");
                      // map.put(Constants.ENGINE_PRESSURE_HIGH_ALARM, sen.getHighPressureAlarmValue());
                      // map.put(Constants.ENGINE_PRESSURE_LOW_ALARM, sen.getLowPressureAlarmValue());
                        
                   }
                        
                }*/
                if (evt.getSentence() instanceof DepthSentence) {
                    DepthSentence sen = (DepthSentence) evt.getSentence();
                    // in meters
                    sk.put(vessels_dot_self_dot + env_depth_belowTransducer, sen.getDepth(),
                            vessels_dot_self_dot + "sources.nmea.0183" + dot + sen.getSentenceId(), now);
                }
            } catch (DataNotAvailableException e) {
                logger.error(e.getMessage() + ":" + evt.getSentence().toSentence());
                //logger.debug(e.getMessage(),e);
            }

        }

        public void readingStopped() {
        }

        public void readingStarted() {
        }

        public void readingPaused() {
        }
    });
}

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

private double getTouchDegrees(float xPos, float yPos) {
    float x = xPos - mTranslateX;
    float y = yPos - mTranslateY;
    //invert the x-coord if we are rotating anti-clockwise
    x = (mClockwise) ? x : -x;//  w  w  w  .  j a v  a2s.c o  m
    // convert to arc Angle
    double angle = Math.toDegrees(Math.atan2(y, x) + (Math.PI / 2) - Math.toRadians(mRotation));
    if (angle < 0) {
        angle = 360 + angle;
    }
    angle -= mStartAngle;
    return angle;
}

From source file:DashboardInterface.LaunchGraph.java

@Override
public void update(String msg) {
    String[] dataPoint = msg.split(";");
    switch (dataPoint[0]) {
    case "STATE":
        //addStateMarker(Integer.parseInt(dataPoint[1]), curTime);
        if (dataPoint[1].equals("3")) {
            startTime = Double.parseDouble(dataPoint[2]);
            curTime = startTime;// ww  w  . j  a  va  2  s.  com
            running = true;
        }
        if (dataPoint[1].equals("1") && running) {
            running = false;
        }
        break;
    case "TENSION":
        curTime += Double.parseDouble(dataPoint[2]);
        if (running)
            addTensionValue(curTime - startTime, Float.parseFloat(dataPoint[1]));
        break;
    case "SPEED":
        if (running)
            addSpeedValue(curTime - startTime, Float.parseFloat(dataPoint[1]));
        break;
    case "OUT":
        float outLength = Float.parseFloat(dataPoint[1]);
        float height = (float) (outLength * Math.sin(Math.toRadians(currentAngle)));
        if (running)
            addHeightValue(curTime - startTime, height);
        break;
    case "ANGLE":
        currentAngle = Double.parseDouble(dataPoint[1]);
        break;
    }

}