Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine of an angle.

Usage

From source file:com.duy.pascal.interperter.libraries.math.MathLib.java

@PascalMethod(description = "")
public double Sec(double x) {
    return 1 / Math.cos(x);
}

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;//  ww  w  .  j ava  2  s.  co  m
}

From source file:sundroid.code.SundroidActivity.java

/** Called when the activity is first created. ***/
@Override/* w  w w .  jav  a  2s .  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:gui.GraphsPanel.java

/** TODO: re-implement the algorithm from vertexColor.
 * Vertice Coloring algorithm executed before the vertexColor Transformer is
 * called/*from   w  ww .ja va  2 s .  co m*/
 * TV same algorithm initially set as a vertexColor Transformer COPY FROM
 * PROCESSCLUSTERRESULTS
 */
public void colorizeTree(TreeNode root, float threshold) {
    // System.out.println("___GraphsPanel: COLORIZE TREE!");
    Color customColor = Color.WHITE;

    // int groupCount =
    // cluster.getAvLnkDendrogram().getGroupCount(threshold);
    // int counter = groupCount;

    // traverese the tree
    // Enumeration en =
    // ((DefaultMutableTreeNode)root).depthFirstEnumeration();
    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> en = ((DefaultMutableTreeNode) root).breadthFirstEnumeration();
    while (en.hasMoreElements()) {
        // Unfortunately the enumeration isn't genericised so we need to
        // downcast
        // when calling nextElement():
        DefaultMutableTreeNode node = en.nextElement();
        DenNode dNode = (DenNode) node.getUserObject();
        Integer level = node.getLevel();

        if (level == 0) {
            dNode.setColor(customColor);
        } else if (level != 0) {
            DenNode pdNode = (DenNode) ((DefaultMutableTreeNode) (node.getParent())).getUserObject();
            if ((dNode.getSimilarity() > threshold) && (pdNode.getColor().equals(Color.WHITE))) {
                dNode.setColor(
                        Color.getHSBColor((float) (Math.cos(dNode.getSimilarity() * 90) * 360), 0.8f, 0.8f));
            } else {
                dNode.setColor(pdNode.getColor());
            }
            // TV
            if (((dNode.getSimilarity() - pdNode.getSimilarity()) > this.getSensitivity())) {
                dNode.setEdgeColor(Color.BLACK);
            }
        }
    }
}

