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:cc.flydev.launcher.Workspace.java

@Override
protected void determineScrollingStart(MotionEvent ev) {
    if (!isFinishedSwitchingState())
        return;/*from w  w w . jav  a 2s .c  om*/

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

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

    float slope = absDeltaY / absDeltaX;
    float theta = (float) Math.atan(slope);

    if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
        cancelCurrentPageLongPress();
    }

    boolean passRightSwipesToCustomContent = (mTouchDownTime
            - mCustomContentShowTime) > CUSTOM_CONTENT_GESTURE_DELAY;

    boolean swipeInIgnoreDirection = isLayoutRtl() ? deltaX < 0 : deltaX > 0;
    if (swipeInIgnoreDirection && getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID
            && passRightSwipesToCustomContent) {
        // Pass swipes to the right to the custom content page.
        return;
    }

    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.wb.launcher3.Workspace.java

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

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

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

    float slope = absDeltaY / absDeltaX;
    float theta = (float) Math.atan(slope);

    if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
        cancelCurrentPageLongPress();
    }

    boolean passRightSwipesToCustomContent = (mTouchDownTime
            - mCustomContentShowTime) > CUSTOM_CONTENT_GESTURE_DELAY;

    boolean swipeInIgnoreDirection = isLayoutRtl() ? deltaX < 0 : deltaX > 0;
    if (swipeInIgnoreDirection && getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID
            && passRightSwipesToCustomContent) {
        // Pass swipes to the right to the custom content page.
        return;
    }

    if (theta > MAX_SWIPE_ANGLE) {
        //*/Added by tyd Greg 2014-03-21,for support the touch swipe gesture
        if (TydtechConfig.SWIPE_GESTURE_ENABLED && (isInOverviewMode() == mStartIsOverViewMode)
                && (mPointCount == 1) && (mTouchUPCountTemp == mPointCount)) {
            CellLayout cell = (CellLayout) getChildAt(mCurrentPage);
            if (true) {
                float y = ev.getY();
                if ((y - mYDown) > 0) {
                    if (Math.abs(y - mYDown) > (mTouchSlop * 5)
                            && LauncherAppState.getInstance().getSwipeDownEnable())
                        mTouchState = TOUCH_SWIPE_DOWN_GESTURE;
                } else {
                    if (Math.abs(y - mYDown) > (mTouchSlop * 5)
                            && LauncherAppState.getInstance().getSwipeUpEnable())
                        mTouchState = TOUCH_SWIPE_UP_GESTURE;
                }
            }
        }
        mTouchUPCountTemp = mPointCount;
        //*/
        // 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.aidy.launcher3.ui.workspace.Workspace.java

@Override
protected void determineScrollingStart(MotionEvent ev) {
    if (!isFinishedSwitchingState())
        return;/*from  w  ww.ja  v  a2  s.  co m*/

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

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

    float slope = absDeltaY / absDeltaX;
    float theta = (float) Math.atan(slope);

    if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
        cancelCurrentPageLongPress();
    }

    boolean passRightSwipesToCustomContent = (mTouchDownTime
            - mCustomContentShowTime) > CUSTOM_CONTENT_GESTURE_DELAY;

    boolean swipeInIgnoreDirection = isLayoutRtl() ? deltaX < 0 : deltaX > 0;
    if (swipeInIgnoreDirection && getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID
            && passRightSwipesToCustomContent) {
        // Pass swipes to the right to the custom content page.
        return;
    }

    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:Geometry.java

/**
 * Create the geometry of an arrow. The arrow is positioned at the
 * end (last point) of the specified polyline, as follows:
 *
 *                      0,4--,              
 *                         \  --,           
 *                          \    --,        
 *                           \      --,     
 *                            \        --,  
 *    -------------------------3-----------1
 *                            /        --'  
 *                           /      --'     
 *                          /    --'        
 *                         /  --'           
 *                        2--'                
 * //from  w ww. j ava 2s .c  o m
 * @param x       X coordinates of polyline of where arrow is positioned
 *                in the end. Must contain at least two points.
 * @param y       Y coordinates of polyline of where arrow is positioned
 *                in the end.
 * @param length  Length along the main axis from point 1 to the
 *                projection of point 0.
 * @param angle   Angle between the main axis and the line 1,0
 *                (and 1,2) in radians.
 * @param inset   Specification of point 3 [0.0-1.0], 1.0 will put
 *                point 3 at distance length from 1, 0.0 will put it
 *                at point 1.
 * @return        Array of the five coordinates [x,y,...]. 
 */
public static int[] createArrow(int[] x, int[] y, double length, double angle, double inset) {
    int[] arrow = new int[10];

    int x0 = x[x.length - 1];
    int y0 = y[y.length - 1];

    arrow[2] = x0;
    arrow[3] = y0;

    // Find position of interior of the arrow along the polyline
    int[] pos1 = new int[2];
    Geometry.findPolygonPosition(x, y, length, pos1);

    // Angles
    double dx = x0 - pos1[0];
    double dy = y0 - pos1[1];

    // Polyline angle
    double v = dx == 0.0 ? Math.PI / 2.0 : Math.atan(Math.abs(dy / dx));

    v = dx > 0.0 && dy <= 0.0 ? Math.PI + v
            : dx > 0.0 && dy >= 0.0 ? Math.PI - v
                    : dx <= 0.0 && dy < 0.0 ? -v : dx <= 0.0 && dy > 0.0 ? +v : 0.0;

    double v0 = v + angle;
    double v1 = v - angle;

    double edgeLength = length / Math.cos(angle);

    arrow[0] = x0 + (int) Math.round(edgeLength * Math.cos(v0));
    arrow[1] = y0 - (int) Math.round(edgeLength * Math.sin(v0));

    arrow[4] = x0 + (int) Math.round(edgeLength * Math.cos(v1));
    arrow[5] = y0 - (int) Math.round(edgeLength * Math.sin(v1));

    double c1 = inset * length;

    arrow[6] = x0 + (int) Math.round(c1 * Math.cos(v));
    arrow[7] = y0 - (int) Math.round(c1 * Math.sin(v));

    // Close polygon
    arrow[8] = arrow[0];
    arrow[9] = arrow[1];

    return arrow;
}

From source file:spinworld.gui.RadarPlot.java

private void drawTickLabel(Graphics2D g2, Rectangle2D radarArea, Point2D middlePoint, double _axisAngle,
        int cat, double tick) {
    double axisAngle = normalize(_axisAngle);
    double _origin = getOrigin(cat).doubleValue();
    double max = getMaxValue(cat).doubleValue();
    double tickValue = ((max - _origin) * tick) + _origin;
    String label = "" + Math.round(tickValue * 1000) / 1000d;
    FontRenderContext frc = g2.getFontRenderContext();
    Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
    int labelW = (int) labelBounds.getWidth();
    int labelH = (int) labelBounds.getHeight();

    double centerX = radarArea.getCenterX();
    double centerY = radarArea.getCenterY();

    double adj = middlePoint.distance(centerX, centerY);
    double opp = TICK_MARK_LENGTH / 2 + 4;
    double hyp = Math.sqrt(Math.pow(opp, 2) + Math.pow(adj, 2));
    double angle = Math.toDegrees(Math.atan(opp / adj));
    int charHeight = g2.getFontMetrics().getHeight();
    int charWidth = g2.getFontMetrics().charWidth('M');

    double alphaRad = Math.toRadians(axisAngle - angle);
    double labelX = centerX + (hyp * Math.cos(alphaRad));
    double labelY = centerY - (hyp * Math.sin(alphaRad)) + labelH;

    //        g2.draw(new Line2D.Double(centerX, centerY, labelX, labelY - labelH)); // test line

    double sinGap = Math.pow(Math.sin(Math.toRadians(axisAngle)), 2);
    if (axisAngle > 90 && axisAngle < 270) {
        labelY -= labelH;// w w  w .j  a v a  2 s . c o m
        labelY += (charHeight * sinGap / 2);
    } else {
        labelY -= (charHeight * sinGap / 2);
    }
    double cosGap = Math.pow(Math.cos(Math.toRadians(axisAngle)), 2);
    if (axisAngle > 180) {
        labelX -= labelW;
        labelX += (charWidth * cosGap / 2);
    } else {
        labelX -= (charWidth * cosGap / 2);
    }
    //        g2.drawRect((int) labelX, (int) labelY - labelH, labelW, labelH); // test rectangle
    g2.setPaint(getLabelPaint());
    g2.setFont(getLabelFont());
    g2.drawString(label, (float) labelX, (float) labelY);
}

From source file:com.klinker.android.launcher.launcher3.Workspace.java

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

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

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

    float slope = absDeltaY / absDeltaX;
    float theta = (float) Math.atan(slope);

    if (absDeltaX > mTouchSlop || absDeltaY > mTouchSlop) {
        cancelCurrentPageLongPress();
    }

    boolean passRightSwipesToCustomContent = (mTouchDownTime
            - mCustomContentShowTime) > CUSTOM_CONTENT_GESTURE_DELAY;

    boolean swipeInIgnoreDirection = mIsRtl ? deltaX < 0 : deltaX > 0;
    boolean onCustomContentScreen = getScreenIdForPageIndex(getCurrentPage()) == CUSTOM_CONTENT_SCREEN_ID;
    if (swipeInIgnoreDirection && onCustomContentScreen && passRightSwipesToCustomContent) {
        // Pass swipes to the right to the custom content page.
        return;
    }

    if (onCustomContentScreen && (mCustomContentCallbacks != null)
            && !mCustomContentCallbacks.isScrollingAllowed()) {
        // Don't allow workspace scrolling if the current custom content screen doesn't allow
        // scrolling.
        return;
    }

    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.example.aaron.test.MyGLSurfaceView.java

public void setVoronoiCoordinates() {

    temp.clear();/* w ww  .  j av  a2  s.c om*/
    temp2.clear();
    for (int i = 0; i < maxBots; i++) {
        if (tList[i].getOn() == 1) {
            temp.add((double) tList[i].getX());
            temp2.add((double) tList[i].getY());
            recievedTurtles = true;
        }
    }
    if (temp != null && recievedTurtles == true) {

        double[] temp3 = new double[temp.size()];
        double[] temp4 = new double[temp.size()];
        for (int i = 0; i < temp.size(); i++) {
            temp3[i] = temp.get(i);
            temp4[i] = temp2.get(i);
        }

        //voronoiEdges = vor.generateVoronoi(temp3, temp4, -width1 / (height1*mRenderer.scale)*2, width1 / (height1*mRenderer.scale)*2, -height1 / (height1*mRenderer.scale)*2, height1 / (height1*mRenderer.scale)*2);
        voronoiEdges = vor.generateVoronoi(temp3, temp4, -1, 1, -1, 1);

        for (int i = 0; i < voronoiEdges.size(); i++) {
            cd = Math.cos(Math.atan((voronoiEdges.get(i).x1 - voronoiEdges.get(i).x2)
                    / (voronoiEdges.get(i).y1 - voronoiEdges.get(i).y2)));
            cy = Math.sin(Math.atan((voronoiEdges.get(i).x1 - voronoiEdges.get(i).x2)
                    / (voronoiEdges.get(i).y1 - voronoiEdges.get(i).y2)));

            vorCoords[0] = (float) voronoiEdges.get(i).x1 + (float) cd * .005f / mRenderer.scale;
            vorCoords[1] = (float) voronoiEdges.get(i).y1 - (float) cy * .005f / mRenderer.scale;

            vorCoords[9] = (float) voronoiEdges.get(i).x2 + (float) cd * .005f / mRenderer.scale;
            vorCoords[10] = (float) voronoiEdges.get(i).y2 - (float) cy * .005f / mRenderer.scale;

            vorCoords[3] = (float) voronoiEdges.get(i).x1 - (float) cd * .005f / mRenderer.scale;
            vorCoords[4] = (float) voronoiEdges.get(i).y1 + (float) cy * .005f / mRenderer.scale;

            vorCoords[6] = (float) voronoiEdges.get(i).x2 - (float) cd * .005f / mRenderer.scale;
            vorCoords[7] = (float) voronoiEdges.get(i).y2 + (float) cy * .005f / mRenderer.scale;

            mRenderer.setVoronoiCoordinates(vorCoords, i, voronoiEdges.size(), voronoiEdges.get(i).x1,
                    voronoiEdges.get(i).y1, voronoiEdges.get(i).x2, voronoiEdges.get(i).y2);

        }
    }
}

From source file:org.apache.sysml.runtime.codegen.LibSpoofPrimitives.java

public static void vectAtanAdd(double[] a, double[] c, int ai, int ci, int len) {
    for (int j = ai; j < ai + len; j++, ci++)
        c[ci] += Math.atan(a[j]);
}

From source file:org.apache.sysml.runtime.codegen.LibSpoofPrimitives.java

public static void vectAtanAdd(double[] a, double[] c, int[] aix, int ai, int ci, int alen, int len) {
    for (int j = ai; j < ai + alen; j++)
        c[ci + aix[j]] += Math.atan(a[j]);
}

From source file:org.apache.sysml.runtime.codegen.LibSpoofPrimitives.java

public static double[] vectAtanWrite(double[] a, int ai, int len) {
    double[] c = allocVector(len, false);
    for (int j = 0; j < len; j++, ai++)
        c[j] = Math.atan(a[ai]);
    return c;/*from  w w  w  .  j  av a2  s .c om*/
}