Example usage for java.lang Math atan

List of usage examples for java.lang Math atan

Introduction

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

Prototype

public static double atan(double a) 

Source Link

Document

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.

Usage

From source file:au.org.ala.biocache.web.WMSController.java

double convertMetersToLat(double meters) {
    return 180.0 / Math.PI * (2 * Math.atan(Math.exp(meters / 20037508.342789244 * Math.PI)) - Math.PI / 2.0);
}

From source file:org.kalypsodeegree_impl.graphics.displayelements.LabelFactory.java

private static double getRotation(final int x1, final int y1, final int x2, final int y2) {
    final double dx = x2 - x1;
    final double dy = y2 - y1;
    return Math.atan(dy / dx);
}

From source file:org.niord.core.area.AreaService.java

/** Calculates the message area sort order for CW and CCW types **/
private double computeCwOrCcwSortOrder(Area area, double lat, double lon) {
    double no = 0.0;
    if (area.getOriginLatitude() == null || area.getOriginLongitude() == null) {
        return no;
    }/*from  w w w  . j  a  v  a  2s  . com*/

    double x = lon2x(area.getOriginLongitude(), area.getOriginLatitude(), lon, lat);
    double y = lat2y(area.getOriginLongitude(), area.getOriginLatitude(), lon, lat);
    double ang = 0.0;

    if (x == 0.0 && y > 0.0) {
        ang = 90.0;
    } else if (x == 0.0 && y < 0.0) {
        ang = 270.0;
    } else if (x != 0.0) {
        ang = Math.atan(y / x) * 180 / Math.PI;
        if (x < 0.0) {
            ang += 180.0;
        } else if (x > 0.0 && y < 0.0) {
            ang += 360.0;
        }
    }
    no = ang - (area.getOriginAngle() == null ? 0 : area.getOriginAngle());

    if (no < 0.0) {
        no += 360.0;
    }
    return (area.getMessageSorting() == AreaMessageSorting.CW) ? -no : no;
}

From source file:app.akexorcist.gdaplibrary.GoogleDirection.java

private float getBearing(LatLng begin, LatLng end) {
    double lat = Math.abs(begin.latitude - end.latitude);
    double lng = Math.abs(begin.longitude - end.longitude);
    if (begin.latitude < end.latitude && begin.longitude < end.longitude)
        return (float) (Math.toDegrees(Math.atan(lng / lat)));
    else if (begin.latitude >= end.latitude && begin.longitude < end.longitude)
        return (float) ((90 - Math.toDegrees(Math.atan(lng / lat))) + 90);
    else if (begin.latitude >= end.latitude && begin.longitude >= end.longitude)
        return (float) (Math.toDegrees(Math.atan(lng / lat)) + 180);
    else if (begin.latitude < end.latitude && begin.longitude >= end.longitude)
        return (float) ((90 - Math.toDegrees(Math.atan(lng / lat))) + 270);
    return -1;//from  w  w w.j  av  a 2  s .com
}

From source file:com.limxing.library.PullToRefresh.SwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    try {/*from  w ww  .ja va 2  s  .  co  m*/
        ensureTarget();

        final int action = MotionEventCompat.getActionMasked(ev);

        if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
            mReturningToStart = false;
        }

        if (!isEnabled() || mReturningToStart) {
            // Fail fast if we're not in a state where a swipe is possible
            return false;
        }
        if (isRefreshing()) {
            return false;
        }

        if (mLoading) {
            return false;
        }

        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mInitialMotionY = ev.getY();
            mInitialMotionX = ev.getX();
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            mIsBeingDragged = false;

            up = canChildScrollUp();
            down = canChildScrollDown();

            break;

        case MotionEvent.ACTION_MOVE:
            if (mActivePointerId == INVALID_POINTER) {
                Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
                return false;
            }

            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex < 0) {
                Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
                return false;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = y - mInitialMotionY;

            final float adx = Math.abs(x - mInitialMotionX);
            final float ady = Math.abs(y - mInitialMotionY);

            if (up) { // ??
                if (down) { // ??
                    return false;
                } else {
                    if (pull2load) {
                        double angle = Math.atan(adx / ady);
                        if (-yDiff > mTouchSlop && (angle < trigger_angle)) { // 
                            direction = 1;
                            mIsBeingDragged = true;
                        }
                    }
                }
            } else {
                if (pull2refresh) {
                    double angle = Math.atan(adx / ady);
                    if (yDiff > mTouchSlop && (angle < trigger_angle)) {
                        direction = 0;
                        mIsBeingDragged = true;
                    }
                }

            }

            break;

        case MotionEventCompat.ACTION_POINTER_UP:
            onSecondaryPointerUp(ev);
            break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mIsBeingDragged = false;
            mActivePointerId = INVALID_POINTER;
            break;
        }

        return mIsBeingDragged;
    } catch (IllegalArgumentException e) {
        Log.e("error", e.getMessage());
        return false;
    }

}

