Example usage for java.lang Math acos

List of usage examples for java.lang Math acos

Introduction

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

Prototype

public static double acos(double a) 

Source Link

Document

Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.

Usage

From source file:Vector3f.java

/**
 * Calculates the angle between this vector and the given vector.
 * /*from www .j a  v a2 s. c o m*/
 * @param v the vector to be used for calculation
 * @return the angle between this and v
 */
public float angle(final Vector3f v) {
    float dls = dot(v) / (this.length() * v.length());
    if (dls < -1.0f)
        dls = -1.0f;
    else if (dls > 1.0f)
        dls = 1.0f;
    return (float) Math.acos(dls);
}

From source file:Quaternion.java

public static final Quaternion orientation(Vector3 unit) {
    Vector3 i = Vector3.i();

    double theta = Math.acos(i.dot(unit));
    Vector3 v = i.cross(unit);/*from w  ww  .  j a v  a  2 s . c om*/

    System.out.println("rotation axis is");
    System.out.println(v);
    System.out.println("and angle is " + theta);

    return Quaternion.rotation(theta, v);
}

From source file:Quaternion.java

/**
 * Return an interpolated quaternion, based on this quaternion, the given quaternion q2, and the
 * parameter t. /*www . j  a v a  2s . com*/
 * @param q2 quaternion to interpolate against
 * @param t interpolation parameter in [0,1]
 * @return
 */
public final Quaternion interpolate(Quaternion q2, double t) {
    //seems to be slerp interpolation of quaterions [02 03 2008]
    Quaternion qa = this;
    Quaternion qb = q2;
    //      qa sin((1-t) theta) + qb sin( t theta )
    //qm = ---------------------------------------  0<t<1 
    //                    sin theta
    //       
    //  theta = arccos( qa dot qb )
    double theta = Math.acos(qa.dot(qb));

    if (Math.abs(theta) < 1e-7) {
        return this;
    }

    return qa.multiply(Math.sin((1 - t) * theta)).add(qb.multiply(Math.sin(t * theta)))
            .multiply(1 / Math.sin(theta));
}

From source file:ExDirectionalLight.java

private Group buildArrows() {
    // Create a transform group surrounding the arrows.
    // Enable writing of its transform.
    arrowDirectionTransformGroup = new TransformGroup();
    arrowDirectionTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Create a group of arrows and add the group to the
    // transform group. The arrows point in the +X direction.
    AnnotationArrowGroup ag = new AnnotationArrowGroup(-2.0f, 2.0f, // X
            // start
            // and
            // end
            1.5f, -1.5f, // Y start and end
            5); // Number of arrows
    arrowDirectionTransformGroup.addChild(ag);

    // Create a set of Transform3Ds for the different
    // arrow directions.
    arrowDirectionTransforms = new Transform3D[directions.length];
    Vector3f dir = new Vector3f();
    Vector3f positiveX = new Vector3f(1.0f, 0.0f, 0.0f);
    Vector3f axis = new Vector3f();
    float angle;//  w w w.j a  v a  2 s.  c o  m
    float dot;

    for (int i = 0; i < directions.length; i++) {
        // Normalize the direction vector
        dir.normalize((Vector3f) directions[i].value);

        // Cross the direction vector with the arrow's
        // +X aim direction to get a vector orthogonal
        // to both. This is the rotation axis.
        axis.cross(positiveX, dir);
        if (axis.x == 0.0f && axis.y == 0.0f && axis.z == 0.0f) {
            // New direction is parallel to current
            // arrow direction. Default to a Y axis.
            axis.y = 1.0f;
        }

        // Compute the angle between the direction and +X
        // vectors, where:
        //
        //   cos(angle) = (dir dot positiveX)
        //                -------------------------------
        //                (positiveX.length * dir.length)
        //
        // but since positiveX is normalized (as created
        // above and dir has been normalized, both have a
        // length of 1. So, the angle between the
        // vectors is:
        //
        //   angle = arccos(dir dot positiveX)
        //
        dot = dir.dot(positiveX);
        angle = (float) Math.acos(dot);

        // Create a Transform3D, setting its rotation using
        // an AxisAngle4f, which takes an XYZ rotation vector
        // and an angle to rotate by around that vector.
        arrowDirectionTransforms[i] = new Transform3D();
        arrowDirectionTransforms[i].setRotation(new AxisAngle4f(axis.x, axis.y, axis.z, angle));
    }

    // Set the initial transform to be the current aim direction.
    arrowDirectionTransformGroup.setTransform(arrowDirectionTransforms[currentDirection]);

    return arrowDirectionTransformGroup;
}

From source file:se.llbit.chunky.renderer.scene.Sky.java

/**
 * Calculate sky color for the ray, based on sky mode
 * @param ray// w  w w.  j  a  v  a2  s  .co m
 */
