Example usage for java.lang Math toDegrees

List of usage examples for java.lang Math toDegrees

Introduction

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

Prototype

public static double toDegrees(double angrad) 

Source Link

Document

Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

Usage

From source file:gr.iit.demokritos.cru.cps.ai.ProfileMerger.java

public ArrayList<Double> CalculateUserTrends(ArrayList<String> users_features, Double start_time)
        throws ParseException {

    SimpleDateFormat sdfu = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
    ArrayList<Double> result = new ArrayList<Double>();

    for (int i = 0; i < users_features.size(); i++) {
        SimpleRegression regression = new SimpleRegression();
        String[] features = ((String) users_features.get(i)).split(";");

        double average = 0.0;
        double f = 0.0;
        for (String s : features) {

            String[] inside_feature = s.split(",");

            //make timestamp secs
            Date udate = sdfu.parse(inside_feature[1]);
            double sec = udate.getTime();

            if (sec > start_time) {
                continue;
            }/* w w  w  . j a v  a  2s . c om*/
            average += Double.parseDouble(inside_feature[0]);
            //fix mls regr

            regression.addData(sec, Double.parseDouble(inside_feature[0]));

            average = average / features.length;

            f = Math.atan(regression.getSlope());// atan of slope is the angle of the regression in rad
            if (Double.isNaN(f)) {
                f = 0;
            }
            if (f != 0 && (Math.toDegrees(f) > 90 || Math.toDegrees(f) < -90)) {
                if ((Math.toDegrees(f) / 90) % 2 == 0) {//make angles in [-90,90]
                    f = Math.toDegrees(f) % Math.toDegrees(Math.PI / 2);
                } else {
                    f = -Math.toDegrees(f) % Math.toDegrees(Math.PI / 2);
                }
            }
            f = f + Math.PI / 2;//refrain trend=0                    

        }

        result.add(f);
        result.add(f * average);

    }
    return result;

}

From source file:main.java.gov.wa.wsdot.candidate.evaluation.App.java

/**
 * Using the Haversine formula this method calculates the distance in miles
 * between two latitude and longitude points.
 * //from   ww  w  .  ja  v a 2 s .c om
 * Formula from: https://en.wikipedia.org/wiki/Haversine_formula
 * 
 * @param lat1  latitude of point 1 (user)
 * @param long1 longitude of point 1 (user)
 * @param lat2  latitude of point 2 (camera)
 * @param long2 longitude of point 2 (camera)
 * @return      distance in miles between two points given
 */
private double getDistance(double lat1, double long1, double lat2, double long2) {

    double deltaLong;
    double deltaLat;
    double hav2;
    double hav1;

    lat1 = Math.toRadians(lat1);
    lat2 = Math.toRadians(lat2);
    long1 = Math.toRadians(long1);
    long2 = Math.toRadians(long2);

    deltaLong = Math.toRadians(long2 - long1);
    deltaLat = Math.toRadians(lat2 - lat1);

    hav1 = (Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2));
    hav2 = (Math.sin(deltaLong / 2) * Math.sin(deltaLong / 2));

    return Math.toDegrees(2 * R * Math.asin(Math.sqrt(hav1 + Math.cos(lat1) * Math.cos(lat2) * hav2)));
}

From source file:com.nextgis.mobile.forms.CompassFragment.java

