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:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java

public static Dataset[] generateMinMaxRadialArray(int[] shape, QSpace qSpace, XAxis xAxis) {

    if (qSpace == null)
        return null;

    double[] beamCentre = qSpace.getDetectorProperties().getBeamCentreCoords();

    Dataset radialArrayMax = DatasetFactory.zeros(shape, Dataset.FLOAT64);
    Dataset radialArrayMin = DatasetFactory.zeros(shape, Dataset.FLOAT64);

    PositionIterator iter = radialArrayMax.getPositionIterator();
    int[] pos = iter.getPos();

    double[] vals = new double[4];
    double w = qSpace.getWavelength();
    while (iter.hasNext()) {

        //FIXME or not fix me, but I would expect centre to be +0.5, but this
        //clashes with much of the rest of DAWN

        if (xAxis != XAxis.PIXEL) {
            vals[0] = qSpace.qFromPixelPosition(pos[1], pos[0]).length();
            vals[1] = qSpace.qFromPixelPosition(pos[1] + 1, pos[0]).length();
            vals[2] = qSpace.qFromPixelPosition(pos[1], pos[0] + 1).length();
            vals[3] = qSpace.qFromPixelPosition(pos[1] + 1, pos[0] + 1).length();
        } else {//  w w  w .j av a 2  s.  c o m
            vals[0] = Math.hypot(pos[1] - beamCentre[0], pos[0] - beamCentre[1]);
            vals[1] = Math.hypot(pos[1] + 1 - beamCentre[0], pos[0] - beamCentre[1]);
            vals[2] = Math.hypot(pos[1] - beamCentre[0], pos[0] + 1 - beamCentre[1]);
            vals[3] = Math.hypot(pos[1] + 1 - beamCentre[0], pos[0] + 1 - beamCentre[1]);
        }

        Arrays.sort(vals);

        switch (xAxis) {
        case ANGLE:
            radialArrayMax.set(Math.toDegrees(Math.asin(vals[3] * w / (4 * Math.PI)) * 2), pos);
            radialArrayMin.set(Math.toDegrees(Math.asin(vals[0] * w / (4 * Math.PI)) * 2), pos);
            break;
        case Q:
        case PIXEL:
            radialArrayMax.set(vals[3], pos);
            radialArrayMin.set(vals[0], pos);
            break;
        case RESOLUTION:
            radialArrayMax.set((2 * Math.PI) / vals[0], pos);
            radialArrayMin.set((2 * Math.PI) / vals[3], pos);
            break;
        }
    }
    return new Dataset[] { radialArrayMin, radialArrayMax };
}

From source file:com.alvermont.terraj.planet.project.ConicalProjection.java

/**
 * Carry out the projection//  w  w  w .j  a va  2  s.  c o  m
 */
