Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given the x and y components of the velocity, how can the angle be computed? [closed]

For a particle moving about in a Cartesian coordinate system (neglecting the z-axis), how can the angle of travel be computed given the x and y components of the velocity?

Before anyone says this isn't programming related, I am programming this right now, however, I don't know vector math.

For example, suppose the x and y values of the velocity are respectively 5.0 and -1.5, how would I compute the angle?

like image 665
farm ostrich Avatar asked May 18 '11 03:05

farm ostrich


People also ask

How do you find the angle between two vectors?

The angle between two vectors a and b is found using the formula θ = cos-1 [ (a · b) / (|a| |b|) ]. If the two vectors are equal, then substitute b = a in this formula, then we get θ = cos-1 [ (a · a) / (|a| |a|) ] = cos-1 (|a|2/|a|2) = cos-11 = 0°.


6 Answers

In Javascript, I'd use Math.atan2(1.5, 5.0). To convert to degrees, use Math.atan2(1.5, 5.0)/(Math.PI/180). On Wikipedia: http://en.wikipedia.org/wiki/Atan2

like image 194
Gray Avatar answered Oct 02 '22 21:10

Gray


You need atan2:

For any real arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it.

like image 34
user541686 Avatar answered Oct 02 '22 21:10

user541686


The angle in radians from the x-axis is given by:

arctan(vy / vx);  // vx > 0

You also need to handle the case vx < 0.

If you want the bearing versus true north, then you might want:

double bearing = 90 - arctan(vy / vx) * 360 / 2 / M_PI;
like image 37
Keith Avatar answered Oct 02 '22 21:10

Keith


The angle is the arctangent of y / x. Many languages have a 4-quadrant arctangent function in the math library that takes x and y arguments.

like image 45
Ted Hopp Avatar answered Oct 02 '22 22:10

Ted Hopp


You have to be careful about what the angles are between. Arctangent, atan(y / x), will give you the angle relative to the positive x-axis, but make sure that's what you need.

like image 42
Adam Avatar answered Oct 02 '22 22:10

Adam


The arc-tangent of the slope will give you what you want.

like image 42
soandos Avatar answered Oct 02 '22 20:10

soandos