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:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java

private void populateStdAnimation(float progress) {
    float height = getSceneView().getHeight();
    float y = height * progress;
    double degrees = Math.toDegrees(Math.acos((height - y) / height));

    mSceneContainer.setAlpha(1f - progress);
    mSceneContainer.setTranslationY(y);/*  w w  w.jav  a2  s  . c  om*/
    mSceneContainer.setRotationX((float) (-degrees / 2f));
}

From source file:com.larvalabs.svgandroid.SVGParser.java

/**
 * Elliptical arc implementation based on the SVG specification notes
 * Adapted from the Batik library (Apache-2 license) by SAU
 *//*w  w w. j  ava 2  s  .co m*/

private static void drawArc(Path path, double x0, double y0, double x, double y, double rx, double ry,
        double angle, boolean largeArcFlag, boolean sweepFlag) {
    double dx2 = (x0 - x) / 2.0;
    double dy2 = (y0 - y) / 2.0;
    angle = Math.toRadians(angle % 360.0);
    double cosAngle = Math.cos(angle);
    double sinAngle = Math.sin(angle);

    double x1 = (cosAngle * dx2 + sinAngle * dy2);
    double y1 = (-sinAngle * dx2 + cosAngle * dy2);
    rx = Math.abs(rx);
    ry = Math.abs(ry);

    double Prx = rx * rx;
    double Pry = ry * ry;
    double Px1 = x1 * x1;
    double Py1 = y1 * y1;

    // check that radii are large enough
    double radiiCheck = Px1 / Prx + Py1 / Pry;
    if (radiiCheck > 1) {
        rx = Math.sqrt(radiiCheck) * rx;
        ry = Math.sqrt(radiiCheck) * ry;
        Prx = rx * rx;
        Pry = ry * ry;
    }

    // Step 2 : Compute (cx1, cy1)
    double sign = (largeArcFlag == sweepFlag) ? -1 : 1;
    double sq = ((Prx * Pry) - (Prx * Py1) - (Pry * Px1)) / ((Prx * Py1) + (Pry * Px1));
    sq = (sq < 0) ? 0 : sq;
    double coef = (sign * Math.sqrt(sq));
    double cx1 = coef * ((rx * y1) / ry);
    double cy1 = coef * -((ry * x1) / rx);

    double sx2 = (x0 + x) / 2.0;
    double sy2 = (y0 + y) / 2.0;
    double cx = sx2 + (cosAngle * cx1 - sinAngle * cy1);
    double cy = sy2 + (sinAngle * cx1 + cosAngle * cy1);

    // Step 4 : Compute the angleStart (angle1) and the angleExtent (dangle)
    double ux = (x1 - cx1) / rx;
    double uy = (y1 - cy1) / ry;
    double vx = (-x1 - cx1) / rx;
    double vy = (-y1 - cy1) / ry;
    double p, n;

    // Compute the angle start
    n = Math.sqrt((ux * ux) + (uy * uy));
    p = ux; // (1 * ux) + (0 * uy)
    sign = (uy < 0) ? -1.0 : 1.0;
    double angleStart = Math.toDegrees(sign * Math.acos(p / n));

    // Compute the angle extent
    n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
    p = ux * vx + uy * vy;
    sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
    double angleExtent = Math.toDegrees(sign * Math.acos(p / n));
    if (!sweepFlag && angleExtent > 0) {
        angleExtent -= 360f;
    } else if (sweepFlag && angleExtent < 0) {
        angleExtent += 360f;
    }
    angleExtent %= 360f;
    angleStart %= 360f;

    RectF oval = new RectF((float) (cx - rx), (float) (cy - ry), (float) (cx + rx), (float) (cy + ry));
    path.addArc(oval, (float) angleStart, (float) angleExtent);
}

From source file:br.com.rescue_bots_android.bluetooth.MainActivity.java

private double meterDistanceBetweenPoints(double lat_a, double lng_a, double lat_b, double lng_b) {
    double pk = (double) (180.f / Math.PI);

    double a1 = lat_a / pk;
    double a2 = lng_a / pk;
    double b1 = lat_b / pk;
    double b2 = lng_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:gdsc.core.clustering.DensityManager.java

/**
 * Calculate the area of circular segment, a portion of a disk whose upper boundary is a (circular) arc and whose
 * lower boundary is a chord making a central angle of theta radians.
 * <p>/*from w w  w  . j a va2  s.c  o  m*/
 * See http://mathworld.wolfram.com/CircularSegment.html
 * 
 * @param R
 *            the radius of the circle
 * @param h
 *            the height of the arced portion
 * @return The area
 */
private double getSegmentArea(double R, double h) {
    return R * R * Math.acos((R - h) / R) - (R - h) * Math.sqrt(2 * R * h - h * h);
}

From source file:br.com.jordan.cadeopenha.util.GoogleDirection.java

public double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
    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 www . ja  v  a2  s  .com
    dist = dist * 60 * 1.1515;
    if (unit == 'K') {
        dist = dist * 1.609344;
    } else if (unit == 'N') {
        dist = dist * 0.8684;
    }
    return (dist);
}