public boolean onTouch(View v, MotionEvent event) {

    switch (event.getAction()) {

    case MotionEvent.ACTION_DOWN:
        downX = event.getX();/* www  . j  a  va2  s  .  c  o m*/
        downY = event.getY();
        return true;

    case MotionEvent.ACTION_MOVE:

        upX = event.getX();
        upY = event.getY();

        double downR = Math.atan2(v.getHeight() / 2 - downY, downX - v.getWidth() / 2);
        int angle1 = (int) Math.toDegrees(downR);

        double upR = Math.atan2(v.getHeight() / 2 - upY, upX - v.getWidth() / 2);
        int angle2 = (int) Math.toDegrees(upR);

        this.rotateCompass(angle1 - angle2);

        if (vibrationOn) {
            vibrator.vibrate(5);
        }

        // update starting point for next move event
        downX = upX;
        downY = upY;

        return true;
    }
    return false;
}

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

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

    Log.d(VRSamplesTouchPadGesturesDetector.DEBUG_TAG, "onFling()");

    if (mDetector == null) {
        return false;
    }/* w ww.j a v a 2s  .c o  m*/

    double distance = Math.sqrt(Math.pow(e2.getX() - e1.getX(), 2) + Math.pow(e2.getY() - e1.getY(), 2));

    saveSwipeDistanceValue((float) distance);

    if (distance > SWIPE_MIN_DISTANCE) {
        try {

            double deltaY = e2.getY() - e1.getY();
            double deltaX = e2.getX() - e1.getX();

            double angle = Math.toDegrees(Math.atan2(deltaY, deltaX)) + 180 + 45;

            if (angle > 360)
                angle -= 360;

            if (angle < 90) {
                return gestureListener.onSwipe(e1, SwipeDirection.Forward, velocityX, velocityY);
            } else if (angle < 180) {
                return gestureListener.onSwipe(e1, SwipeDirection.Up, velocityX, velocityY);
            } else if (angle < 270) {
                return gestureListener.onSwipe(e1, SwipeDirection.Backward, velocityX, velocityY);
            } else {
                return gestureListener.onSwipe(e1, SwipeDirection.Down, velocityX, velocityY);
            }

        } catch (Exception e) {
            // Ignore
        }

    } else if (distance >= ONTAP_MIN_DISTANCE) {
        /*
         * The gesture listener filters out dirty taps that look like swipes
         * altogether. This reduces usability as it's hard to get a clean
         * tap on the tracker
         */
        gestureListener.onSingleTap(e1);
        return true;
    }

    return false;
}

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

@PascalMethod(description = "")
public double RadToDeg(double d) {
    return Math.toDegrees(d);
}

From source file:org.kuali.kra.printing.service.impl.WatermarkServiceImpl.java

/**
 * This method is for setting the properties of watermark Text.
 * //w  w  w  . j  a v  a  2 s . c o  m
 * @param pdfContentByte
 * @param pageWidth
 * @param pageHeight
 * @param watermarkBean
 */
private void decoratePdfWatermarkText(PdfContentByte pdfContentByte, int pageWidth, int pageHeight,
        WatermarkBean watermarkBean) {
    float x, y, x1, y1, angle;
    try {
        if (watermarkBean.getType().equalsIgnoreCase(WatermarkConstants.WATERMARK_TYPE_TEXT)) {
            pdfContentByte.beginText();
            pdfContentByte.setFontAndSize(watermarkBean.getFont().getBaseFont(),
                    watermarkBean.getFont().getSize());
            Color fillColor = watermarkBean.getFont().getColor() == null
                    ? WatermarkConstants.DEFAULT_WATERMARK_COLOR
                    : watermarkBean.getFont().getColor();
            pdfContentByte.setColorFill(fillColor);
            int textWidth = (int) pdfContentByte.getEffectiveStringWidth(watermarkBean.getText(), false);
            int diagonal = (int) Math.sqrt((pageWidth * pageWidth) + (pageHeight * pageHeight));
            int pivotPoint = (diagonal - textWidth) / 2;

            angle = (float) Math.atan((float) pageHeight / pageWidth);

            x = (float) (pivotPoint * pageWidth) / diagonal;
            y = (float) (pivotPoint * pageHeight) / diagonal;

            x1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.sin(angle));
            y1 = (float) (((float) watermarkBean.getFont().getSize() / 2) * Math.cos(angle));

            pdfContentByte.showTextAligned(Element.ALIGN_LEFT, watermarkBean.getText(), x + x1, y - y1,
                    (float) Math.toDegrees(angle));
            pdfContentByte.endText();
        }

    } catch (Exception exception) {
        LOG.error("Exception occured in WatermarkServiceImpl. Water mark Exception: " + exception.getMessage());
    }

}

From source file:PaintUtils.java

