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:com.fairphone.fplauncher3.Workspace.java

@Override
protected void determineScrollingStart(MotionEvent ev) {
    if (!isFinishedSwitchingState()) {
        return;//from w ww . j a v a2s  .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 = isLayoutRtl() ? 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:org.apache.sysml.runtime.codegen.LibSpoofPrimitives.java

public static double[] vectAtanWrite(double[] a, int[] aix, int ai, int alen, int len) {
    double[] c = allocVector(len, true);
    for (int j = ai; j < ai + alen; j++)
        c[aix[j]] = Math.atan(a[j]);
    return c;/*from  w w w  .  j  a v  a2 s.c  o  m*/
}

From source file:com.example.aaron.test.MyGLSurfaceView.java

public void setFreeDrawCoordinates(float x, float y, float xp, float yp, boolean closed) {

    float Coords[] = { -0.5f, 0.5f, 0.0f, // top left
            -0.5f, -0.5f, 0.0f, // bottom left
            0.5f, -0.5f, 0.0f, // bottom right
            0.5f, 0.5f, 0.0f }; // top right

    double cd = Math.cos(Math.atan((x - xp) / (y - yp)));
    double cy = Math.sin(Math.atan((x - xp) / (y - yp)));

    Coords[0] = x + (float) cd * .005f * mRenderer.scale;
    Coords[0] = Coords[0] / mRenderer.scale;
    Coords[1] = y - (float) cy * .005f * mRenderer.scale;
    Coords[1] = Coords[1] / mRenderer.scale;

    Coords[9] = xp + (float) cd * .005f * mRenderer.scale;
    Coords[9] = Coords[9] / mRenderer.scale;
    Coords[10] = yp - (float) cy * .005f * mRenderer.scale;
    Coords[10] = Coords[10] / mRenderer.scale;

    Coords[3] = x - (float) cd * .005f * mRenderer.scale;
    Coords[3] = Coords[3] / mRenderer.scale;
    Coords[4] = y + (float) cy * .005f * mRenderer.scale;
    Coords[4] = Coords[4] / mRenderer.scale;

    Coords[6] = xp - (float) cd * .005f * mRenderer.scale;
    Coords[6] = Coords[6] / mRenderer.scale;
    Coords[7] = yp + (float) cy * .005f * mRenderer.scale;
    Coords[7] = Coords[7] / mRenderer.scale;

    freeDrawCount++;/*from  w  ww.ja  v a 2 s  . co  m*/
    if (freeDrawCount < 100) {
        mRenderer.setFreeDrawCoordinates(Coords, freeDrawCount - 1, freeDrawCount, xp, yp, x, y, closed);
    }
    pathPublisherFlag = true;

}

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

@Override
protected void determineScrollingStart(MotionEvent ev) {
    if (!isFinishedSwitchingState())
        return;/*w  ww .  jav  a 2 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;
    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.igormaznitsa.mindmap.swing.panel.MindMapPanel.java

private static double findLineAngle(final double sx, final double sy, final double ex, final double ey) {
    final double deltax = ex - sx;
    if (deltax == 0.0d) {
        return Math.PI / 2;
    }//from   w  w w  .ja  v a  2 s.  c o  m
    return Math.atan((ey - sy) / deltax) + (ex < sx ? Math.PI : 0);
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void processFrame() {
    long newTime = System.currentTimeMillis();
    long time = newTime - mLastTime;

    boolean end = false;

    if (time > 60) {
        Log.e("LONG", "Frame time took too long! Time: " + time + " Last process frame: " + mLastFrameTime
                + " Count: " + mBackgroundCount + " Level: " + mLevel);
    }/*from  www. j av  a  2  s  . c om*/

    // We don't want to jump too far so, if real time is > 60 treat it as 33.  On screen will seem to slow
    // down instaead of "jump"
    if (time > 60) {
        time = 33;
    }

    // Score is based on time + presents.  Right now 100 point per second played.  No presents yet
    if (mLevel < 6) {
        mScore += time;
    }

    if (mIsTv) {
        mScoreText.setText(mScoreLabel + ": " + NumberFormat.getNumberInstance().format((mScore / 10)));
    } else {
        mScoreText.setText(NumberFormat.getNumberInstance().format((mScore / 10)));
    }

    float scroll = mElfVelX * time;

    // Do collision detection first...
    // The elf can't collide if it is within 2 seconds of colliding previously.
    if (mElfIsHit) {
        if ((newTime - mElfHitTime) > 2000) {
            // Move to next state.
            if (mElfState < 4) {
                mElfState++;
                AnalyticsManager.sendEvent(getString(R.string.analytics_screen_rocket),
                        getString(R.string.analytics_action_rocket_hit), null, mElfState);
                if (mElfState == 4) {
                    mSoundPool.play(mGameOverSound, 1.0f, 1.0f, 2, 0, 1.0f);
                    // No more control...
                    mControlView.setOnTouchListener(null);
                    mElfAccelY = 0.0f;
                    if (mJetThrustStream != 0) {
                        mSoundPool.stop(mJetThrustStream);
                    }
                }
            }
            updateElf(false);
            mElfIsHit = false;
        }
    } else if (mElfState == 4) {
        // Don't do any collision detection for parachute elf.  Just let him fall...
    } else {
        // Find the obstacle(s) we might be colliding with.  It can only be one of the first 3 obstacles.
        for (int i = 0; i < 3; i++) {
            View view = mObstacleLayout.getChildAt(i);
            if (view == null) {
                // No more obstacles...
                break;
            }

            int[] tmp = new int[2];
            view.getLocationOnScreen(tmp);

            // If the start of this view is past the center of the elf, we are done
            if (tmp[0] > mElfPosX) {
                break;
            }

            if (RelativeLayout.class.isInstance(view)) {
                // this is an obstacle layout.
                View topView = view.findViewById(R.id.top_view);
                View bottomView = view.findViewById(R.id.bottom_view);
                if ((topView != null) && topView.getVisibility() == View.VISIBLE) {
                    topView.getLocationOnScreen(tmp);
                    Rect obsRect = new Rect(tmp[0], tmp[1], tmp[0] + topView.getWidth(),
                            tmp[1] + topView.getHeight());
                    if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                        handleCollision();
                    }
                }
                if (!mElfIsHit) {
                    if ((bottomView != null) && bottomView.getVisibility() == View.VISIBLE) {
                        bottomView.getLocationOnScreen(tmp);
                        Rect obsRect = new Rect(tmp[0], tmp[1], tmp[0] + bottomView.getWidth(),
                                tmp[1] + bottomView.getHeight());
                        if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                            // Special case for the mammoth obstacle...
                            if (bottomView.getTag() != null) {
                                if (((mElfPosX - tmp[0]) / (float) bottomView.getWidth()) > 0.25f) {
                                    // We are over the mammoth not the spike.  lower the top of the rect and test again.
                                    obsRect.top = (int) (tmp[1] + ((float) bottomView.getHeight() * 0.18f));
                                    if (obsRect.contains((int) mElfPosX,
                                            (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                                        handleCollision();
                                    }
                                }
                            } else {
                                handleCollision();
                            }
                        }
                    }
                }
            } else if (FrameLayout.class.isInstance(view)) {
                // Present view
                FrameLayout frame = (FrameLayout) view;
                if (frame.getChildCount() > 0) {
                    ImageView presentView = (ImageView) frame.getChildAt(0);
                    presentView.getLocationOnScreen(tmp);
                    Rect presentRect = new Rect(tmp[0], tmp[1], tmp[0] + presentView.getWidth(),
                            tmp[1] + presentView.getHeight());
                    mElfLayout.getLocationOnScreen(tmp);
                    Rect elfRect = new Rect(tmp[0], tmp[1], tmp[0] + mElfLayout.getWidth(),
                            tmp[1] + mElfLayout.getHeight());
                    if (elfRect.intersect(presentRect)) {
                        // We got a present!
                        mPresentCount++;
                        if (mPresentCount < 4) {
                            mSoundPool.play(mScoreSmallSound, 1.0f, 1.0f, 2, 0, 1.0f);
                            mScore += 1000; // 100 points.  Score is 10x displayed score.
                            mPlus100.setVisibility(View.VISIBLE);
                            if (mElfPosY > (mScreenHeight / 2)) {
                                mPlus100.setY(mElfPosY - (mElfLayout.getHeight() + mPlus100.getHeight()));
                            } else {
                                mPlus100.setY(mElfPosY + mElfLayout.getHeight());
                            }
                            mPlus100.setX(mElfPosX);
                            if (m100Anim.hasStarted()) {
                                m100Anim.reset();
                            }
                            mPlus100.startAnimation(m100Anim);
                        } else {
                            mSoundPool.play(mScoreBigSound, 1.0f, 1.0f, 2, 0, 1.0f);
                            mScore += 5000; // 500 points.  Score is 10x displayed score.
                            if (!mRainingPresents) {
                                mPresentCount = 0;
                            }
                            mPlus500.setVisibility(View.VISIBLE);
                            if (mElfPosY > (mScreenHeight / 2)) {
                                mPlus500.setY(mElfPosY - (mElfLayout.getHeight() + mPlus100.getHeight()));
                            } else {
                                mPlus500.setY(mElfPosY + mElfLayout.getHeight());
                            }
                            mPlus500.setX(mElfPosX);
                            if (m500Anim.hasStarted()) {
                                m500Anim.reset();
                            }
                            mPlus500.startAnimation(m500Anim);
                            mPresentBonus = true;
                        }
                        frame.removeView(presentView);
                    } else if (elfRect.left > presentRect.right) {
                        mPresentCount = 0;
                    }
                }
            }
        }
    }

    if (mForegroundLayout.getChildCount() > 0) {
        int currentX = mForegroundScroll.getScrollX();
        View view = mForegroundLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mForegroundLayout.removeViewAt(0);
        }
        mForegroundScroll.setScrollX(newX);
    }

    // Scroll obstacle views
    if (mObstacleLayout.getChildCount() > 0) {
        int currentX = mObstacleScroll.getScrollX();
        View view = mObstacleLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mObstacleLayout.removeViewAt(0);
        }
        mObstacleScroll.setScrollX(newX);
    }

    // Scroll the background and foreground
    if (mBackgroundLayout.getChildCount() > 0) {
        int currentX = mBackgroundScroll.getScrollX();
        View view = mBackgroundLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mBackgroundLayout.removeViewAt(0);
            if (view.getTag() != null) {
                Pair<Integer, Integer> pair = (Pair<Integer, Integer>) view.getTag();
                int type = pair.first;
                int level = pair.second;
                if (type == 0) {
                    if (mBackgrounds[level] != null) {
                        mBackgrounds[level].recycle();
                        mBackgrounds[level] = null;
                    } else if (mBackgrounds2[level] != null) {
                        mBackgrounds2[level].recycle();
                        mBackgrounds2[level] = null;
                    }
                } else if (type == 1) {
                    if (mExitTransitions[level] != null) {
                        mExitTransitions[level].recycle();
                        mExitTransitions[level] = null;
                    }
                } else if (type == 2) {
                    if (mEntryTransitions[level] != null) {
                        mEntryTransitions[level].recycle();
                        mEntryTransitions[level] = null;
                    }
                }
            }
            if (mBackgroundCount == 5) {
                if (mLevel < 6) {
                    // Pre-fetch next levels backgrounds
                    // end level uses the index 1 background...
                    int level = (mLevel == 5) ? 1 : (mLevel + 1);
                    BackgroundLoadTask task = new BackgroundLoadTask(getResources(), mLevel + 1,
                            BACKGROUNDS[level], EXIT_TRANSITIONS[mLevel],
                            // Exit transitions are for the current level...
                            ENTRY_TRANSITIONS[level], mScaleX, mScaleY, mBackgrounds, mBackgrounds2,
                            mExitTransitions, mEntryTransitions, mScreenWidth, mScreenHeight);
                    task.execute();
                    addNextImages(mLevel, true);
                    addNextObstacles(mLevel, 2);
                }
                // Fetch first set of obstacles if the next level changes from woods to cave or cave to factory
                if (mLevel == 1) {
                    // Next level will be caves.  Get bitmaps for the first 20 obstacles.
                    ObstacleLoadTask task = new ObstacleLoadTask(getResources(), CAVE_OBSTACLES, mCaveObstacles,
                            mCaveObstacleList, 0, 2, mScaleX, mScaleY);
                    task.execute();
                } else if (mLevel == 3) {
                    // Next level will be factory.  Get bitmaps for the first 20 obstacles.
                    ObstacleLoadTask task = new ObstacleLoadTask(getResources(), FACTORY_OBSTACLES,
                            mFactoryObstacles, mFactoryObstacleList, 0, 2, mScaleX, mScaleY);
                    task.execute();
                }
                mBackgroundCount++;
            } else if (mBackgroundCount == 7) {
                // Add transitions and/or next level
                if (mLevel < 5) {
                    addNextTransitionImages(mLevel + 1);
                    if (mTransitionImagesCount > 0) {
                        addNextObstacleSpacer(mTransitionImagesCount);
                    }
                    addNextImages(mLevel + 1);
                    // First screen of each new level has no obstacles
                    if ((mLevel % 2) == 1) {
                        addNextObstacleSpacer(1);
                        addNextObstacles(mLevel + 1, 1);
                    } else {
                        addNextObstacles(mLevel + 1, 2);
                    }
                } else if (mLevel == 5) {
                    addNextTransitionImages(mLevel + 1);
                    if (mTransitionImagesCount > 0) {
                        addNextObstacleSpacer(mTransitionImagesCount);
                    }
                    addFinalImages();
                }
                mBackgroundCount++;
            } else if (mBackgroundCount == 9) {
                // Either the transition or the next level is showing
                if (this.mTransitionImagesCount > 0) {
                    mTransitionImagesCount--;
                } else {
                    if (mLevel == 1) {
                        // Destroy the wood obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mWoodObstacles) {
                                    for (Bitmap bmp : mWoodObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mWoodObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    } else if (mLevel == 3) {
                        // Destroy the cave obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mCaveObstacles) {
                                    for (Bitmap bmp : mCaveObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mCaveObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    } else if (mLevel == 5) {
                        // Destroy the factory obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mFactoryObstacles) {
                                    for (Bitmap bmp : mFactoryObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mFactoryObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    }
                    mLevel++;

                    // Add an event for clearing this level - note we don't increment mLevel as
                    // it's 0-based and we're tracking the previous level.
                    AnalyticsManager.sendEvent(getString(R.string.analytics_screen_rocket),
                            getString(R.string.analytics_action_rocket_level), null, mLevel);

                    // Achievements
                    if (!mHitLevel) {
                        mCleanLevel = true;
                    }
                    mHitLevel = false;
                    if (mLevel == 5) {
                        mPlus100.setSelected(true);
                        mPlus500.setSelected(true);
                    } else if (mLevel == 6) {
                        mPlus100.setSelected(false);
                        mPlus500.setSelected(false);
                    }
                    if (mLevel < 6) {
                        mSoundPool.play(mLevelUpSound, 1.0f, 1.0f, 2, 0, 1.0f);
                        addNextImages(mLevel);
                        addNextObstacles(mLevel, 2);
                    }
                    mBackgroundCount = 0;
                }
            } else {
                if ((mBackgroundCount % 2) == 1) {
                    if (mLevel < 6) {
                        addNextImages(mLevel);
                        addNextObstacles(mLevel, 2);
                    }
                }
                mBackgroundCount++;
            }
        }
        int current = mBackgroundScroll.getScrollX();
        mBackgroundScroll.setScrollX(newX);
        if ((mLevel == 6) && (mBackgroundScroll.getScrollX() == current)) {
            end = true;
        }
    }

    // Check on the elf
    boolean hitBottom = false;
    boolean hitTop = false;

    float deltaY = mElfVelY * time;
    mElfPosY = mElfLayout.getY() + deltaY;
    if (mElfPosY < 0.0f) {
        mElfPosY = 0.0f;
        mElfVelY = 0.0f;
        hitTop = true;
    } else if (mElfPosY > (mScreenHeight - mElfLayout.getHeight())) {
        mElfPosY = mScreenHeight - mElfLayout.getHeight();
        mElfVelY = 0.0f;
        hitBottom = true;
    } else {
        // Remember -Y is up!
        mElfVelY += (mGravityAccelY * time - mElfAccelY * time);
    }
    mElfLayout.setY(mElfPosY);

    // Rotate the elf to indicate thrust, dive.
    float rot = (float) (Math.atan(mElfVelY / mElfVelX) * 120.0 / Math.PI);
    mElfLayout.setRotation(rot);

    mElf.invalidate();

    // Update the time and spawn the next call to processFrame.
    mLastTime = newTime;
    mLastFrameTime = System.currentTimeMillis() - newTime;
    if (!end) {
        if ((mElfState < 4) || !hitBottom) {
            if (mLastFrameTime < 16) {
                mHandler.postDelayed(mGameLoop, 16 - mLastFrameTime);
            } else {
                mHandler.post(mGameLoop);
            }
        } else {
            endGame();
        }
    } else {
        // Whatever the final stuff is, do it here.
        mPlayPauseButton.setEnabled(false);
        mPlayPauseButton.setVisibility(View.INVISIBLE);
        endGame();
    }
}

From source file:joshuatee.wx.USWXOGLRadarActivity.java

@Override
public void onLongPress(MotionEvent event) {

    x = event.getX();//from  w w w . j  a va 2s  . c  om
    //y=0.0f;
    y = event.getY() - statusBarHeight - actionBarHeight;

    x_middle = screen_width / 2;
    y_middle = (screen_height - statusBarHeight - actionBarHeight) / 2;

    diff_x = density * (x_middle - x) / mScaleFactor;
    diff_y = density * (y_middle - y) / mScaleFactor;

    x_str = preferences.getString("RID_" + rid1 + "_X", "0.00");
    y_str = preferences.getString("RID_" + rid1 + "_Y", "0.00");

    //Float center_x = 0.0f;
    //Float center_y = 0.0f;

    try {
        center_x = Float.parseFloat(x_str);
        center_y = Float.parseFloat(y_str);
    } catch (Exception e) {
    }

    ppd = OGLR.one_degree_scale_factor;
    new_x = center_y + ((OGLR.mPositionX) / mScaleFactor + diff_x) / ppd;
    test2 = 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + center_x * (Math.PI / 180) / 2));
    new_y = (float) test2 + ((-OGLR.mPositionY) / mScaleFactor + diff_y) / ppd;
    new_y = (float) (180 / Math.PI * (2 * Math.atan(Math.exp(new_y * Math.PI / 180)) - Math.PI / 2));

    rid_tmp = UtilityLocation.GetNearestRid(getBaseContext(), Float.toString(new_y),
            Float.toString(new_x * -1));

    if (!rid1.equals(rid_tmp))
        RIDMapSwitch(rid_tmp);

}