From source file:de.tlabs.ssr.g1.client.SourcesView.java

@Override
public boolean onScroll(MotionEvent firstEvent, MotionEvent thisEvent, float distanceX, float distanceY) {

    // transform sound source or surface?
    if (lastTouchSoundSource != null) { // transform sound source
        synchronized (GlobalData.audioScene) {
            // is lastTouchSoundSource selected?
            if (!lastTouchSoundSource.isSelected()) {
                // select only this source
                GlobalData.audioScene.deselectAllSoundSources();
                GlobalData.audioScene.selectSoundSource(lastTouchSoundSource);
            }/*from   w w  w  . ja va  2  s  .  c  om*/

            // save positions of sources if this is first scroll event
            if (!scrolling) {
                scrolling = true;
                firstScrollPoint[0] = firstEvent.getX();
                firstScrollPoint[1] = firstEvent.getY();
                ArrayList<SoundSource> selectedSources = GlobalData.audioScene.getSelectedSoundSources();
                int numSources = selectedSources.size();
                for (int i = 0; i < numSources; i++) { // loop through all currently selected sources
                    selectedSources.get(i).getXY(point);
                    GlobalData.audioScene.mapPoint(point);
                    viewportTransformation.mapPoints(point);
                    selectedSources.get(i).savePosition(point);
                }
            }

            // enough time elapsed to do next position update?
            long currentTime = SystemClock.uptimeMillis();
            if (currentTime - lastSendTime < MAX_POSITION_UPDATE_FREQ)
                return true;
            lastSendTime = currentTime;

            // translate or rotate?
            if (transformationMode == TransformationMode.TRANSLATE) { // translate
                // generate server request string
                String strMsg = "<request>";
                ArrayList<SoundSource> selectedSources = GlobalData.audioScene.getSelectedSoundSources();
                int numSources = selectedSources.size();
                SoundSource soundSource;
                for (int i = 0; i < numSources; i++) { // loop through all currently selected sources
                    soundSource = selectedSources.get(i);

                    // if source is fixed, skip it
                    if (soundSource.isPositionFixed())
                        continue;

                    strMsg += "<source id='" + soundSource.getId() + "'>";
                    // transform screen coords into object coords, consider offset
                    point[0] = soundSource.getSavedX() + thisEvent.getX() - firstScrollPoint[0];
                    point[1] = soundSource.getSavedY() + thisEvent.getY() - firstScrollPoint[1];
                    inverseViewportTransformation.mapPoints(point);

                    if (soundSource.getSourceModel() == SoundSource.SourceModel.PLANE) { // recalculate orientation for plane waves
                        float norm = FloatMath.sqrt(point[0] * point[0] + point[1] * point[1]); // for plane waves, if source is movable
                        if (norm != 0.0f) {
                            float newAzimuth;
                            if (point[1] >= 0.0f)
                                newAzimuth = (float) (Math.acos(point[0] / norm) / Math.PI * 180.0f) - 180.0f
                                        + GlobalData.audioScene.getReference().getAzimuth();
                            else
                                newAzimuth = (float) -(Math.acos(point[0] / norm) / Math.PI * 180.0f) - 180.0f
                                        + GlobalData.audioScene.getReference().getAzimuth();
                            strMsg += "<orientation azimuth='" + String.valueOf(newAzimuth) + "'/>";
                        }
                    }

                    GlobalData.audioScene.inverseMapPoint(point);
                    strMsg += "<position x='" + String.valueOf(point[0]) + "' y='" + String.valueOf(point[1])
                            + "'/>";
                    strMsg += "</source>";
                }
                strMsg += "</request>\0";

                // send changes to server
                sendToServer(strMsg);
            } else { // rotate
                // not implemented
            }
        }
    } else { // transform surface
        if (!scrolling) {
            scrolling = true;
            firstScrollPoint[0] = thisEvent.getX();
            firstScrollPoint[1] = thisEvent.getY();
            currentSavedTranslation[0] = currentTranslation[0];
            currentSavedTranslation[1] = currentTranslation[1];
        }

        // translate or rotate?
        if (transformationMode == TransformationMode.TRANSLATE) { // translate
            if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
                point[0] = thisEvent.getX() - firstScrollPoint[0];
                point[1] = thisEvent.getY() - firstScrollPoint[1];
            } else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
                point[0] = thisEvent.getY() - firstScrollPoint[1];
                point[1] = -(thisEvent.getX() - firstScrollPoint[0]);
            }
            setCurrentTranslation(currentSavedTranslation[0] + point[0], currentSavedTranslation[1] + point[1]);
        } else { // rotate
            // not implemented
        }
    }

    return true;
}

From source file:org.deegree.geometry.linearization.CurveLinearizer.java