public void getSkyDiffuseColorInner(Ray ray) {
    switch (mode) {
    case GRADIENT: {
        double angle = Math.asin(ray.d.y);
        int x = 0;
        if (gradient.size() > 1) {
            double pos = (angle + Constants.HALF_PI) / Math.PI;
            Vector4d c0 = gradient.get(x);
            Vector4d c1 = gradient.get(x + 1);
            double xx = (pos - c0.w) / (c1.w - c0.w);
            while (x + 2 < gradient.size() && xx > 1) {
                x += 1;
                c0 = gradient.get(x);
                c1 = gradient.get(x + 1);
                xx = (pos - c0.w) / (c1.w - c0.w);
            }
            xx = 0.5 * (Math.sin(Math.PI * xx - Constants.HALF_PI) + 1);
            double a = 1 - xx;
            double b = xx;
            ray.color.set(a * c0.x + b * c1.x, a * c0.y + b * c1.y, a * c0.z + b * c1.z, 1);
        }
        break;
    }
    case SIMULATED: {
        scene.sun().calcSkyLight(ray, horizonOffset);
        break;
    }
    case SKYMAP_PANORAMIC: {
        if (mirrored) {
            double theta = FastMath.atan2(ray.d.z, ray.d.x);
            theta += rotation;
            theta /= Constants.TAU;
            if (theta > 1 || theta < 0) {
                theta = (theta % 1 + 1) % 1;
            }
            double phi = Math.abs(Math.asin(ray.d.y)) / Constants.HALF_PI;
            skymap.getColor(theta, phi, ray.color);
        } else {
            double theta = FastMath.atan2(ray.d.z, ray.d.x);
            theta += rotation;
            theta /= Constants.TAU;
            theta = (theta % 1 + 1) % 1;
            double phi = (Math.asin(ray.d.y) + Constants.HALF_PI) / Math.PI;
            skymap.getColor(theta, phi, ray.color);
        }
        break;
    }
    case SKYMAP_SPHERICAL: {
        double cos = FastMath.cos(-rotation);
        double sin = FastMath.sin(-rotation);
        double x = cos * ray.d.x + sin * ray.d.z;
        double y = ray.d.y;
        double z = -sin * ray.d.x + cos * ray.d.z;
        double len = Math.sqrt(x * x + y * y);
        double theta = (len < Ray.EPSILON) ? 0 : Math.acos(-z) / (Constants.TAU * len);
        double u = theta * x + .5;
        double v = .5 + theta * y;
        skymap.getColor(u, v, ray.color);
        break;
    }
    case SKYBOX: {
        double cos = FastMath.cos(-rotation);
        double sin = FastMath.sin(-rotation);
        double x = cos * ray.d.x + sin * ray.d.z;
        double y = ray.d.y;
        double z = -sin * ray.d.x + cos * ray.d.z;
        double xabs = QuickMath.abs(x);
        double yabs = QuickMath.abs(y);
        double zabs = QuickMath.abs(z);
        if (y > xabs && y > zabs) {
            double alpha = 1 / yabs;
            skybox[SKYBOX_UP].getColor((1 + x * alpha) / 2.0, (1 + z * alpha) / 2.0, ray.color);
        } else if (-z > xabs && -z > yabs) {
            double alpha = 1 / zabs;
            skybox[SKYBOX_FRONT].getColor((1 + x * alpha) / 2.0, (1 + y * alpha) / 2.0, ray.color);
        } else if (z > xabs && z > yabs) {
            double alpha = 1 / zabs;
            skybox[SKYBOX_BACK].getColor((1 - x * alpha) / 2.0, (1 + y * alpha) / 2.0, ray.color);
        } else if (-x > zabs && -x > yabs) {
            double alpha = 1 / xabs;
            skybox[SKYBOX_LEFT].getColor((1 - z * alpha) / 2.0, (1 + y * alpha) / 2.0, ray.color);
        } else if (x > zabs && x > yabs) {
            double alpha = 1 / xabs;
            skybox[SKYBOX_RIGHT].getColor((1 + z * alpha) / 2.0, (1 + y * alpha) / 2.0, ray.color);
        } else if (-y > xabs && -y > zabs) {
            double alpha = 1 / yabs;
            skybox[SKYBOX_DOWN].getColor((1 + x * alpha) / 2.0, (1 - z * alpha) / 2.0, ray.color);
        }
        break;
    }
    default:
        break;
    }
}

From source file:de.avanux.livetracker.statistics.TrackingStatistics.java

/**
 * Distance calculation between 2 Geopoint by Haversine formula
 * /*from   w ww  .ja v a 2 s  .c  o m*/
 * Origin:
 * http://www.anddev.org/distance_calculation_between_2_geopoint_by_haversine_formula-t3062.html
 * 
 * @param lat_a
 * @param lon_a
 * @param lat_b
 * @param lon_b
 * @return distance in meters
 */
private double calculateDistance(float lat_a, float lon_a, float lat_b, float lon_b) {
    float pk = (float) (180 / 3.14169);

    float a1 = lat_a / pk;
    float a2 = lon_a / pk;
    float b1 = lat_b / pk;
    float b2 = lon_b / pk;

    double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2);
    double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2);
    double t3 = Math.sin(a1) * Math.sin(b1);
    double tt = Math.acos(t1 + t2 + t3);

    return 6366000 * tt;
}