From source file:code.Servlet.java

private void createSteps(String idEvent, Statement stmt) throws IOException, SQLException {

    String query = "SELECT * FROM event join city where event.city_name=city.name and event.idEvent=" + idEvent
            + "'"; // TODO && event.idEvent=idEvent
    ResultSet res = stmt.executeQuery(query);

    if (!res.next()) {
        System.out.println("Nessun evento");
    }/*w  ww . j  a  va2s.  co  m*/

    Location start = new Location(Double.parseDouble(res.getString("start_lat")),
            Double.parseDouble(res.getString("start_lon")));
    Location center = new Location(Double.parseDouble(res.getString("latitude")),
            Double.parseDouble(res.getString("longitude")));
    double d = Double.parseDouble(res.getString("diameter"));

    double randLat = (start.lat - center.lat) / kmToLat;
    double randLon = (start.lon - center.lon) / kmToLon;

    System.out.println("center: " + Double.parseDouble(res.getString("latitude")) + ", "
            + Double.parseDouble(res.getString("longitude")));
    System.out.println("randLat: " + randLat + "   randLon: " + randLon);
    System.out
            .println("randLat*kmToLat: " + (randLat * kmToLat) + "   randLon*kmToLon: " + (randLon * kmToLon));

    double a = -randLon, b = -randLat;
    double teta = 0;
    if (a == 0 && b == 0)
        ; // error, recalculate randLat and randLon
    if (b > 0) {
        teta = Math.toDegrees(Math.atan(a / b));
    }
    if (a >= 0 && b < 0) {
        teta = 180 + Math.toDegrees(Math.atan(a / b));
    }
    if (a < 0 && b < 0) {
        teta = -180 + Math.toDegrees(Math.atan(a / b));
    }
    if (a > 0 && b == 0) {
        teta = 90;
    }
    if (a < 0 && b == 0) {
        teta = -90;
    }
    if (teta < 0) {
        teta += 360;
    }

    double offset = (teta + 90 < 360) ? (teta + 90) : (teta + 90 - 360);
    System.out.println("teta: " + teta + "   offset: " + offset);

    query = "select number_step from event where idEvent=" + idEvent + "'";
    res = stmt.executeQuery(query);
    if (!res.next()) {
        System.out.println("vuoto numero step nell'evento");
    }

    // at the beginning of the game
    int N = Integer.parseInt(res.getString("number_step")); //numero utenti fare limite damiano
    double passo = 180 / N;

    // get rsndom id question
    query = "SELECT idQuestion FROM mydb_treasure.question where idQuestion<>6 order by rand()";
    res = stmt.executeQuery(query);
    if (!res.next()) {
        System.out.println("Nessuna domanda nel db");
    }
    List<String> questionsId = new ArrayList<String>();
    do {
        questionsId.add(res.getString("idQuestion"));
    } while (res.next());

    double[] tete = new double[N + 1];
    for (int i = 0; i < N + 1; i++) { //FORSE PROBLME SE STEP> QUESTION ****************
        tete[i] = (offset - i * passo < 0.0) ? ((offset - i * passo) + 360) : (offset - i * passo);
        query = "INSERT INTO `mydb_treasure`.`step`(`angle`, `len_step`, `Question_idQuestion`, `event_idEvent`) VALUES ('"
                + tete[i] + "', '" + lenPasso + "', '" + questionsId.get(i % questionsId.size()) + "', "
                + idEvent + "')";
        stmt.executeUpdate(query);
    }
}

From source file:com.jug.MotherMachine.java

/**
 * Rotates the whole stack (each Z-slize) in order to vertically align the
 * wells seen in the micrographs come from the MotherMachine. Note: This is
 * NOT done in-place! The returned <code>Img</code> in newly created!
 *
 * @param img//from   w w  w  . j ava 2s . c  o m
 *            - the 3d <code>Img</code> to be straightened.
 * @return the straightened <code>Img</code>. (Might be larger to avoid
 *         loosing data!)
 */