From source file:com.android.leanlauncher.CellLayout.java

private void computeDirectionVector(float deltaX, float deltaY, int[] result) {
    double angle = Math.atan(deltaY / deltaX);

    result[0] = 0;/*from   ww w.j  a  v a2  s.  c  o m*/
    result[1] = 0;
    if (Math.abs(Math.cos(angle)) > 0.5f) {
        result[0] = (int) Math.signum(deltaX);
    }
    if (Math.abs(Math.sin(angle)) > 0.5f) {
        result[1] = (int) Math.signum(deltaY);
    }
}

From source file:whitebox.stats.Kriging.java

/**
 * Creates the pairs list based on sector classification. calcs the distance
 * and moment of inertia for each pair It also calculates the min and max
 * points and boundary It also build the KDTree object to be used with the
 * Kriging/*from ww  w.  j  a v a 2  s.c o m*/
 */
void calPairs4Sec() throws FileNotFoundException {
    MaximumDistance = 0;
    MinX = Double.POSITIVE_INFINITY;
    MinY = Double.POSITIVE_INFINITY;
    MaxX = Double.NEGATIVE_INFINITY;
    MaxY = Double.NEGATIVE_INFINITY;
    pointsTree = new KdTree.SqrEuclid<>(2, new Integer(this.points.size()));
    //PairsTree = new KdTree.SqrEuclid<Double>(2, new Integer(this.Points.size()*(this.Points.size()-1)/2));
    PairsTree = new KdTree.SqrEuclid<>(2, new Integer(this.points.size() * (this.points.size())));
    double[] entry;
    double[] pairentry;

    //        String s = new String();
    double dx = 0;
    double dy = 0;
    for (int i = 0; i < this.points.size(); i++) {

        if (this.points.get(i).x < MinX) {
            MinX = this.points.get(i).x;
        }
        if (this.points.get(i).y < MinY) {
            MinY = this.points.get(i).y;
        }
        if (this.points.get(i).x > MaxX) {
            MaxX = this.points.get(i).x;
        }
        if (this.points.get(i).y > MaxY) {
            MaxY = this.points.get(i).y;
        }

        entry = new double[] { this.points.get(i).y, this.points.get(i).x };
        pointsTree.addPoint(entry, (double) i);

        for (int j = 0; j < this.points.size(); j++) {
            pair pr = new pair();

            if (i != j) {

                pr.FirstP = i;
                pr.SecondP = j;
                pr.Distance = Math.sqrt(Math.pow((points.get(i).x - points.get(j).x), 2)
                        + Math.pow((points.get(i).y - points.get(j).y), 2));

                pr.HorDistance = (points.get(j).x - points.get(i).x);
                pr.VerDistance = (points.get(j).y - points.get(i).y);

                if (MaximumDistance < pr.Distance) {
                    MaximumDistance = pr.Distance;
                }

                dx = points.get(j).x - points.get(i).x;
                dy = points.get(j).y - points.get(i).y;

                if (dx != 0) {
                    if ((dx > 0 && dy >= 0)) {
                        pr.Direction = Math.atan(dy / dx);
                    }
                    if (dx < 0 && dy >= 0) {
                        pr.Direction = Math.atan(dy / dx) + Math.PI;
                    }
                    if (dx > 0 && dy < 0) {
                        pr.Direction = Math.atan(dy / dx) + 2 * Math.PI;
                    }
                    if (dx < 0 && dy < 0) {
                        pr.Direction = Math.atan(dy / dx) + Math.PI;
                        ;
                    }
                } else {
                    if (dy >= 0) {
                        pr.Direction = Math.PI / 2;
                    } else {
                        pr.Direction = 3 * Math.PI / 2;
                    }
                }
                pr.MomentI = Math.pow((points.get(i).z - points.get(j).z), 2) / 2;
                Pairs.add(pr);

                pairentry = new double[] { pr.VerDistance, pr.HorDistance };
                PairsTree.addPoint(pairentry, (double) Pairs.size() - 1.0);

            }
        }
    }

    //        pw.close();
    //LagSize  = MaximumDistance/NumberOfLags;
    bMaxX = MaxX;
    bMaxY = MaxY;
    bMinX = MinX;
    bMinY = MinY;
}

From source file:com.android.launcher3.CellLayout.java

private void computeDirectionVector(float deltaX, float deltaY, int[] result) {
    double angle = Math.atan(((float) deltaY) / deltaX);

    result[0] = 0;/*from ww  w. j ava  2  s.  c  o  m*/
    result[1] = 0;
    if (Math.abs(Math.cos(angle)) > 0.5f) {
        result[0] = (int) Math.signum(deltaX);
    }
    if (Math.abs(Math.sin(angle)) > 0.5f) {
        result[1] = (int) Math.signum(deltaY);
    }
}