private int calcNumPoints(Point p0, Point p1, Point p2, boolean isCircle, double error) {

    // shift the points down (to reduce the occurrence of floating point errors), independently on the x and y axes
    double minOrd0 = CurveLinearizer.findShiftOrd0(p0, p1, p2);
    double minOrd1 = CurveLinearizer.findShiftOrd1(p0, p1, p2);

    // if the points are already shifted, this does no harm!
    Point p0Shifted = new DefaultPoint(null, p0.getCoordinateSystem(), p0.getPrecision(),
            new double[] { p0.get0() - minOrd0, p0.get1() - minOrd1 });
    Point p1Shifted = new DefaultPoint(null, p1.getCoordinateSystem(), p1.getPrecision(),
            new double[] { p1.get0() - minOrd0, p1.get1() - minOrd1 });
    Point p2Shifted = new DefaultPoint(null, p2.getCoordinateSystem(), p2.getPrecision(),
            new double[] { p2.get0() - minOrd0, p2.get1() - minOrd1 });

    Point center = calcCircleCenter(p0Shifted, p1Shifted, p2Shifted);

    double centerX = center.get0();
    double centerY = center.get1();

    double dx = p0Shifted.get0() - centerX;
    double dy = p0Shifted.get1() - centerY;
    double ex = p2Shifted.get0() - centerX;
    double ey = p2Shifted.get1() - centerY;

    double startAngle = Math.atan2(dy, dx);
    double endAngle = isCircle ? startAngle : Math.atan2(ey, ex);
    double radius = Math.sqrt(dx * dx + dy * dy);

    double angleStep = 2 * Math.acos(1 - error / radius);
    int numPoints;
    if (isCircle) {
        numPoints = (int) Math.ceil(2 * Math.PI / angleStep) + 1;
    } else {//from w ww  . j  av a  2  s . co m
        if (!isClockwise(p0Shifted, p1Shifted, p2Shifted)) {
            if (endAngle < startAngle) {
                endAngle += 2 * Math.PI;
            }
            numPoints = (int) Math.ceil((endAngle - startAngle) / angleStep) + 1;
        } else {
            if (startAngle < endAngle) {
                startAngle += 2 * Math.PI;
            }
            numPoints = (int) Math.ceil((startAngle - endAngle) / angleStep) + 1;
        }
    }
    return numPoints;
}

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

@Test
public void acosInt() {
    try {//from w  w  w  . ja  v a  2s. co m
        Expression expression = getExpressionWithFunctionContext("acos(16)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.acos(16), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:eu.trentorise.smartcampus.mobility.util.GamificationHelper.java

public static void removeOutliers(List<Geolocation> points) {
    Set<Geolocation> toRemove = Sets.newHashSet();

    double averageSpeed = 0;

    double distance = 0;
    for (int i = 1; i < points.size(); i++) {
        double d = harvesineDistance(points.get(i).getLatitude(), points.get(i).getLongitude(),
                points.get(i - 1).getLatitude(), points.get(i - 1).getLongitude());
        long t = points.get(i).getRecorded_at().getTime() - points.get(i - 1).getRecorded_at().getTime();
        if (t > 0) {
            distance += d;//from w  w w  .j a v  a  2s . c  o m
        }
    }
    double time = points.get(points.size() - 1).getRecorded_at().getTime()
            - points.get(0).getRecorded_at().getTime();
    averageSpeed = 3600000 * distance / (double) time;

    for (int i = 1; i < points.size() - 1; i++) {
        double d1 = harvesineDistance(points.get(i).getLatitude(), points.get(i).getLongitude(),
                points.get(i - 1).getLatitude(), points.get(i - 1).getLongitude());
        long t1 = points.get(i).getRecorded_at().getTime() - points.get(i - 1).getRecorded_at().getTime();
        double s1 = 0;
        if (t1 > 0) {
            s1 = 3600000 * d1 / (double) t1;
        }
        double d2 = harvesineDistance(points.get(i).getLatitude(), points.get(i).getLongitude(),
                points.get(i + 1).getLatitude(), points.get(i + 1).getLongitude());
        long t2 = points.get(i + 1).getRecorded_at().getTime() - points.get(i).getRecorded_at().getTime();
        double s2 = 0;
        if (t2 > 0) {
            s2 = 3600000 * d2 / (double) t2;
        }

        Integer index = null;

        double d3 = harvesineDistance(points.get(i - 1).getLatitude(), points.get(i - 1).getLongitude(),
                points.get(i + 1).getLatitude(), points.get(i + 1).getLongitude());

        double a = Math.acos((d1 * d1 + d2 * d2 - d3 * d3) / (2 * d1 * d2));

        if (a < 0.017453292519943 * 3) {
            index = i;
        } else if (a < 0.017453292519943 * 30 && s1 > 4 * averageSpeed && s2 > 4 * averageSpeed && i != 1
                && i != points.size() - 2) {
            index = i;
        } else if (i == 1 && s1 > 4 * averageSpeed) {
            index = 0;
        } else if (i == points.size() - 2 && s2 > 4 * averageSpeed) {
            index = points.size() - 1;
        }

        if (index != null) {
            toRemove.add(points.get(index));
        }
    }

    points.removeAll(toRemove);
}

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

@Test
public void acosDouble() {
    try {//from   w w w. j  a va2  s  .c  om
        Expression expression = getExpressionWithFunctionContext("acos(33.3)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.acos(33.3), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}