private void straightenRawImg() {
    assert (imgRaw.numDimensions() == 3);

    // new raw image
    Img<DoubleType> rawNew;

    // find out how slanted the given stack is...
    final List<Cursor<DoubleType>> points = new Loops<DoubleType, Cursor<DoubleType>>().forEachHyperslice(
            Views.hyperSlice(imgRaw, 2, 0), 0,
            new FindLocationAboveThreshold<DoubleType>(new DoubleType(0.33)));

    final SimpleRegression regression = new SimpleRegression();
    final long[] pos = new long[2];
    int i = 0;
    final double[] plotData = new double[points.size()];
    for (final Cursor<DoubleType> c : points) {
        c.localize(pos);
        regression.addData(i, -pos[0]);
        plotData[i] = -pos[0];
        // System.out.println("Regression.addData ( " + i + ", " + (-pos[0])
        // + " )");
        i++;
    }
    // Plot2d.simpleLinePlot("Global positioning regression data",
    // plotData);

    this.dCorrectedSlope = regression.getSlope();
    final double radSlant = Math.atan(regression.getSlope());
    // System.out.println("slope = " + regression.getSlope());
    // System.out.println("intercept = " + regression.getIntercept());
    final double[] dCenter2d = new double[] { imgRaw.dimension(0) * 0.5,
            -regression.getIntercept() + points.size() * regression.getSlope() };

    // ...and inversely rotate the whole stack in XY
    final AffineTransform2D affine = new AffineTransform2D();
    affine.translate(-dCenter2d[0], -dCenter2d[1]);
    affine.rotate(radSlant);
    affine.translate(dCenter2d[0], dCenter2d[1]);

    long minX = 0, maxX = imgRaw.dimension(0);
    long minY = 0;
    final long maxY = imgRaw.dimension(1);
    final double[][] corners = { new double[] { minX, minY }, new double[] { maxX, minY },
            new double[] { minX, maxY }, new double[] { maxX, maxY } };
    final double[] tmp = new double[2];
    for (final double[] corner : corners) {
        affine.apply(corner, tmp);
        minX = Math.min(minX, (long) tmp[0]);
        maxX = Math.max(maxX, (long) tmp[0]);
        minY = Math.min(minY, (long) tmp[1]);
        // maxY = Math.max(maxY, (long)tmp[1]); // if this line is active
        // also the bottom would be extenden while rotating (currently not
        // wanted!)
    }

    rawNew = imgRaw.factory().create(new long[] { maxX - minX, maxY - minY, imgRaw.dimension(2) },
            imgRaw.firstElement());

    for (i = 0; i < imgRaw.dimension(2); i++) {
        final RandomAccessibleInterval<DoubleType> viewZSlize = Views.hyperSlice(imgRaw, 2, i);
        final RandomAccessible<DoubleType> raInfZSlize = Views.extendValue(viewZSlize, new DoubleType(0.0));
        final RealRandomAccessible<DoubleType> rraInterpolatedZSlize = Views.interpolate(raInfZSlize,
                new NLinearInterpolatorFactory<DoubleType>());
        final RandomAccessible<DoubleType> raRotatedZSlize = RealViews.affine(rraInterpolatedZSlize, affine);

        final RandomAccessibleInterval<DoubleType> raiRotatedAndTruncatedZSlize = Views
                .zeroMin(Views.interval(raRotatedZSlize, new long[] { minX, minY }, new long[] { maxX, maxY }));

        DataMover.copy(raiRotatedAndTruncatedZSlize, Views.iterable(Views.hyperSlice(rawNew, 2, i)));
    }

    // set new, straightened image to be the new imgRaw
    imgRaw = rawNew;
}

From source file:com.android.launcher2.Workspace.java