From source file:rod_design_compute.ShowPanel.java

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

    x[0] = (int) (Math.cos(theta) * l / 2);
    y[0] = (int) (Math.sin(theta) * l / 2);
    x[1] = -x[0];/*from  ww  w .  j a  v a2s. c om*/
    y[1] = -y[0];

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

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

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

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void cosPiHalf() {
    try {//from w w w. j  ava2  s  .co m
        Expression expression = getExpressionWithFunctionContext("cos(pi/2)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.cos(Math.PI / 2), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

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

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

    forwardVec = getForwardVector();/*from  w ww . j  a  va  2s  . c om*/

    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:etomica.potential.EwaldSummation.java

public double uFourier() {
    double kCutSquared = kCut * kCut; // criteria for spherical cutoff in fourier space
    double coefficient = 2.0 * Math.PI / volume;
    double uFourier = 0.0; //>>>>>>>>>>>>>> calculated from cos*cos + sin*sin
    IAtomList atoms = box.getLeafList();
    int nAtoms = atoms.getAtomCount();

    // loop over vectors in k-space. (1)k=(0,0,0) is excluded, (2)within sphere with kCutoff as its radius
    for (int xAxis = -nKs[0]; xAxis < nKs[0] + 1; xAxis++) {
        kVector.setX(0, (xAxis * basis[0]));// assign value to the x-axis
        for (int yAxis = -nKs[1]; yAxis < nKs[1] + 1; yAxis++) {
            kVector.setX(1, (yAxis * basis[1]));// assign value to the y-axis
            for (int zAxis = -nKs[2]; zAxis < nKs[2] + 1; zAxis++) {
                if ((xAxis * xAxis + yAxis * yAxis + zAxis * zAxis) == 0)
                    continue;// first check: k is a non-zero vector
                kVector.setX(2, (zAxis * basis[2]));// assign value to the z-axis, now the vector is specified
                double kSquared = kVector.squared();

                if (kSquared > kCutSquared)
                    continue;// k-vector should be within the sphere with kCutoff as the radius

                double kCoefficientTerm = Math.exp(-0.25 * kSquared / alpha2) / kSquared;//exp(-k*k/4/alpha/alpha) / k/k , a constant for a given kVector
                double structureFactorReal = 0.0;//>>>>>>>>>>>>> calculated from cos*cos + sin*sin
                double structureFactorImagine = 0.0;//>>>>>>>>>>>>> calculated from cos*cos + sin*sin
                for (int i = 0; i < nAtoms; i++) {
                    IAtom atom = atoms.getAtom(i);
                    IVectorMutable position = atom.getPosition();
                    double charge = atomAgentManager.getAgent(atom).charge;
                    if (charge == 0)
                        continue;
                    double k_r_dot = kVector.dot(position);
                    structureFactorReal += charge * Math.cos(k_r_dot);// >>>>>>>>>>>>> calculated from cos*cos + sin*sin
                    structureFactorImagine += charge * Math.sin(k_r_dot);// >>>>>>>>>>>>> calculated from cos*cos + sin*sin
                } // close loop for all sites within 1 molecule
                double structureFactorSquared = structureFactorReal * structureFactorReal
                        + structureFactorImagine * structureFactorImagine;//>>>>>>>>>>>>>calculated from cos*cos + sin*sin
                uFourier += kCoefficientTerm * structureFactorSquared; //>>>>>>>>>>>>>calculated from cos*cos + sin*sin
            } // close for z-axis
        } //close for y-axis
    } // close for x-axis(all non-zero kVecors)
    double u = coefficient * uFourier;
    return u;//from w  w w  .j av a2s. co  m
}

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);//from  w  ww .  j a  v a 2s  .c  o  m
    dist = rad2deg(dist);
    dist = dist * 60 * 1.1515;
    // distance in meters
    dist = dist * 1.609344 * 1000;
    return (Double.valueOf(dist / 1000).intValue() + 1);
}

From source file:edu.umn.cs.spatialHadoop.nasa.HDFRecordReader.java

/**
 * Sets the geometry information for the given object according to its
 * position in the array//from w  ww.  j  a  va2s. c  om
 * @param s
 * @param position
 */
protected void setShapeGeometry(Shape s, int position) {
    position /= valueSize;
    int row = position / nasaDataset.resolution;
    int col = position % nasaDataset.resolution;
    if (s instanceof Point) {
        Point p = (Point) s;
        p.y = (90 - nasaDataset.v * 10) - (double) row * 10 / nasaDataset.resolution;
        p.x = (nasaDataset.h * 10 - 180) + (double) (col) * 10 / nasaDataset.resolution;
        p.x /= Math.cos(p.y * Math.PI / 180);
    } else if (s instanceof Rectangle) {
        Rectangle r = (Rectangle) s;
        r.y2 = (90 - nasaDataset.v * 10) - (double) row * 10 / nasaDataset.resolution;
        r.y1 = (90 - nasaDataset.v * 10) - (double) (row + 1) * 10 / nasaDataset.resolution;
        double[] xs = new double[4];
        xs[0] = xs[1] = (nasaDataset.h * 10 - 180) + (double) (col) * 10 / nasaDataset.resolution;
        xs[2] = xs[3] = (nasaDataset.h * 10 - 180) + (double) (col + 1) * 10 / nasaDataset.resolution;

        // Project all four corners and select the min-max for the rectangle
        xs[0] /= Math.cos(r.y1 * Math.PI / 180);
        xs[1] /= Math.cos(r.y2 * Math.PI / 180);
        xs[2] /= Math.cos(r.y1 * Math.PI / 180);
        xs[3] /= Math.cos(r.y2 * Math.PI / 180);
        r.x1 = r.x2 = xs[0];
        for (double x : xs) {
            if (x < r.x1)
                r.x1 = x;
            if (x > r.x2)
                r.x2 = x;
        }
    } else {
        throw new RuntimeException("Unsupported shape " + s.getClass());
    }
}