paydro
paydro

Reputation: 120

Convert velocityX and velocityY to Angle

In my application, I have a GestureListener with a fling method. This fling method returns an x velocity and y velocity, which is the speed of the finger moving in the x and y direction. The problem is, I want to know the angle in either radians or degrees of the fling. How could I achieve this?

Here is the method:

@Override
public boolean fling(float velocityX, float velocityY, int button) {
    return false;
}

All help is appreciated.

Upvotes: 0

Views: 164

Answers (1)

Blindman67
Blindman67

Reputation: 54039

To get the angle use the math function atan2. It returns the angle in the range -PI to PI

double velX = ?;
double velY = ?;
double angleRadians = Math.atan2(velY, velX); // Note Y comes first

Upvotes: 2

Related Questions