开发者

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

开发者 https://www.devze.com 2023-03-06 11:39 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. 开发者_如何学JAVA Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers. 开发者_如何学JAVA

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

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?


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 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消