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.evgenyvyaz.cinaytaren.activity.FaceTrackerActivity.java

public double getAngle(double startLat, double startLng, double endLat, double endLng) throws JSONException {
    double longitude1 = startLng;
    double longitude2 = endLng;
    double latitude1 = Math.toRadians(startLat);
    double latitude2 = Math.toRadians(endLat);
    double longDiff = Math.toRadians(longitude2 - longitude1);
    double y = Math.sin(longDiff) * Math.cos(latitude2);
    double x = Math.cos(latitude1) * Math.sin(latitude2)
            - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff);
    return (Math.toDegrees(Math.atan2(y, x)) + 360) % 360;
}

From source file:uk.ac.susx.tag.method51.twitter.geocoding.geonames.GeonamesSPARQLLocationDatabase.java

public static double euclideanDistance(double[] p1, double[] p2) {

    double EARTH_RADIUS = 6371;

    double lat1 = p1[0];
    double lon1 = p1[1];

    double lat2 = p2[0];
    double lon2 = p2[1];

    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lon2 - lon1);
    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 x = (lon2 - lon1) * Math.cos((lat1 + lat2) / 2);

    double y = (lat2 - lat1);

    //double dist = Math.sqrt( x*x + y*y ) * EARTH_RADIUS;

    double dist = c * EARTH_RADIUS;
    return dist;/*from w  ww.  java  2 s . c  om*/
}

From source file:mrmc.chart.ROCCurvePlot.java

/**
 * Creates an ROC curve that averages together the scores for all readers in
 * the diagonal direction//from   w w  w .  j  av a  2s  .  co m
 * 
 * @param treeMap Mapping of readers to points defining a curve
 * @return Series containing the ROC curve points
 */
private XYSeries generateDiagonalROC(TreeMap<String, TreeSet<XYPair>> treeMap) {
    XYSeries diagAvg = new XYSeries("Diagonal Average", false);
    TreeMap<String, TreeSet<XYPair>> rotatedData = new TreeMap<String, TreeSet<XYPair>>();

    // rotate all points in data 45 degrees clockwise about origin
    for (String r : treeMap.keySet()) {
        rotatedData.put(r, new TreeSet<XYPair>());
        for (XYPair point : treeMap.get(r)) {
            double x2 = (point.x + point.y) / Math.sqrt(2.0);
            double y2 = (point.y - point.x) / Math.sqrt(2.0);
            rotatedData.get(r).add(new XYPair(x2, y2));
        }
    }

    // generate linear interpolation with new points
    ArrayList<InterpolatedLine> rotatedLines = new ArrayList<InterpolatedLine>();
    for (String r : rotatedData.keySet()) {
        rotatedLines.add(new InterpolatedLine(rotatedData.get(r)));
    }

    // take vertical sample averages from x = 0 to x = 1
    for (double i = 0; i <= Math.sqrt(2); i += 0.01) {
        double avg = 0;
        int counter = 0;
        for (InterpolatedLine line : rotatedLines) {
            avg += line.getYatDiag(i);
            counter++;
        }

        // rotate points back 45 degrees counterclockwise
        double x1 = i;
        double y1 = (avg / (double) counter);
        double x2 = (x1 * Math.cos(Math.toRadians(45))) - (y1 * Math.sin(Math.toRadians(45)));
        double y2 = (x1 * Math.sin(Math.toRadians(45))) + (y1 * Math.cos(Math.toRadians(45)));
        diagAvg.add(x2, y2);
    }

    diagAvg.add(1, 1);
    return diagAvg;
}

From source file:Matrix.java

/**
 * Laterally rotate a matrix (lateral rotation is around a (0, 1, 0) axis).
 * @param angle the angle of the rotation
 * @param m the matrix to rotate//from   ww w  .  j  a v  a 2 s . c om
 * @return the resulting matrix
 */
public static float[] matrixRotateLateral(float[] m, float angle) {
    if (angle == 0f)
        return matrixIdentity();
    angle = (float) Math.toRadians(angle);
    float cos = (float) java.lang.Math.cos(angle);
    float sin = (float) java.lang.Math.sin(angle);
    float r[] = new float[16];
    r[0] = m[0] * cos + m[2] * sin;
    r[4] = m[4] * cos + m[6] * sin;
    r[8] = m[8] * cos + m[10] * sin;
    r[12] = m[12] * cos + m[14] * sin;
    r[1] = m[1];
    r[5] = m[5];
    r[9] = m[9];
    r[13] = m[13];
    r[2] = -m[0] * sin + m[2] * cos;
    r[6] = -m[4] * sin + m[6] * cos;
    r[10] = -m[8] * sin + m[10] * cos;
    r[14] = -m[12] * sin + m[14] * cos;
    r[3] = 0;
    r[7] = 0;
    r[11] = 0;
    r[15] = 1;
    return r;
    //    return matrixMultiply(matrixRotateLateral(angle), m);
}