From source file:fr.amap.viewer3d.object.camera.TrackballCamera.java

public void rotateFromOrientation(Vec3F axis, Vec3F center, float angle) {

    forwardVec = getForwardVector();/*  w w  w. ja v  a2s  . co m*/

    float radius = Vec3F.length(forwardVec);

    forwardVec = Vec3F.normalize(forwardVec);

    rightVec = Vec3F.cross(forwardVec, up);

    if (Vec3F.length(rightVec) == 0) {
        rightVec.y = 1;
    }

    upVec = getUpVector();

    //forwardVec = Vec3F.normalize(forwardVec);
    rightVec = Vec3F.normalize(rightVec);
    upVec = Vec3F.normalize(upVec);

    if (axis.x != 0) {

        //quation du cercle:
        //M = C + A* r * cos(t) + B * r *sin(t) avec M = position sur le cercle, C = centre du cercle, A = vecteur du cercle, B = vecteur du cercle orthogonal  A, r = rayon du cercle, t = angle
        //position = Vec3.add(pivot, Vec3.add(Vec3.multiply(viewXAxis, r* (float)Math.cos(angleX)), Vec3.multiply(viewYAxis, r* (float)Math.sin(angleX))));

        //pondration de l'angle par l'inclinaison
        float n = Vec3F.dot(forwardVec, up);
        float d = Vec3F.length(forwardVec) * Vec3F.length(up);

        float tilt = (float) (Math.acos(Math.abs(n / d)));
        /*
        if(tilt == 0){
        tilt = 0.18f;
        }*/

        angle *= (tilt / (Math.PI / 2.0d));

        angle = -angle;
        float angleSinus = (float) Math.sin(angle);
        float angleCosinus = (float) Math.cos(angle);

        location.x = target.x + (-forwardVec.x * radius * angleCosinus) + (rightVec.x * radius * angleSinus);
        location.y = target.y + (-forwardVec.y * radius * angleCosinus) + (rightVec.y * radius * angleSinus);
        location.z = target.z + (-forwardVec.z * radius * angleCosinus) + (rightVec.z * radius * angleSinus);

    }
    if (axis.y != 0) {

        float angleSinus = (float) Math.sin(angle);
        float angleCosinus = (float) Math.cos(angle);

        //copy
        Vec3F oldLocation = new Vec3F(location.x, location.y, location.z);

        location.x = target.x + (-forwardVec.x * radius * angleCosinus) + (upVec.x * radius * angleSinus);
        location.y = target.y + (-forwardVec.y * radius * angleCosinus) + (upVec.y * radius * angleSinus);
        location.z = target.z + (-forwardVec.z * radius * angleCosinus) + (upVec.z * radius * angleSinus);

        Vec3F newForwardVec = getForwardVector();
        newForwardVec = Vec3F.normalize(newForwardVec);

        Vec3F newRightVec = Vec3F.cross(newForwardVec, up);

        if ((newRightVec.y < 0 && rightVec.y > 0) || (newRightVec.y > 0 && rightVec.y < 0)) {
            location = oldLocation;
        }
    }

    //target = pivot;

    updateViewMatrix();

}

From source file:elements.Vector3D.java

/** Compute the angular separation between two vectors.
 * <p>This method computes the angular separation between two
 * vectors using the dot product for well separated vectors and the
 * cross product for almost aligned vectors. This allow to have a
 * good accuracy in all cases, even for vectors very close to each
 * other.</p>//from   w ww  .j  av  a 2  s. c o  m
 * @param v1 first vector
 * @param v2 second vector
 * @return angular separation between v1 and v2
 * @exception ArithmeticException if either vector has a null norm
 */
public static double angle(Vector3D v1, Vector3D v2) {

    double normProduct = v1.getNorm() * v2.getNorm();
    if (normProduct == 0) {
        // throw new ArithmeticException("null norm");
    }

    double dot = dotProduct(v1, v2);
    double threshold = normProduct * 0.9999;
    if ((dot < -threshold) || (dot > threshold)) {
        // the vectors are almost aligned, compute using the sine
        Vector3D v3 = crossProduct(v1, v2);
        if (dot >= 0) {
            return Math.asin(v3.getNorm() / normProduct);
        }
        return Math.PI - Math.asin(v3.getNorm() / normProduct);
    }

    // the vectors are sufficiently separated to use the cosine
    return Math.acos(dot / normProduct);

}

From source file:sundroid.code.SundroidActivity.java

/** Called when the activity is first created. ***/
@Override//from   ww w .j  a  v a  2 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:demo.RxJavaTransformer.java

private static int distance(double lat1, double lon1, double lat2, double lon2) {
    double theta = lon1 - lon2;
    double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
            + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
    dist = Math.acos(dist);
    dist = rad2deg(dist);//from w  w  w  .j ava  2  s .co  m
    dist = dist * 60 * 1.1515;
    // distance in meters
    dist = dist * 1.609344 * 1000;
    return (Double.valueOf(dist / 1000).intValue() + 1);
}