public void project() {
    setcolours();

    final int width = getParameters().getProjectionParameters().getWidth();
    final int height = getParameters().getProjectionParameters().getHeight();

    final double lat = getParameters().getProjectionParameters().getLatitudeRadians();
    final double lon = getParameters().getProjectionParameters().getLongitudeRadians();

    final double scale = getParameters().getProjectionParameters().getScale();

    final double hgrid = getParameters().getProjectionParameters().getHgrid();
    final double vgrid = getParameters().getProjectionParameters().getVgrid();

    final boolean doShade = getParameters().getProjectionParameters().isDoShade();

    cacheParameters();

    colours = new short[width][height];
    shades = new short[width][height];

    final double sla = Math.sin(lat);
    final double cla = Math.cos(lat);
    final double slo = Math.sin(lon);
    final double clo = Math.cos(lon);

    depth = (3 * ((int) (log2(scale * height)))) + 6;

    double k1;
    double c;
    double y2;
    double x;
    double y;
    double zz;
    double x1;
    double y1;
    double z1;
    double theta1;
    double theta2;
    double ymin;
    double ymax;
    double cos2;
    int i;
    int j;

    ymin = 2.0;
    ymax = -2.0;

    if (lat > 0) {
        k1 = 1.0 / Math.sin(lat);
        c = k1 * k1;

        y2 = Math.sqrt((c * (1.0 - Math.sin(lat / k1))) / (1.0 + Math.sin(lat / k1)));

        progress.progressStart(height, "Generating Terrain");

        for (j = 0; j < height; ++j) {
            progress.progressStep(j);

            for (i = 0; i < width; ++i) {
                x = ((2.0 * i) - width) / height / scale;
                y = (((2.0 * j) - height) / height / scale) + y2;
                zz = (x * x) + (y * y);

                if (zz == 0.0) {
                    theta1 = 0.0;
                } else {
                    theta1 = k1 * Math.atan2(x, y);
                }

                if ((theta1 < -Math.PI) || (theta1 > Math.PI)) {
                    colours[i][j] = backgroundColour;

                    if (doShade) {
                        shades[i][j] = 255;
                    }
                } else {
                    /* theta1 is longitude */
                    theta1 += (lon - (0.5 * Math.PI));
                    theta2 = k1 * Math.asin((zz - c) / (zz + c));

                    /* theta2 is latitude */
                    if ((theta2 > (0.5 * Math.PI)) || (theta2 < (-0.5 * Math.PI))) {
                        colours[i][j] = backgroundColour;

                        if (doShade) {
                            shades[i][j] = 255;
                        }
                    } else {
                        cos2 = Math.cos(theta2);
                        y = Math.sin(theta2);

                        if (y < ymin) {
                            ymin = y;
                        }

                        if (y > ymax) {
                            ymax = y;
                        }

                        colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2);

                        if (doShade) {
                            shades[i][j] = shade;
                        }
                    }
                }
            }
        }

        progress.progressComplete("Terrain Generated");

        if (hgrid != 0.0) {
            /* draw horizontal gridlines */
            for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid)
                ;

            for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) {
                y = Math.sin(Math.toRadians(theta1));

                if ((ymin <= y) && (y <= ymax)) {
                    zz = Math.sqrt((c * (1.0 + Math.sin(Math.toRadians(theta1) / k1)))
                            / (1.0 - Math.sin(Math.toRadians(theta1) / k1)));

                    for (theta2 = -Math.PI + lon; theta2 < (Math.PI + lon); theta2 += (0.5 / width / scale)) {
                        z1 = theta2 - lon;
                        x1 = zz * Math.sin(z1 / k1);
                        y1 = zz * Math.cos(z1 / k1);

                        i = (int) (0.5 * ((height * scale * x1) + width));
                        j = (int) (0.5 * ((height * scale * (y1 - y2)) + height));

                        if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) {
                            colours[i][j] = BLACK;
                        }
                    }
                }
            }
        }

        if (vgrid != 0.0) {
            /* draw vertical gridlines */
            for (theta1 = -0.5 * Math.PI; theta1 < (0.5 * Math.PI); theta1 += (0.5 / width / scale)) {
                y = Math.sin(theta1);

                if ((ymin <= y) && (y <= ymax)) {
                    zz = Math.sqrt((c * (1.0 + Math.sin(theta1 / k1))) / (1.0 - Math.sin(theta1 / k1)));

                    for (theta2 = 0.0; theta2 > (-180.0 + Math.toDegrees(lon)); theta2 -= vgrid)
                        ;

                    for (theta2 = theta2; theta2 < (180.0 + Math.toDegrees(lon)); theta2 += vgrid) {
                        z1 = Math.toRadians(theta2) - lon;
                        x1 = zz * Math.sin(z1 / k1);
                        y1 = zz * Math.cos(z1 / k1);

                        i = (int) (0.5 * ((height * scale * x1) + width));
                        j = (int) (0.5 * ((height * scale * (y1 - y2)) + height));

                        if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) {
                            colours[i][j] = BLACK;
                        }
                    }
                }
            }
        }
    } else {
        k1 = 1.0 / Math.sin(lat);
        c = k1 * k1;
        y2 = Math.sqrt((c * (1.0 - Math.sin(lat / k1))) / (1.0 + Math.sin(lat / k1)));

        progress.progressStart(height, "Generating Terrain");

        for (j = 0; j < height; ++j) {
            progress.progressStep(j);

            for (i = 0; i < width; ++i) {
                x = ((2.0 * i) - width) / height / scale;
                y = (((2.0 * j) - height) / height / scale) - y2;
                zz = (x * x) + (y * y);

                if (zz == 0.0) {
                    theta1 = 0.0;
                } else {
                    theta1 = -k1 * Math.atan2(x, -y);
                }

                if ((theta1 < -Math.PI) || (theta1 > Math.PI)) {
                    colours[i][j] = backgroundColour;

                    if (doShade) {
                        shades[i][j] = 255;
                    }
                } else {
                    /* theta1 is longitude */
                    theta1 += (lon - (0.5 * Math.PI));
                    theta2 = k1 * Math.asin((zz - c) / (zz + c));

                    /* theta2 is latitude */
                    if ((theta2 > (0.5 * Math.PI)) || (theta2 < (-0.5 * Math.PI))) {
                        colours[i][j] = backgroundColour;

                        if (doShade) {
                            shades[i][j] = 255;
                        }
                    } else {
                        cos2 = Math.cos(theta2);
                        y = Math.sin(theta2);

                        if (y < ymin) {
                            ymin = y;
                        }

                        if (y > ymax) {
                            ymax = y;
                        }

                        colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2);

                        if (doShade) {
                            shades[i][j] = shade;
                        }
                    }
                }
            }
        }

        progress.progressComplete("Terrain Generated");

        if (hgrid != 0.0) {
            /* draw horizontal gridlines */
            for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid)
                ;

            for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) {
                y = Math.sin(Math.toRadians(theta1));

                if ((ymin <= y) && (y <= ymax)) {
                    zz = Math.sqrt((c * (1.0 + Math.sin(Math.toRadians(theta1) / k1)))
                            / (1.0 - Math.sin(Math.toRadians(theta1) / k1)));

                    for (theta2 = -Math.PI + lon; theta2 < (Math.PI + lon); theta2 += (0.5 / width / scale)) {
                        z1 = theta2 - lon;
                        x1 = -zz * Math.sin(z1 / k1);
                        y1 = -zz * Math.cos(z1 / k1);

                        i = (int) (0.5 * ((height * scale * x1) + width));
                        j = (int) (0.5 * ((height * scale * (y1 + y2)) + height));

                        if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) {
                            colours[i][j] = BLACK;
                        }
                    }
                }
            }
        }

        if (vgrid != 0.0) {
            /* draw vertical gridlines */
            for (theta1 = -0.5 * Math.PI; theta1 < (0.5 * Math.PI); theta1 += (0.5 / width / scale)) {
                y = Math.sin(theta1);

                if ((ymin <= y) && (y <= ymax)) {
                    zz = Math.sqrt((c * (1.0 + Math.sin(theta1 / k1))) / (1.0 - Math.sin(theta1 / k1)));

                    for (theta2 = 0.0; theta2 > (-180.0 + Math.toDegrees(lon)); theta2 -= vgrid)
                        ;

                    for (theta2 = theta2; theta2 < (180.0 + Math.toDegrees(lon)); theta2 += vgrid) {
                        z1 = Math.toRadians(theta2) - lon;
                        x1 = -zz * Math.sin(z1 / k1);
                        y1 = -zz * Math.cos(z1 / k1);

                        i = (int) (0.5 * ((height * scale * x1) + width));
                        j = (int) (0.5 * ((height * scale * (y1 + y2)) + height));

                        if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) {
                            colours[i][j] = BLACK;
                        }
                    }
                }
            }
        }
    }

    if (doShade) {
        smoothshades();
    }

    doOutlining();
}

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