From source file:sundroid.code.SundroidActivity.java

/** Called when the activity is first created. ***/
@Override/*from   www . j a v a2  s .c  o  m*/
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    this.chk_usecelsius = (CheckBox) findViewById(R.id.chk_usecelsius);
    Button cmd_submit = (Button) findViewById(R.id.cmd_submit);

    cmd_submit.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            try {

                ///////////////// Code to get weather conditions for entered place ///////////////////////////////////////////////////
                String cityParamString = ((EditText) findViewById(R.id.edit_input)).getText().toString();
                String queryString = "https://www.google.com/ig/api?weather=" + cityParamString;
                queryString = queryString.replace("#", "");

                /* Parsing the xml file*/
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();

                GoogleWeatherHandler gwh = new GoogleWeatherHandler();
                xr.setContentHandler(gwh);

                HttpClient httpclient = new DefaultHttpClient();
                HttpGet httpget = new HttpGet(queryString.replace(" ", "%20"));
                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                String responseBody = httpclient.execute(httpget, responseHandler);
                ByteArrayInputStream is = new ByteArrayInputStream(responseBody.getBytes());
                xr.parse(new InputSource(is));
                Log.d("Sundroid", "parse complete");

                WeatherSet ws = gwh.getWeatherSet();

                newupdateWeatherInfoView(R.id.weather_today, ws.getWeatherCurrentCondition(),
                        " " + cityParamString, "");

                ///////////////// Code to get weather conditions for entered place ends /////////////////////////////////////////////////// 

                ///////////////// Code to get latitude and longitude using zipcode starts ///////////////////////////////////////////////////

                String latlng_querystring = "http://maps.googleapis.com/maps/api/geocode/xml?address="
                        + cityParamString.replace(" ", "%20") + "&sensor=false";
                URL url_latlng = new URL(latlng_querystring);
                spf = SAXParserFactory.newInstance();
                sp = spf.newSAXParser();

                xr = sp.getXMLReader();
                xmlhandler_latlong xll = new xmlhandler_latlong();
                xr.setContentHandler(xll);
                xr.parse(new InputSource(url_latlng.openStream()));

                Latitude_longitude ll = xll.getLatlng_resultset();
                double selectedLat = ll.getLat_lng_pair().getLat();
                double selectedLng = ll.getLat_lng_pair().getLon();

                ///////////////// Code to get latitude and longitude using zipcode ends ///////////////////////////////////////////////////

                ///////////////// Code to get miles from text box & convert to meters for passing into the api link////////////////////////
                EditText edt = (EditText) findViewById(R.id.edit_miles);
                float miles = Float.valueOf(edt.getText().toString());
                float meters = (float) (miles * 1609.344);

                ///////////////// Code to get miles from text box & convert to meters for passing into the api link ends /////////////////

                ///////////////// Code to pass lat,long and radius and get destinations from places api starts////////// /////////////////
                URL queryString_1 = new URL("https://maps.googleapis.com/maps/api/place/search/xml?location="
                        + Double.toString(selectedLat) + "," + Double.toString(selectedLng) + "&radius="
                        + Float.toString(meters)
                        + "&types=park|types=aquarium|types=point_of_interest|types=establishment|types=museum&sensor=false&key=AIzaSyDmP0SB1SDMkAJ1ebxowsOjpAyeyiwHKQU");
                spf = SAXParserFactory.newInstance();
                sp = spf.newSAXParser();
                xr = sp.getXMLReader();
                xmlhandler_places xhp = new xmlhandler_places();
                xr.setContentHandler(xhp);
                xr.parse(new InputSource(queryString_1.openStream()));
                int arraysize = xhp.getVicinity_List().size();
                String[] place = new String[25];
                String[] place_name = new String[25];
                Double[] lat_pt = new Double[25];
                Double[] lng_pt = new Double[25];
                int i;
                //Getting name and vicinity tags from the xml file//
                for (i = 0; i < arraysize; i++) {
                    place[i] = xhp.getVicinity_List().get(i);
                    place_name[i] = xhp.getPlacename_List().get(i);
                    lat_pt[i] = xhp.getLatlist().get(i);
                    lng_pt[i] = xhp.getLonglist().get(i);
                    System.out.println("long -" + lng_pt[i]);
                    place[i] = place[i].replace("#", "");

                }

                ///////////////// Code to pass lat,long and radius and get destinations from places api ends////////// /////////////////

                //////////////////////while loop for getting top 5 from the array////////////////////////////////////////////////

                int count = 0;
                int while_ctr = 0;
                String str_weathercondition;
                str_weathercondition = "";
                WeatherCurrentCondition reftemp;
                //Places to visit if none of places in the given radius are sunny/clear/partly cloudy
                String[] rainy_place = { "Indoor Mall", "Watch a Movie", "Go to a Restaurant", "Shopping!" };
                double theDistance = 0;
                String str_dist = "";
                while (count < 5) {
                    //Checking if xml vicinity value is empty
                    while (place[while_ctr] == null || place[while_ctr].length() < 2) {
                        while_ctr = while_ctr + 1;
                    }
                    //First search for places that are sunny or clear 
                    if (while_ctr < i - 1) {
                        queryString = "https://www.google.com/ig/api?weather=" + place[while_ctr];
                        System.out.println("In while loop - " + queryString);
                        theDistance = (Math.sin(Math.toRadians(selectedLat))
                                * Math.sin(Math.toRadians(lat_pt[while_ctr]))
                                + Math.cos(Math.toRadians(selectedLat))
                                        * Math.cos(Math.toRadians(lat_pt[while_ctr]))
                                        * Math.cos(Math.toRadians(selectedLng - lng_pt[while_ctr])));
                        str_dist = new Double((Math.toDegrees(Math.acos(theDistance))) * 69.09).intValue()
                                + " miles";
                        System.out.println(str_dist);
                        spf = SAXParserFactory.newInstance();
                        sp = spf.newSAXParser();

                        xr = sp.getXMLReader();

                        gwh = new GoogleWeatherHandler();
                        xr.setContentHandler(gwh);
                        httpclient = new DefaultHttpClient();
                        httpget = new HttpGet(queryString.replace(" ", "%20"));
                        responseHandler = new BasicResponseHandler();
                        responseBody = httpclient.execute(httpget, responseHandler);
                        is = new ByteArrayInputStream(responseBody.getBytes());
                        xr.parse(new InputSource(is));
                        if (gwh.isIn_error_information()) {
                            System.out.println("Error Info flag set");
                        } else {
                            ws = gwh.getWeatherSet();

                            reftemp = ws.getWeatherCurrentCondition();
                            str_weathercondition = reftemp.getCondition();

                            //         Check if the condition is sunny or partly cloudy
                            if (str_weathercondition.equals("Sunny")
                                    || str_weathercondition.equals("Mostly Sunny")
                                    || str_weathercondition.equals("Clear")) {
                                System.out.println("Sunny Loop");

                                //  Increment the count 
                                ++count;

                                //   Disply the place on the widget 
                                if (count == 1) {
                                    newupdateWeatherInfoView(R.id.weather_1, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else if (count == 2) {
                                    newupdateWeatherInfoView(R.id.weather_2, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else if (count == 3) {
                                    newupdateWeatherInfoView(R.id.weather_3, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else if (count == 4) {
                                    newupdateWeatherInfoView(R.id.weather_4, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else if (count == 5) {
                                    newupdateWeatherInfoView(R.id.weather_5, reftemp, place_name[while_ctr],
                                            str_dist);
                                } else {
                                }
                            }
                        }
                    }

                    //  If Five sunny places not found then search for partly cloudy places 

                    else if (while_ctr >= i && while_ctr < i * 2) {
                        queryString = "https://www.google.com/ig/api?weather=" + place[while_ctr - i];
                        queryString = queryString.replace("  ", " ");

                        spf = SAXParserFactory.newInstance();
                        sp = spf.newSAXParser();

                        // Get the XMLReader of the SAXParser we created. 
                        xr = sp.getXMLReader();

                        gwh = new GoogleWeatherHandler();
                        xr.setContentHandler(gwh);

                        // Use HTTPClient to deal with the URL  
                        httpclient = new DefaultHttpClient();
                        httpget = new HttpGet(queryString.replace(" ", "%20"));
                        responseHandler = new BasicResponseHandler();
                        responseBody = httpclient.execute(httpget, responseHandler);
                        is = new ByteArrayInputStream(responseBody.getBytes());
                        xr.parse(new InputSource(is));
                        Log.d(DEBUG_TAG, "parse complete");

                        if (gwh.isIn_error_information()) {
                        } else {
                            ws = gwh.getWeatherSet();
                            reftemp = ws.getWeatherCurrentCondition();
                            str_weathercondition = reftemp.getCondition();

                            //    Check if the condition is sunny or partly cloudy
                            if (str_weathercondition.equals("Partly Cloudy")) {

                                count = count + 1;

                                //  Display the place 
                                if (count == 1) {
                                    newupdateWeatherInfoView(R.id.weather_1, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else if (count == 2) {
                                    newupdateWeatherInfoView(R.id.weather_2, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else if (count == 3) {
                                    newupdateWeatherInfoView(R.id.weather_3, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else if (count == 4) {
                                    newupdateWeatherInfoView(R.id.weather_4, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else if (count == 5) {
                                    newupdateWeatherInfoView(R.id.weather_5, reftemp, place_name[while_ctr - i],
                                            str_dist);
                                } else {
                                }
                            }
                        }
                    }
                    ////////////////////////////////  Give suggestions for a rainy day 
                    else {
                        queryString = "https://www.google.com/ig/api?weather=" + cityParamString;
                        queryString = queryString.replace("#", "");

                        spf = SAXParserFactory.newInstance();
                        sp = spf.newSAXParser();

                        // Get the XMLReader of the SAXParser we created. 
                        xr = sp.getXMLReader();
                        gwh = new GoogleWeatherHandler();
                        xr.setContentHandler(gwh);

                        httpclient = new DefaultHttpClient();

                        httpget = new HttpGet(queryString.replace(" ", "%20"));
                        // create a response handler 
                        responseHandler = new BasicResponseHandler();
                        responseBody = httpclient.execute(httpget, responseHandler);
                        is = new ByteArrayInputStream(responseBody.getBytes());
                        xr.parse(new InputSource(is));
                        if (gwh.isIn_error_information()) {
                        }

                        else {
                            ws = gwh.getWeatherSet();

                            reftemp = ws.getWeatherCurrentCondition();
                            str_weathercondition = reftemp.getCondition();

                            if (count == 0) {
                                newupdateWeatherInfoView(R.id.weather_1, reftemp, rainy_place[0], "");
                                newupdateWeatherInfoView(R.id.weather_2, reftemp, rainy_place[1], "");
                                newupdateWeatherInfoView(R.id.weather_3, reftemp, rainy_place[2], "");
                                newupdateWeatherInfoView(R.id.weather_4, reftemp, rainy_place[3], "");
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[1], "");
                            } else if (count == 1) {
                                newupdateWeatherInfoView(R.id.weather_2, reftemp, rainy_place[1], "");
                                newupdateWeatherInfoView(R.id.weather_3, reftemp, rainy_place[2], "");
                                newupdateWeatherInfoView(R.id.weather_4, reftemp, rainy_place[3], "");
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[0], "");
                            } else if (count == 2) {
                                newupdateWeatherInfoView(R.id.weather_3, reftemp, rainy_place[2], "");
                                newupdateWeatherInfoView(R.id.weather_4, reftemp, rainy_place[0], "");
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[1], "");
                            } else if (count == 3) {
                                newupdateWeatherInfoView(R.id.weather_4, reftemp, rainy_place[0], "");
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[1], "");
                            } else if (count == 4) {
                                newupdateWeatherInfoView(R.id.weather_5, reftemp, rainy_place[1], "");
                            } else {
                            }
                            count = 5;
                        }
                        count = 5;
                    }
                    while_ctr++;
                }

                /////////////Closing the soft keypad////////////////
                InputMethodManager iMethodMgr = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                iMethodMgr.hideSoftInputFromWindow(edt.getWindowToken(), 0);

            } catch (Exception e) {
                resetWeatherInfoViews();
                Log.e(DEBUG_TAG, "WeatherQueryError", e);
            }
        }
    });
}

From source file:com.congxiaoyao.xber_admin.widget.MaterialProgressDrawable.java

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

From source file:com.bigkoo.svprogresshud.view.MaterialProgressDrawable.java

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

From source file:nl.b3p.viewer.stripes.OntbrandingsActionBean.java

private void createSafetyDistances(JSONArray gs, Geometry audience, Geometry ignition, Geometry safetyZone)
        throws TransformException {
    // Create safetydistances
    // 1. afstand tussen rand afsteekzone en safetyzone: loodrecht op publiek
    Point audienceCentroid = audience.getCentroid();
    Point ignitionCentroid = ignition.getCentroid();
    Coordinate[] coords = { audienceCentroid.getCoordinate(), ignitionCentroid.getCoordinate() };
    LineString audience2ignition = gf.createLineString(coords);

    double dx = ignitionCentroid.getX() - audienceCentroid.getX();
    double dy = ignitionCentroid.getY() - audienceCentroid.getY();
    double length = audience2ignition.getLength();
    double ratioX = (dx / length);
    double ratioY = (dy / length);
    double fanX = ratioX * 1000;
    double fanY = ratioY * 1000;

    Point eindLoodlijn = gf/*from  w  ww  .  ja  v  a2s.c o  m*/
            .createPoint(new Coordinate(ignitionCentroid.getX() + fanX, ignitionCentroid.getY() + fanY));
    Coordinate ancorPoint = ignitionCentroid.getCoordinate();

    double angleRad = Math.toRadians(90);
    AffineTransform affineTransform = AffineTransform.getRotateInstance(angleRad, ancorPoint.x, ancorPoint.y);
    MathTransform mathTransform = new AffineTransform2D(affineTransform);

    Geometry rotatedPoint = JTS.transform(eindLoodlijn, mathTransform);
    Coordinate[] loodLijnCoords = { ignitionCentroid.getCoordinate(), rotatedPoint.getCoordinate() };
    LineString loodLijn = gf.createLineString(loodLijnCoords);
    Geometry cutoffLoodlijn = loodLijn.intersection(safetyZone);
    cutoffLoodlijn = cutoffLoodlijn.difference(ignition);
    gs.put(createFeature(cutoffLoodlijn, "safetyDistance", (int) cutoffLoodlijn.getLength() + " m"));

    // 2. afstand tussen rand afsteekzone en safetyzone: haaks op publiek

    Coordinate[] endContinuousLine = { ignitionCentroid.getCoordinate(), eindLoodlijn.getCoordinate() };
    LineString continuousLine = gf.createLineString(endContinuousLine);
    Geometry cutoffContLine = continuousLine.intersection(safetyZone);
    cutoffContLine = cutoffContLine.difference(ignition);

    gs.put(createFeature(cutoffContLine, "safetyDistance", (int) cutoffContLine.getLength() + " m"));
}

From source file:eu.hansolo.tilesfx.tools.Location.java

public double calcBearingInDegree(final double LAT_1, final double LON_1, final double LAT_2,
        final double LON_2) {
    double lat1 = Math.toRadians(LAT_1);
    double lon1 = Math.toRadians(LON_1);
    double lat2 = Math.toRadians(LAT_2);
    double lon2 = Math.toRadians(LON_2);
    double deltaLon = lon2 - lon1;
    double deltaPhi = Math.log(Math.tan(lat2 * 0.5 + Math.PI * 0.25) / Math.tan(lat1 * 0.5 + Math.PI * 0.25));
    if (Math.abs(deltaLon) > Math.PI) {
        if (deltaLon > 0) {
            deltaLon = -(2.0 * Math.PI - deltaLon);
        } else {//from ww w .  j  av a2 s  .  c o  m
            deltaLon = (2.0 * Math.PI + deltaLon);
        }
    }
    double bearing = (Math.toDegrees(Math.atan2(deltaLon, deltaPhi)) + 360.0) % 360.0;
    return bearing;
}

From source file:es.emergya.geo.util.Lambert.java

/**
 * Translate latitude/longitude in WGS84, (ellipsoid GRS80) to Lambert
 * geographic, (ellipsoid Clark)/*from w  ww  .  j  a v  a  2 s . c o  m*/
 */
private LatLon GRS802Clark(LatLon wgs) {
    double lat = Math.toRadians(wgs.lat()); // degree to radian
    double lon = Math.toRadians(wgs.lon());
    // WGS84 geographic => WGS84 cartesian
    double N = Ellipsoid.GRS80.a / (Math.sqrt(1.0 - Ellipsoid.GRS80.e2 * Math.sin(lat) * Math.sin(lat)));
    double X = (N/* +height */) * Math.cos(lat) * Math.cos(lon);
    double Y = (N/* +height */) * Math.cos(lat) * Math.sin(lon);
    double Z = (N * (1.0 - Ellipsoid.GRS80.e2)/* + height */) * Math.sin(lat);
    // WGS84 => Lambert ellipsoide similarity
    X += 168.0;
    Y += 60.0;
    Z += -320.0;
    // Lambert cartesian => Lambert geographic
    return Geographic(X, Y, Z, Ellipsoid.clarke);
}