@Override
protected void determineScrollingStart(MotionEvent ev) {
    if (isSmall())
        return;/*w w  w .j a v a  2 s  .c  o  m*/
    if (!isFinishedSwitchingState())
        return;

    float deltaX = Math.abs(ev.getX() - mXDown);
    float deltaY = Math.abs(ev.getY() - mYDown);

    if (Float.compare(deltaX, 0f) == 0)
        return;

    float slope = deltaY / deltaX;
    float theta = (float) Math.atan(slope);

    if (deltaX > mTouchSlop || deltaY > mTouchSlop) {
        cancelCurrentPageLongPress();
    }

    if (theta > MAX_SWIPE_ANGLE) {
        // Above MAX_SWIPE_ANGLE, we don't want to ever start scrolling the workspace
        return;
    } else if (theta > START_DAMPING_TOUCH_SLOP_ANGLE) {
        // Above START_DAMPING_TOUCH_SLOP_ANGLE and below MAX_SWIPE_ANGLE, we want to
        // increase the touch slop to make it harder to begin scrolling the workspace. This
        // results in vertically scrolling widgets to more easily. The higher the angle, the
        // more we increase touch slop.
        theta -= START_DAMPING_TOUCH_SLOP_ANGLE;
        float extraRatio = (float) Math.sqrt((theta / (MAX_SWIPE_ANGLE - START_DAMPING_TOUCH_SLOP_ANGLE)));
        super.determineScrollingStart(ev, 1 + TOUCH_SLOP_DAMPING_FACTOR * extraRatio);
    } else {
        // Below START_DAMPING_TOUCH_SLOP_ANGLE, we don't do anything special
        super.determineScrollingStart(ev);
    }
}

From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!isEnabledInAdapterView() || !isEnabled())
        return true;

    if (!isSwipeEnabled())
        return super.onTouchEvent(event);

    int action = event.getActionMasked();
    ViewParent parent = getParent();/*from www  .j  a  v a  2 s .co  m*/

    gestureDetector.onTouchEvent(event);
    Status status = getOpenStatus();
    ViewGroup touching = null;
    if (status == Status.Close) {
        touching = getSurfaceView();
    } else if (status == Status.Open) {
        touching = getBottomView();
    }

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mDragHelper.processTouchEvent(event);
        parent.requestDisallowInterceptTouchEvent(true);

        sX = event.getRawX();
        sY = event.getRawY();

        if (touching != null)
            touching.setPressed(true);

        return true;
    case MotionEvent.ACTION_MOVE: {
        if (sX == -1 || sY == -1) {
            // Trick:
            // When in nested mode, we need to send a constructed ACTION_DOWN MotionEvent to mDragHelper, to help
            // it initialize itself.
            event.setAction(MotionEvent.ACTION_DOWN);
            mDragHelper.processTouchEvent(event);
            parent.requestDisallowInterceptTouchEvent(true);
            sX = event.getRawX();
            sY = event.getRawY();
            return true;
        }

        float distanceX = event.getRawX() - sX;
        float distanceY = event.getRawY() - sY;
        float angle = Math.abs(distanceY / distanceX);
        angle = (float) Math.toDegrees(Math.atan(angle));

        boolean doNothing = false;
        if (mDragEdge == DragEdge.Right) {
            boolean suitable = (status == Status.Open && distanceX > 0)
                    || (status == Status.Close && distanceX < 0);
            suitable = suitable || (status == Status.Middle);

            if (angle > 30 || !suitable) {
                doNothing = true;
            }
        }

        if (mDragEdge == DragEdge.Left) {
            boolean suitable = (status == Status.Open && distanceX < 0)
                    || (status == Status.Close && distanceX > 0);
            suitable = suitable || status == Status.Middle;

            if (angle > 30 || !suitable) {
                doNothing = true;
            }
        }

        if (mDragEdge == DragEdge.Top) {
            boolean suitable = (status == Status.Open && distanceY < 0)
                    || (status == Status.Close && distanceY > 0);
            suitable = suitable || status == Status.Middle;

            if (angle < 60 || !suitable) {
                doNothing = true;
            }
        }

        if (mDragEdge == DragEdge.Bottom) {
            boolean suitable = (status == Status.Open && distanceY > 0)
                    || (status == Status.Close && distanceY < 0);
            suitable = suitable || status == Status.Middle;

            if (angle < 60 || !suitable) {
                doNothing = true;
            }
        }

        if (doNothing) {
            parent.requestDisallowInterceptTouchEvent(false);
            return false;
        } else {
            if (touching != null) {
                touching.setPressed(false);
            }
            parent.requestDisallowInterceptTouchEvent(true);
            mDragHelper.processTouchEvent(event);
        }
        break;
    }
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        sX = -1;
        sY = -1;
        if (touching != null) {
            touching.setPressed(false);
        }
    }
    default:
        parent.requestDisallowInterceptTouchEvent(true);
        mDragHelper.processTouchEvent(event);
    }

    return true;
}

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

@Test
public void atanInt() {
    try {// w w  w.  j a va  2s.c  om
        Expression expression = getExpressionWithFunctionContext("atan(16)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.atan(16), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}