public static void rotateWithOpenGLLookAt(Vector3D cameraVector, Vector3D parentVector, GVRSceneObject object) {
    Vector3D globalUpVector = new Vector3D(0, 1, 0);
    Vector3D lookVector = parentVector.normalize();
    Vector3D rightVector = lookVector.crossProduct(globalUpVector);
    Vector3D upVector = rightVector.crossProduct(lookVector);
    Vector3D zAxis = cameraVector.subtract(parentVector).normalize();
    // Vector3D xAxis = upVector.crossProduct(zAxis).normalize();
    Vector3D xAxis = zAxis.crossProduct(upVector).normalize();
    Vector3D yAxis = xAxis.crossProduct(zAxis).normalize();
    // Vector3D yAxis = xAxis.crossProduct(zAxis).normalize();
    zAxis = zAxis.scalarMultiply(-1.f);//  ww w  .  j  a v  a 2 s.c  om

    float angle = (float) Vector3D.angle(parentVector, cameraVector);
    angle = (float) Math.toDegrees(angle);

    object.getTransform().rotateByAxis(angle, (float) xAxis.getX(), (float) xAxis.getY(), (float) xAxis.getZ());
    object.getTransform().rotateByAxis(angle, (float) yAxis.getX(), (float) yAxis.getY(), (float) yAxis.getZ());
    object.getTransform().rotateByAxis(angle, (float) zAxis.getX(), (float) zAxis.getY(), (float) zAxis.getZ());
}

