Example usage for java.lang Math sin

List of usage examples for java.lang Math sin

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double sin(double a) 

Source Link

Document

Returns the trigonometric sine of an angle.

Usage

From source file:sundroid.code.SundroidActivity.java

/** Called when the activity is first created. ***/
@Override/*from w  w w  . j a va2  s  .com*/
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.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;/*  w ww.  j  av  a2  s .  c om*/
}

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

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

    forwardVec = getForwardVector();// w ww  . j  a v  a2 s . c o  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:com.bdb.weather.display.preferences.ColorPreferencePanel.java

private void createSeriesData() {
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        XYSeries series = dataset.getSeries(i);
        series.clear();//from   ww w .  jav  a2s. com
        for (int j = 0; j < 360; j++) {
            series.add(j / 360.0, Math.sin(Math.toRadians(j + (i * (360.0 / dataset.getSeriesCount())))),
                    false);
        }
        series.fireSeriesChanged();
    }
}

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];//ww w.jav  a 2 s  .com
    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: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);// w  w  w . jav  a2 s.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:br.liveo.ndrawer.ui.fragment.MainFragment22.java

public double getDistanceBetweenTwoCoordiantes(double lat1, double lat2, double lon1, double lon2) {
    try {//  www .  ja v  a 2 s.co m
        double R = 6371.0; // km

        double dLat = toRad(lat2 - lat1);
        double dLon = toRad(lon2 - lon1);

        double a = Math.sin(dLat / 2.0) * Math.sin(dLat / 2.0)
                + Math.sin(dLon / 2.0) * Math.sin(dLon / 2.0) * Math.cos(toRad(lat1)) * Math.cos(toRad(lat2));
        double c = 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
        double d = R * c;

        // return unit meter
        return d * 1000;
    } catch (Exception e) {
        return 0;
    }
}

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

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

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;//  www . j a v a  2 s  .  c om
}

From source file:ExDepthCue.java

public Shape3D buildSurface(double freqAlpha, double freqTheta, double radius, float red, float green,
        float blue) {
    int nAngles = 64;
    double amp = radius / 4.0;

    int nAlpha = nAngles / 2;
    double theta, alpha;
    double x, y, z, rprime, r;
    double deltaTheta, deltaAlpha;
    int i, j;//ww w .  java  2s .  com
    int i1, i2, i3, i4;

    deltaTheta = 360.0 / (nAngles - 1.0);
    deltaAlpha = 180.0 / (nAlpha - 1.0);

    // Build an appearance
    Appearance app = new Appearance();

    LineAttributes latt = new LineAttributes();
    latt.setLineWidth(1.0f);
    app.setLineAttributes(latt);

    ColoringAttributes catt = new ColoringAttributes();
    catt.setColor(red, green, blue);
    app.setColoringAttributes(catt);

    PolygonAttributes patt = new PolygonAttributes();
    patt.setCullFace(PolygonAttributes.CULL_NONE);
    patt.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    app.setPolygonAttributes(patt);

    // Compute coordinates
    double[] coordinates = new double[nAlpha * nAngles * 3];
    alpha = 90.0;
    int n = 0;
    for (i = 0; i < nAlpha; i++) {
        theta = 0.0;
        for (j = 0; j < nAngles; j++) {
            r = radius + amp * Math.sin((freqAlpha * ((double) i / (double) (nAlpha - 1))
                    + freqTheta * ((double) j / (double) (nAngles - 1))) * 2.0 * Math.PI);
            y = r * Math.sin(alpha / 180.0 * Math.PI);
            rprime = y / Math.tan(alpha / 180.0 * Math.PI);
            x = rprime * Math.cos(theta / 180.0 * Math.PI);
            z = rprime * Math.sin(theta / 180.0 * Math.PI);

            coordinates[n + 0] = x;
            coordinates[n + 1] = y;
            coordinates[n + 2] = z;
            n += 3;
            theta += deltaTheta;
        }
        alpha -= deltaAlpha;
    }

    // Compute coordinate indexes
    int[] indexes = new int[(nAlpha - 1) * nAngles * 4];
    n = 0;
    for (i = 0; i < nAlpha - 1; i++) {
        for (j = 0; j < nAngles; j++) {
            i1 = i * nAngles + j;
            if (j == nAngles - 1) {
                i2 = i1 - j;
                i3 = (i + 1) * nAngles;
            } else {
                i2 = i1 + 1;
                i3 = (i + 1) * nAngles + j + 1;
            }
            i4 = (i + 1) * nAngles + j;

            indexes[n + 0] = i1;
            indexes[n + 1] = i2;
            indexes[n + 2] = i3;
            indexes[n + 3] = i4;
            n += 4;
        }
    }

    // Build the shape
    IndexedQuadArray lines = new IndexedQuadArray(coordinates.length / 3, // Number
            // of
            // coordinates
            GeometryArray.COORDINATES, // coordinates only
            indexes.length); // Number of indexes
    lines.setCoordinates(0, coordinates);
    lines.setCoordinateIndices(0, indexes);

    Shape3D shape = new Shape3D(lines, app);

    return shape;
}