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?
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°.
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
You need atan2
:
For any real arguments
x
andy
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.
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;
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.
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.
The arc-tangent of the slope will give you what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With