From source file:org.interpss.mapper.bean.aclf.BaseAclfNet2BeanMapper.java

private static void mapPsXfrData(PSXfrPControl tap, PsXfrTapControlBean tb) {
    tb.controlOnFromSide = tap.isControlOnFromSide();
    tb.controlType = tap.getFlowControlType() == AdjControlType.POINT_CONTROL ? TapControlTypeBean.Point_Control
            : TapControlTypeBean.Range_Control;
    tb.desiredControlTarget = tap.getPSpecified();
    tb.flowFrom2To = tap.isFlowFrom2To();
    if (tap.getControlRange() != null) {
        tb.lowerLimit = tap.getControlRange().getMin();
        tb.upperLimit = tap.getControlRange().getMax();
    }//ww w  .  j  av  a2  s .  co m
    if (tap.getAngLimit() != null) {
        tb.maxAngle = Math.toDegrees(tap.getAngLimit().getMax());
        tb.minAngle = Math.toDegrees(tap.getAngLimit().getMin());
    }
    if (tap.getControlLimit() != null) {
        tb.maxTap = tap.getControlLimit().getMax();
        tb.minTap = tap.getControlLimit().getMin();
    }
    tb.measuredOnFromSide = tap.isMeteredOnFromSide();
    tb.status = tap.isStatus() == true ? 1 : 0;
}

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:sundroid.code.SundroidActivity.java

/** Called when the activity is first created. ***/
@Override/*from  ww w  .  j a  va2s . co 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:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java

private static Dataset generateRadialArray(int[] shape, QSpace qSpace, XAxis xAxis, boolean radians) {

    if (qSpace == null)
        return null;

    double[] beamCentre = qSpace.getDetectorProperties().getBeamCentreCoords();

    Dataset ra = DatasetFactory.zeros(shape, Dataset.FLOAT64);

    PositionIterator iter = ra.getPositionIterator();
    int[] pos = iter.getPos();

    while (iter.hasNext()) {

        Vector3d q;// w  w  w  .  j  a  va2s .  c o  m
        double value = 0;
        //FIXME or not fix me, but I would expect centre to be +0.5, but this
        //clashes with much of the rest of DAWN
        q = qSpace.qFromPixelPosition(pos[1] + 0.5, pos[0] + 0.5);

        switch (xAxis) {
        case ANGLE:
            value = qSpace.scatteringAngle(q);
            if (!radians)
                value = Math.toDegrees(value);
            break;
        case Q:
            value = q.length();
            break;
        case RESOLUTION:
            value = (2 * Math.PI) / q.length();
            break;
        case PIXEL:
            value = Math.hypot(pos[1] - beamCentre[0] + 0.5, pos[0] - beamCentre[1] + 0.5);
            break;
        }
        ra.set(value, pos);
    }

    return ra;
}

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  w  w w .  j av a2 s  .co  m*/
            deltaLon = (2.0 * Math.PI + deltaLon);
        }
    }
    double bearing = (Math.toDegrees(Math.atan2(deltaLon, deltaPhi)) + 360.0) % 360.0;
    return bearing;
}

From source file:net.line2soft.preambul.controllers.SlippyMapListener.java

@Override
public void onSensorChanged(SensorEvent event) {
    CompassView cp = (CompassView) activity.findViewById(R.id.compass);
    CompassView cpBig = (CompassView) activity.findViewById(R.id.compassBig);
    switch (event.sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        System.arraycopy(event.values, 0, mGravity, 0, 3);
        break;//  w w w  . java 2 s  . c  o  m
    case Sensor.TYPE_MAGNETIC_FIELD:
        System.arraycopy(event.values, 0, mMagnetic, 0, 3);
        break;
    default:
        return;
    }
    if (SensorManager.getRotationMatrix(mRotationM, null, mGravity, mMagnetic)) {
        SensorManager.remapCoordinateSystem(mRotationM, SensorManager.AXIS_X, SensorManager.AXIS_Z,
                mRemapedRotationM);
        SensorManager.getOrientation(mRemapedRotationM, mOrientation);
        int mAzimuth = (int) Math.round((Math.toDegrees(mOrientation[0])) * 2) / 2;
        cp.updateDirection(mAzimuth);
        cpBig.updateDirection(mAzimuth);
    }
}

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);
    lon = Math.toDegrees(lon);//  w  w  w .  j a  va  2 s.c om

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

    return destination;
}