private static Point2D[] adjustPoints(Point2D[] pts, int width, int height) {
    Point2D start = pts[0];/*from   w w w.  j av a 2s  .  c om*/
    Point2D end = pts[1];

    double angle = calcAngle(start, end);
    double a2 = Math.toDegrees(angle);
    double e = 1;

    // if it is near 0 degrees
    if (Math.abs(angle) < Math.toRadians(e) || Math.abs(angle) > Math.toRadians(360 - e)) {
        start = new Point2D.Float(0, 0);
        end = new Point2D.Float(width, 0);
    }

    // near 45
    if (isNear(a2, 45, e)) {
        start = new Point2D.Float(0, 0);
        end = new Point2D.Float(width, height);
    }

    // near 90
    if (isNear(a2, 90, e)) {
        start = new Point2D.Float(0, 0);
        end = new Point2D.Float(0, height);
    }

    // near 135
    if (isNear(a2, 135, e)) {
        start = new Point2D.Float(width, 0);
        end = new Point2D.Float(0, height);
    }

    // near 180
    if (isNear(a2, 180, e)) {
        start = new Point2D.Float(width, 0);
        end = new Point2D.Float(0, 0);
    }

    // near 225
    if (isNear(a2, 225, e)) {
        start = new Point2D.Float(width, height);
        end = new Point2D.Float(0, 0);
    }

    // near 270
    if (isNear(a2, 270, e)) {
        start = new Point2D.Float(0, height);
        end = new Point2D.Float(0, 0);
    }

    // near 315
    if (isNear(a2, 315, e)) {
        start = new Point2D.Float(0, height);
        end = new Point2D.Float(width, 0);
    }

    return new Point2D[] { start, end };
}

From source file:uk.ac.diamond.scisoft.analysis.diffraction.powder.PixelIntegrationUtils.java

public static Dataset[] generateMinMaxAzimuthalArray(double[] beamCentre, int[] shape, boolean radians) {

    Dataset aMax = DatasetFactory.zeros(shape, Dataset.FLOAT64);
    Dataset aMin = DatasetFactory.zeros(shape, Dataset.FLOAT64);

    PositionIterator iter = aMax.getPositionIterator();
    int[] pos = iter.getPos();
    double[] vals = new double[4];

    while (iter.hasNext()) {
        //find vals at pixel corners
        vals[0] = Math.atan2(pos[0] - beamCentre[1], pos[1] - beamCentre[0]);
        vals[1] = Math.atan2(pos[0] - beamCentre[1] + 1, pos[1] - beamCentre[0]);
        vals[2] = Math.atan2(pos[0] - beamCentre[1], pos[1] - beamCentre[0] + 1);
        vals[3] = Math.atan2(pos[0] - beamCentre[1] + 1, pos[1] - beamCentre[0] + 1);

        Arrays.sort(vals);/*ww  w . ja  va  2s  . c om*/

        if (vals[0] < -Math.PI / 2 && vals[3] > Math.PI / 2) {
            //FIXME do best to handle discontinuity here - saves changing the integration routine
            //may not be as accurate - might need to make the integration aware.
            //currently just squeeze all the signal in one side

            if (Math.PI - vals[3] > Math.PI + vals[0]) {
                vals[3] = Math.PI;
                vals[0] = vals[2];
            } else {
                vals[0] = -Math.PI;
                vals[3] = vals[1];
            }
        }

        if (radians) {
            aMax.set(vals[3], pos);
            aMin.set(vals[0], pos);
        } else {
            aMax.set(Math.toDegrees(vals[3]), pos);
            aMin.set(Math.toDegrees(vals[0]), pos);
        }
    }

    return new Dataset[] { aMin, aMax };
}

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

public LatLon eastNorth2latlon(EastNorth p) {
    LatLon geo;/* w w  w  .j a  v  a  2  s .c  om*/
    if (layoutZone == -1)
        // possible until the Lambert zone is determined by latlon2eastNorth() with a valid LatLon
        geo = Geographic(p, Xs[currentZone], Ys[currentZone], c[currentZone], n[currentZone]);
    else
        geo = Geographic(p, Xs[layoutZone], Ys[layoutZone], c[layoutZone], n[layoutZone]);
    // translate ellipsoid Clark => GRS80 (WGS83)
    LatLon wgs = Clark2GRS80(geo);
    return new LatLon(Math.toDegrees(wgs.lat()), Math.toDegrees(wgs.lon()));
}

From source file:org.esa.beam.util.math.FastMathTest.java

@Test
public void testMathToDegrees() {
    for (double i = 0; i < numItr; ++i) {
        double val = Math.toDegrees(i);
    }/*from w  w  w.  j av  a2s. c  o  m*/
}